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: systemctl kill --signal sends a signal to a service's processes

Linux
~/tips/tip-systemctl-kill-signal

sudo systemctl kill --signal=SIGHUP --kill-whom=main nginx.service

Sends a chosen signal to the main or all processes of a unit without looking up a PID.

Sending a signal to a service by hand usually starts with hunting for its process ID. systemd already knows which processes belong to a unit.

sudo systemctl kill --signal=SIGHUP --kill-whom=main nginx.service

That sends SIGHUP, often used to make a daemon re-read its config, to the main process of the unit only. Per the man page, --signal defaults to SIGTERM. The value for --kill-whom must be one of main, control, cgroup or all, and if you leave it out it defaults to all.

That default needs care. It means every process of the unit gets the signal, workers and helpers included. A SIGKILL to all of them is a hard stop, so I keep that for a service that is truly stuck.

The unit name stays the same across restarts, while a PID changes every time, so the command is easier to put in a script. The man page also notes that --signal=help lists the signal names it accepts:

systemctl kill --signal=help

The command only delivers the signal, and what happens next depends on the process. If the service has Restart= set, systemd may start it again after you kill it. For a normal stop, systemctl stop is the right tool.

Further reading: systemd: systemctl man page

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link