MySQL 8.0.40
Source Code Documentation
restart_monitor_win.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_RESTART_MONITOR_WIN_H_
25#define SQL_RESTART_MONITOR_WIN_H_
26
27#include <stdlib.h>
28#include <string.h>
29
30/**
31 Type indicating the type of signals which involve communication
32 between the monitor and the mysqld.
33*/
34
35enum class Signal_type {
36 /**
37 Shutdown signal from monitor to mysqld. This is used
38 to relay the shutdown that comes from the SCM.
39 */
41
42 /**
43 Signal used to send the service status command to the monitor.
44 */
45
47
48 /**
49 Signal to the the mysqld from monitor indicating service status command
50 has been processed.
51 */
52
54};
55
56/**
57 Service status message providing an abstraction for the service message sent
58 by monitor to client.
59*/
60
62 private:
63 /**
64 Service status message indicating type of update to be done monitor to SCM.
65 */
66
67 char m_service_msg[32];
68
69 public:
70 /**
71 Constructor which initializes the service status message to a null string.
72 */
73
75
76 /**
77 Constructor initializes the service status with a particular message.
78
79 @param msg pointer to message string.
80 */
81
82 Service_status_msg(const char *msg) {
83 strncpy(m_service_msg, msg, sizeof(m_service_msg));
84 }
85
86 /**
87 Get service message.
88
89 @return pointer to the service message.
90 */
91
92 const char *service_msg() const { return m_service_msg; }
93};
94
95/**
96 Type of messages logged by monitor logging.
97*/
98
100 /**
101 Error log.
102 */
104
105 /**
106 Warning log.
107 */
109
110 /**
111 Information log.
112 */
114};
115
116/**
117 Initialize the mysqld monitor. This method is called from
118 both the monitor and mysqld. It sets the variable that
119 distinguishes the monitor and the mysqld. It also initialize the
120 monitor logging subsystem if the process under which it is called
121 is monitor.
122*/
123
125
126/**
127 Deinitialize the monitor.
128 This method essentially closes any handles opened during initialization.
129*/
130
132
133/**
134 Send service status message to the monitor. This method is used by mysqld to
135 send service status like running and setting the slow timeout value.
136*/
137
139
140/**
141 Close the service status pipe. This method is called by
142 the mysqld child process.
143*/
144
146
147/**
148 Get char representation corresponding to MYSQLD_PARENT_PID.
149
150 @return Pointer to string representing pid of the monitor.
151*/
152
153const char *get_monitor_pid();
154
155/**
156 Signal an event of type Signal_type.
157
158 @param signal type of the event.
159*/
160
162
163/**
164 Check if option is an early type or --gdb, --no-monitor.
165 The early type options are verbose, help, initialize, version
166 and initialize-insecure. These options print and do certain activities
167 and allow the server to exit. In addition there are options like gdb,
168 no-monitor where we do not spawn a monitor process.
169
170 @param argc Count of arguments.
171 @param argv Vector of arguments.
172
173 @return true if we are early option else false.
174*/
175
176bool is_early_option(int argc, char **argv);
177
178/**
179 Check if we are monitor process.
180
181 @return true if the current process is monitor else false.
182*/
183
184bool is_mysqld_monitor();
185
186/**
187 Check if the monitor is started under a windows service.
188
189 @return true if the monitor is started as a windows service.
190*/
191
193
194/**
195 Start the monitor if we are called in parent (monitor) context.
196 In child context, set the event names and get the monitor process
197 pid and return -1.
198
199 @return -1 if we are in child context else exit code of the mysqld process.
200*/
201
202int start_monitor();
203
204/**
205 Setup the service status command processed handle.
206 This method is called from mysqld context. This handle ensures the
207 synchronization required between the monitor and mysqld once the
208 monitor has handled the service status sent by client.
209*/
210
212
213/**
214 Close the Service Status Cmd Processed handle.
215*/
216
218
219// extern declarations.
220extern bool is_windows_service();
221class NTService;
223#endif // SQL_RESTART_MONITOR_WIN_H_
Definition: nt_servc.h:23
static int signal(mysql_cond_t *that, const char *, unsigned int)
Definition: mysql_cond_v1_native.cc:87
Signal_type
Type indicating the type of signals which involve communication between the monitor and the mysqld.
Definition: restart_monitor_win.h:35
@ SIGNAL_SERVICE_STATUS_CMD
Signal used to send the service status command to the monitor.
@ SIGNAL_SERVICE_STATUS_CMD_PROCESSED
Signal to the the mysqld from monitor indicating service status command has been processed.
@ SIGNAL_SHUTDOWN
Shutdown signal from monitor to mysqld.
void close_service_status_pipe_in_mysqld()
Close the service status pipe.
Definition: restart_monitor_win.cc:268
bool setup_service_status_cmd_processed_handle()
Setup the service status command processed handle.
Definition: restart_monitor_win.cc:617
bool is_early_option(int argc, char **argv)
Check if option is an early type or –gdb, –no-monitor.
Definition: restart_monitor_win.cc:560
bool is_mysqld_monitor()
Check if we are monitor process.
Definition: restart_monitor_win.cc:588
void close_service_status_cmd_processed_handle()
Close the Service Status Cmd Processed handle.
Definition: restart_monitor_win.cc:639
void deinitialize_mysqld_monitor()
Deinitialize the monitor.
Definition: restart_monitor_win.cc:586
Monitor_log_msg_type
Type of messages logged by monitor logging.
Definition: restart_monitor_win.h:99
@ MONITOR_LOG_INFO
Information log.
@ MONITOR_LOG_ERROR
Error log.
@ MONITOR_LOG_WARN
Warning log.
bool send_service_status(const Service_status_msg &)
Send service status message to the monitor.
Definition: restart_monitor_win.cc:319
bool is_monitor_win_service()
Check if the monitor is started under a windows service.
Definition: restart_monitor_win.cc:578
bool initialize_mysqld_monitor()
Initialize the mysqld monitor.
Definition: restart_monitor_win.cc:572
void signal_event(Signal_type signal)
Signal an event of type Signal_type.
Definition: restart_monitor_win.cc:215
NTService * get_win_service_ptr()
bool is_windows_service()
const char * get_monitor_pid()
Get char representation corresponding to MYSQLD_PARENT_PID.
Definition: restart_monitor_win.cc:213
int start_monitor()
Start the monitor if we are called in parent (monitor) context.
Definition: restart_monitor_win.cc:666
Service status message providing an abstraction for the service message sent by monitor to client.
Definition: restart_monitor_win.h:61
char m_service_msg[32]
Service status message indicating type of update to be done monitor to SCM.
Definition: restart_monitor_win.h:67
Service_status_msg(const char *msg)
Constructor initializes the service status with a particular message.
Definition: restart_monitor_win.h:82
Service_status_msg()
Constructor which initializes the service status message to a null string.
Definition: restart_monitor_win.h:74
const char * service_msg() const
Get service message.
Definition: restart_monitor_win.h:92