Recipe for systemd: forced restart of the service on the file flag
Task:
there is a certain self-written service started and monitored from systemd;
it is necessary to restart this service when a flag file appears;
it cannot be done from within the service for religious reasons.
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 torestart 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