How can I configure a systemd service to restart periodically?

wes picture wes · Jun 25, 2015 · Viewed 53.8k times · Source

I have a simple systemd service that needs to be periodically restarted to keep its process from bugging out. Is there a configuration option for systemd services to periodically restart them? All of the Restart* options seem to pertain to restarting the service when it exits.

Answer

Alex Forbes picture Alex Forbes · May 14, 2018

This may not have been present at the time the question was asked, but for systemd version >= 229, there is an option called RuntimeMaxSec, which terminates the service after it has been running for the given period of time.

e.g.

[Service]
Restart=always
RuntimeMaxSec=604800

To me this seems more elegant than abusing Type=notify and WatchdogSec.