Running but dead: a 2-minute TCP watchdog for services restart policies can't save

petrusenko_max · x · 2026-12-06

launchd KeepAlive, systemd Restart=, and Docker restart policies only ask "did the process exit?" — a service that stays up but stops answering gets no rescue. The author's X reply bot was down 2 days after the hermes gateway on his Mac mini hung post-update; a stale process holding a port had caused a similar outage. His fix: a shell watchdog on a 2-minute timer that opens a real TCP connection (nc -z, 5s timeout) with rules: two consecutive failures before restart; kill leftover 30-min+ stale processes first; cap 3 restarts/hour to avoid loops; re-bootstrap unloaded jobs; skip when the machine's Tailscale address is absent; log one line, no notifications. Logs show 21-second recovery. Caveat: TCP connect only proves something accepts connections — probe a health endpoint and read the response body if you have one.

Original post →

More from coding & agent

coding & agent channel →