Ramblings of an aging IT geek
← Ramblings of an aging IT geek
linux

a systemd unit that refused to stay dead

A service that kept respawning after I stopped it, and the Restart directive I had forgotten was doing exactly what I told it to.

A Linux terminal glowing in the dark

I stopped a service this morning. It came back. I stopped it again, more firmly, with the particular keystrokes of a man who is no longer asking. It came back again. For a few minutes I genuinely entertained the idea that something had got onto the box.

Nothing had got onto the box. The unit file had Restart=always and a short RestartSec, which means systemd was doing precisely what I had asked it to do months ago and then forgotten about. systemctl stop stops the running process. It does not stop systemd's opinion that the process should be running, and the two are not the same thing.

The honest fix is to stop telling it to come back:

[Service]
Restart=on-failure
RestartSec=5

on-failure only restarts on a non-zero exit or a signal, not on a clean operator stop. If you genuinely want it gone right now without editing the unit, systemctl stop followed by nothing works once you stop fighting your own restart policy. The lesson, as ever, is that the box was not haunted. I was.