I have a group of services that are fundamentally linked (ideally they should be ran as a single service/process but that work still needs to be done) in that I want the failure of one service to cause the other services to be restarted as well.
I'm using a target unit to start them all at the same time and I have them all set to Restart=always
to individually recover but that wouldn't restart the other services if one service failed for any reason.
I thought I might get away with using the BindsTo
directive which does seem to stop all the services if a single one fails (such as the process being killed).
My service files currently look like this:
[Unit]
Description=foo
After=syslog.target network.target
BindsTo=foo.service bar.service baz.service all-services.target
[Service]
User=foo
WorkingDirectory=~
Restart=always
RestartSec=90
StartLimitInterval=400
StartLimitBurst=3
SyslogIdentifier=foo
ExecStart=/path/to/binary
[Install]
WantedBy=all-services.target
With a grouping target defined as:
[Unit]
Description=all-services
BindsTo=foo.service bar.service baz.service
But the BindsTo
directive seems to completely stop all the services when one fails and never attempt a restart.
I can't seem to find anything that suggests this service group restarting property is achievable directly in systemd rather than restarting a chain of dependencies but I might be missing something (or ignoring a better way of doing this).