basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    Background jobs: alert on silence (dead man’s switch)

    If a script alerts only on error, a disabled timer, a hung process, or a dead server produces complete silence. A dead man’s switch flips the model: the job confirms every successful run to an external watchdog, and missing that signal by the deadline is what raises the alert.

    What “alert on error” misses

    “Script failed, send a message” works only if the script starts and reaches its notification line. Silent failures slip right past it:

    • a timer or cron entry was disabled during an upgrade and never turned back on;
    • the server was down or rebooting at the scheduled minute;
    • the process hung halfway through and never returned an exit code;
    • the disk filled up or the network dropped, cutting off the notification itself.

    You find out that backups or updates stopped only during an incident, when it’s too late to fix them.

    How a dead man’s switch works

    regular alert:      job fails ──────────→ notification   (never ran → silence)
    dead man's switch:  job passes ──→ external watchdog ──→ no ping by deadline ──→ alert

    After a successful run, the job sends a short HTTP ping to an external service. The watchdog knows the schedule and grace window: if no ping arrives on time, it raises the alert on its own — whatever caused the silence doesn’t matter.

    Two rules make this hold:

    • Keep the watchdog outside, separate from the host it watches — otherwise they go silent together when the machine dies.
    • Ping only after success (using && or after checking the exit code), never unconditionally at the end of the script.

    Which jobs belong under it

    Use a dead man’s switch for background tasks nobody watches by eye every day: nightly backups (A backup off the server), scheduled restore checks (Test backups with scheduled restores), periodic deploys (Deploy without SSH), and monitoring’s own heartbeat (Beszel). For check setup, schedules, and /start / /fail signals, see Healthchecks.io.

    If it doesn’t work

    Error notifications were configured, yet backups stopped for weeks without anyone noticing

    Cause
    The script didn’t exit with an error — it never ran (the timer was off, the server was down at start time, or the disk filled up before the alert could be sent).
    Fix
    Switch the job to a dead man’s switch: on success it pings an external watchdog (Healthchecks.io) that alerts on silence.

    The watchdog runs on the same server as the job, so no alert came when the VPS went down

    Cause
    When the server goes down, local monitoring goes quiet along with it.
    Fix
    Move the watchdog outside — to another server or an external service such as Healthchecks.io.