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: ExecReload= with $MAINPID gives a systemd service a working reload

Systemd
~/tips/tip-systemd-exec-reload

ExecReload=/bin/kill -HUP $MAINPID

Make systemctl reload send a signal to the main process of your own service.

Lots of daemons reread their config on SIGHUP. Without an ExecReload= line in the unit, though, systemctl reload just says the unit does not support it.

Add the line, and let systemd fill in the main PID:

[Service]
ExecStart=/usr/local/bin/myapp
ExecReload=/bin/kill -HUP $MAINPID

After systemctl daemon-reload, a systemctl reload myapp sends SIGHUP to the right process, even if the PID changed after a restart. With a small shell loop that traps HUP, the journal shows Reloading, Reloaded and then the line from the trap handler.

This is the example the systemd.service man page itself uses, so I consider it a safe pattern. It also makes systemctl reload-or-restart pick the gentle path for your service.

One weakness: kill returns as soon as the signal is sent, so systemd says Reloaded before the program actually finished reading its config. If a later step depends on the new config being active, check the program’s own log. Services with Type=notify-reload (systemd 253 and newer) report when they are done, but that needs support in the program.

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