📜 ⬆️ ⬇️

Recipe for systemd: forced restart of the service on the file flag

Task:

Decision:
restart-myservice.service
[Unit] Description=Restart my cool service [Service] Type=oneshot ExecStartPre=/bin/rm -f /path/to/restart.flag ExecStart=/bin/systemctl restart myservice.service 


restart-myservice.path
 [Unit] Description=Path marker to restart my cool service [Path] PathExists=/path/to/restart.flag Unit=restart-myservice.service 


Do not forget to tell systemctl start restart-myservice.path and set restart-myservice.path in the parameter Wants managed service.
')
Limitations:
The unit path works through the notify system call, and if the flag is on the way with the symlink, then when you rearrange the symlink (it was on the directory without the flag, it became with the flag), it most likely will not shoot, I did not check.

Additional materials:
man systemd.path
man systemd.unit

Source: https://habr.com/ru/post/273351/


All Articles