Eu criei o seguinte arquivo de unidade:
[Unit]
Description=Something
[Service]
Type=forking
WorkingDirectory=/tmp
ExecStart=/tmp/script.sh
ExecStop=/tmp/script.sh
Restart=on-failure
O script.sh contém o seguinte:
#!/bin/sh
echo "Forking"
/tmp/myscript.sh &
O myscript.sh contém o seguinte:
#!/bin/sh
sleep 60
exit 1
Com certeza, a cada 60 segundos, o systemd reinicia o serviço.
Como mostrado aqui, observe os diferentes PIDs e os horários de início, observe que ele reinicia o pai:
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.