Systemd service that is always restarted

Just using Restart and RestartSec is not enough: systemd services have start rate limiting enabled by default. If service is started more than StartLimitBurst times in StartLimitIntervalSec seconds is it not permitted to start any more. This parameters are inherited from DefaultStartLimitIntervalSec(default 10s) and DefaultStartLimitBurst(default 5) in systemd-system.conf.

Use systemctl edit foobar.service or manually edit /etc/systemd/system/foobar.service.d/override.conf and run systemctl deamon-reload.

[Service]
Restart=always
# time to sleep before restarting a service
RestartSec=1

[Unit]
# StartLimitIntervalSec in recent systemd versions
StartLimitInterval=0

In recent systemd versions StartLimitInterval was renamed to StartLimitIntervalSec.

You can tune Restart parameter to restart service only on failure, only on uncaught signal, etc. Check the manpage.

Links:



License: Creative Commons Attribution-ShareAlike License Share: share on reddit share on facebook share on twitter