Mat*_*att 8 systemd exit-status
最初发布在 StackOverflow 上,被告知来这里问。回顾一下那次谈话——
我原来的问题如下:
假设我的systemd
单元文件中有以下内容:
Type=forking
Restart=on-failure
Run Code Online (Sandbox Code Playgroud)
父进程以状态 0 退出(子进程成功启动)。在稍后的某个时刻,孩子以非零状态死亡。发生什么了? systemd
可以跟踪子守护进程PID:
Process: 1768 ExecStart=/bin/mydaemon (code=exited, status=0/SUCCESS)
Main PID: 1770 (mydaemon)
Run Code Online (Sandbox Code Playgroud)
是Restart=on-failure
只盯着父退出状态,或者还有孩子呢?
我创建了以下单元文件:
[Unit]
Description=Something
[Service]
Type=forking
WorkingDirectory=/tmp
ExecStart=/tmp/script.sh
ExecStop=/tmp/script.sh
Restart=on-failure
Run Code Online (Sandbox Code Playgroud)
script.sh 包含以下内容:
#!/bin/sh
echo "Forking"
/tmp/myscript.sh &
Run Code Online (Sandbox Code Playgroud)
myscript.sh 包含以下内容:
#!/bin/sh
sleep 60
exit 1
Run Code Online (Sandbox Code Playgroud)
果然,每隔 60 秒,systemd 就会重启服务。
如图所示,注意不同的 PID 和开始时间,注意它会重新启动父级:
linux:~ # systemctl status myService.service
? myService.service - Something
Loaded: loaded (/etc/systemd/system/myService.service; static; vendor preset: disabled)
Active: active (running) since Mon 2017-07-10 20:43:29 CEST; 57s ago
Process: 4393 ExecStart=/tmp/script.sh (code=exited, status=0/SUCCESS)
Main PID: 4396 (script.sh)
Tasks: 2 (limit: 512)
CGroup: /system.slice/myService.service
??4396 /bin/sh /tmp/script.sh
??4397 sleep 60
Jul 10 20:43:29 linux.suse systemd[1]: Starting Something...
Jul 10 20:43:29 linux.suse script.sh[4393]: Forking
Jul 10 20:43:29 linux.suse systemd[1]: Started Something.
linux:~ # systemctl status myService.service
? myService.service - Something
Loaded: loaded (/etc/systemd/system/myService.service; static; vendor preset: disabled)
Active: active (running) since Mon 2017-07-10 20:44:29 CEST; 1s ago
Process: 4409 ExecStop=/tmp/script.sh (code=exited, status=0/SUCCESS)
Process: 4417 ExecStart=/tmp/script.sh (code=exited, status=0/SUCCESS)
Main PID: 4420 (script.sh)
Tasks: 2 (limit: 512)
CGroup: /system.slice/myService.service
??4420 /bin/sh /tmp/script.sh
??4421 sleep 60
Jul 10 20:44:29 linux.suse systemd[1]: Starting Something...
Jul 10 20:44:29 linux.suse script.sh[4417]: Forking
Jul 10 20:44:29 linux.suse systemd[1]: Started Something.
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4612 次 |
最近记录: |