Restarting systemd service on dependency failure

I'll try to summarize my findings for this issue in case someone comes across this as information on this topic is scant.

  • Restart=on-failure only applies to process failures (does not apply to failure due to dependency failures)
  • The fact that dependent failed units get restarted under certain conditions when a dependency successfully restart was a bug in systemd < 220: http://lists.freedesktop.org/archives/systemd-devel/2015-July/033513.html
  • If there's even a small chance that a dependency might fail on start and you care about resiliency, don't use Before/After and instead perform a check on some artifact that the dependency produces

e.g.

ExecStartPre=/usr/bin/test -f /some/thing
Restart=on-failure
RestartSec=5s

You could even use systemctl is-active <dependecy>.

Very hacky, but I haven't found any better options.

In my opinion, not having a way to handle dependency failures is a flaw in systemd.

Tags:

Systemd