brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: systemd Restart=on-failure with StartLimitBurst stops a restart loop

Systemd
~/tips/tip-systemd-restart-on-failure-start-limit

Restart=on-failure

Restarts a crashed service after a pause and gives up after too many quick failures.

A service that crashes at once and restarts at once will fill the journal, so I set the limits on purpose.

[Unit]
StartLimitIntervalSec=60
StartLimitBurst=5
[Service]
Restart=on-failure
RestartSec=5

Restart=on-failure restarts after a non-zero exit, a signal, a timeout or a watchdog expiry, but not after a clean stop. RestartSec=5 waits five seconds between attempts. With the default window of 10 seconds, five starts never fit inside it when the pause is five seconds, so the service would restart forever. A 60 second window fixes that: after more than five starts in 60 seconds systemd marks the unit failed and stops trying. The two StartLimit settings belong in [Unit], not [Service]. Clear the failed state with systemctl reset-failed myapp.service.

Further reading: systemd.unit manual page

More Systemd tips [Service] sudo mkdir -p /etc/systemd/system/service.d [Service] printf 'hunter2' | sudo systemd-creds encrypt --name=dbpass – dbpass.cred systemd-analyze timespan 1h30min All Systemd tips (88) All topics

Link