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: SuccessExitStatus= tells systemd which odd exit codes are fine

Systemd
~/tips/tip-systemd-success-exit

[Service]

Stop a service from showing as failed when its program exits with a harmless code.

Some programs use a non-zero exit code for a normal outcome. rsync returns 24 when files vanished during the copy, for example, which on a busy folder is just life. systemd sees anything but 0 as a failure.

List the codes that should count as success:

[Service]
Type=oneshot
ExecStart=/usr/bin/rsync -a /srv/data/ /mnt/backup/data/
SuccessExitStatus=24

With ExecStart=/bin/sh -c "exit 3" and SuccessExitStatus=3, the unit is simply inactive after the run, not failed. You can list several codes and signal names on one line, like SuccessExitStatus=24 SIGUSR1.

Java services are the other classic case. A JVM that is stopped with SIGTERM exits with 143, which makes every clean systemctl stop look like a failure:

SuccessExitStatus=143

The opposite setting exists too: RestartPreventExitStatus= lists codes that should not trigger Restart=, handy for a code that means the config is broken.

I’d only whitelist codes you understand. If you add a code that also covers real errors, failures go silent: no OnFailure= alert, no restart, and nothing in systemctl --failed.

Further reading: systemd.service man 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