A service (say bar.service) is dependent on another service (say foo.service), like below
bar's service file:
[Unit]
After=foo.service
Requires=foo.service
...
If foo.service is restarted (either manually or due to a bug), how can bar.service be automatically restarted as well?
I think the needed option is BindsTo, it handles the misbehaviours too.
A another solution might be to use ExecStartPost option to restart the bar.service (if it´s executed) when foo.service has (re)started:
The additional Restart and RestartSec options ensure that foo.service will automatically restarted on crash and thus also bar.service.
A second extension my be to add same to bar.service and ensure that bar.service start after foo.service:
This should start both services automatically in case of a crash and bar.service will be restarted when foo.service restarts (due to an error or manually triggered).
You can use
PartOf
.From the
systemd.unit
man page: