CentOS 7下systemd是如何stop mysql服務的
【背景】
有同事在研究mongo的服務啟動方式,討論到mysql5.7的服務管理時一起做了下面測試。
MySQL5.7是用systemd來管理service的,它的配置檔案/usr/lib/systemd/system/[email protected]中,只定義了ExecStart啟動伺服器的命令,
但沒有定義ExecStop引數,就是停止mysqld服務時執行的命令。systemd究竟是如何stop mysql服務的。
【測試步驟】
1、執行關閉服務的命令
systemctl stop
2、使用systemtap指令碼來抓取kill程序時的訊號量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
global target;
global signal;
probe begin
{
printf(
"%-6s %-12s %-5s %-6s %6s\n"
,
"FROM"
,
"COMMAND"
,
"SIG"
,
"TO"
,
"RESULT"
);
}
probe nd_syscall.kill
{
target[tid()] = uint_arg(1);
signal[tid()] = uint_arg(2);
}
probe nd_syscall.kill.
return
{
if
(target[tid()] != 0) {
printf(
"%-6d %-12s %-5d %-6d %6d\n"
, pid(), execname(),
signal[tid()], target[tid()], int_arg(1));
delete target[tid()];
delete signal[tid()];
}
}
|
3、可以看到上面的mysqld程序127531被systemd程序kill掉了,先傳15,再傳18兩個訊號量
相當於執行了kill -15 127531,kill -18 127531兩個命令
4、從文件中也找到了說明,
KillSignal引數可以指定停止程序時使用的訊號,預設值為15 SIGTERM ,另外systemd會緊跟此訊號再發送一個18 SIGCONT訊號,以確保殺死已掛起的程序。
KillSignal=Specifies which signal to use when killing a service. This controls the signal that is sent as first step of shutting down a unit (see above), and is usually followed by SIGKILL (see above and below). For a list of valid signals, see signal(7). Defaults to SIGTERM.
Note that, right after sending the signal specified in this setting, systemd will always send SIGCONT, to ensure that even suspended tasks can be terminated cleanly.
【背景】
有同事在研究mongo的服務啟動方式,討論到mysql5.7的服務管理時一起做了下面測試。
MySQL5.7是用systemd來管理service的,它的配置檔案/usr/lib/systemd/system/[email protected]中,只定義了ExecStart啟動伺服器的命令,
但沒有定義ExecStop引數,就是停止mysqld服務時執行的命令。systemd究竟是如何stop mysql服務的。
【測試步驟】
1、執行關閉服務的命令
systemctl stop [email protected]
2、使用systemtap指令碼來抓取kill程序時的訊號量
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
global target;
global signal;
probe begin
{
printf(
"%-6s %-12s %-5s %-6s %6s\n"
,
"FROM"
,
"COMMAND"
,
"SIG"
,
"TO"
,
"RESULT"
);
}
probe nd_syscall.kill
{
target[tid()] = uint_arg(1);
signal[tid()] = uint_arg(2);
}
probe nd_syscall.kill.
return
{
if
(target[tid()] != 0) {
printf(
"%-6d %-12s %-5d %-6d %6d\n"
, pid(), execname(),
signal[tid()], target[tid()], int_arg(1));
delete target[tid()];
delete signal[tid()];
}
}
|
3、可以看到上面的mysqld程序127531被systemd程序kill掉了,先傳15,再傳18兩個訊號量
相當於執行了kill -15 127531,kill -18 127531兩個命令
4、從文件中也找到了說明,
KillSignal引數可以指定停止程序時使用的訊號,預設值為15 SIGTERM ,另外systemd會緊跟此訊號再發送一個18 SIGCONT訊號,以確保殺死已掛起的程序。
KillSignal=Specifies which signal to use when killing a service. This controls the signal that is sent as first step of shutting down a unit (see above), and is usually followed by SIGKILL (see above and below). For a list of valid signals, see signal(7). Defaults to SIGTERM.
Note that, right after sending the signal specified in this setting, systemd will always send SIGCONT, to ensure that even suspended tasks can be terminated cleanly.