Restart=always never fired, because nothing exited

Restart=always never fired, because nothing exited

●2 ●42 ●105
calendar_today • schedule1 min read

On August 6 my laptop booted to a blank terminal. lightdm has Restart=always, and systemctl status said active (running). Xorg had entered the NVIDIA init about 140 ms before the device nodes existed and hung there for fourteen hours: state S, 20 ms of CPU, no error line. A restart policy restarts processes that exit. Mine never exited.

"Down" is three states: crashed, stopped on purpose, or running but not answering. The usual watchdog handles the first and misreads the others. It even misreads a typo. I re-ran this today with a swapped letter in the third name:

$ for u in cron lightdm crno; do
>   printf '%-8s is-active=%-9s rc=' "$u" "$(systemctl is-active "$u")"
>   systemctl is-active --quiet "$u"; echo $?
> done
cron     is-active=active    rc=0
lightdm  is-active=active    rc=0
crno     is-active=inactive  rc=4

Exit 3 is a real unit that is stopped; exit 4 is a unit that does not exist, and both print inactive. A watchdog that only checks is-active tries to start crno every minute, forever. Check LoadState first, and for the hung case, probe the service the way a client would, with a timeout.

The three-state table, the start-limit trap and a cron watchdog that alerts once per outage are in the full guide to auto-restarting a Linux service.


I bundled the scripts I copy onto every new server, plus 10 bonus ones, into the Production Bash Toolkit. 30-day refund if it isn't useful.

Want more #devops & #linux deep dives?

Join 6,176+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

More Posts

The cleanup failed on the night there was nothing to clean

BashSnippets - Dec 2

My hung process had no file open. It was stuck inside open().

BashSnippets - Dec 1

A deploy guard that passes with no token

BashSnippets - Nov 24

bash ran a path that no longer existed, and exited 127

BashSnippets - Oct 21

The Alert Never Fired Because the Loop Skipped the Last Line of the File

BashSnippets - Jun 19
chevron_left
4k Points • 149 Badges
North America • bashsnippets.xyz
79Posts
44Comments
14Connections
Linux user who got tired of Googling the same bash commands every time I sat down at a terminal. Sta... Show more

Commenters (This Week)

2 comments
2 comments
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!