basforge

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

    RU

    Healthchecks.io: server heartbeat and alerting when a job fails to run

    Healthchecks.io waits for pings on a schedule and alerts when a ping is overdue, a job reports a failure, or a run starts and never finishes. A dead server can’t say it’s down, and an unrun script writes no log — only silence reveals either, and an external watchdog listens for it.

    A job that never runs leaves no trace: empty journal, no mail, and backups can silently stop for weeks. A server that goes down stays quiet too. Healthchecks.io watches for that silence: each job gets its own ping URL, pings it on completion, and triggers an ntfy alert if no ping arrives on time. Across the server path, the Beszel hub (Beszel), nightly backups (A backup off the server), scheduled restore checks (Test backups with scheduled restores), and deploy scripts all ping Healthchecks.io. Here is how it decides when to alert.

    How a check decides a job missed its run

    A check is a ping URL like https://hc-ping.com/<uuid> paired with a schedule. Its states:

    new ── first ping ──▶ up ── due time passed ──▶ late ── grace time passed ──▶ down ── ping ──▶ up
                           │                                                       ▲
                           └────────────── /fail or non-zero exit code ────────────┘
    • new — no pings yet. There’s nothing to count from, so alerts never fire.
    • late — due time passed, still within Grace Time. Still no alert.
    • down — alert sent. The next success ping flips it back to up and sends a recovery notice with the downtime duration.

    You don’t have to wait for the deadline on a failure: appending /fail to the URL marks the check down right away. You can also append the exit code directly: /0 counts as success, any other number as failure.

    Treat the ping URL like a job password: anyone who has it can forge a success ping. Store it under /srv/secrets/…, never hardcoded in a script.

    Schedules: Simple, Cron or OnCalendar

    Schedule When it expects a ping Good for
    Simple one Period after the last ping heartbeats: Beszel hub every minute
    Cron standard cron expression crontab jobs
    OnCalendar systemd OnCalendar= syntax systemd timers — what every job on this path uses

    Simple measures from the last ping: the backup recipe sets Period to 1 day and Grace Time to 2 hours, so a missed night alerts around 05:00 the next morning. The deadline floats, though: a backup that catches up at noon after a reboot shifts the next deadline to noon too. Cron and OnCalendar anchor to wall-clock time. For a timer with OnCalendar=*-*-* 03:00, put the same string in OnCalendar Expression, match Time Zone to the server’s zone (timedatectl shows it), and set Grace Time to 2 hours: no ping by 05:00 triggers an alert.

    Grace Time absorbs normal delays. A timer with Persistent=true runs a missed job after a reboot, so the ping lands late — Grace Time covers it. Unattended overnight reboots after updates need that buffer too, otherwise every update night wakes you.

    Wrapping a script

    A supervised job sends three signals: /start before doing work, the bare URL on success, and /fail with the tail of its output on failure. That’s how backup.sh on the path works:

    ping=$(cat /srv/secrets/kopia/hc-url)
    curl -fsS -m 10 --retry 3 -o /dev/null "$ping/start"
    
    if out=$(run 2>&1); then
      curl -fsS -m 10 --retry 3 -o /dev/null "$ping"
    else
      printf '%s\n' "$out" | tail -c 10000 |
        curl -fsS -m 10 --retry 3 -o /dev/null --data-binary @- "$ping/fail"
      exit 1
    fi
    • /start starts the run clock: Healthchecks.io now waits for success no longer than Grace Time. If the job hangs, you get alerted after Grace Time instead of a day later. The check’s page also records how long each run took.
    • /fail with a body marks the failure right away and attaches the tail of the output to the check’s event log. The notification itself omits the body and includes only the reason and ping type.
    • curl -fsS -m 10 --retry 3: -f fails on a not found reply from a bad URL, -m 10 keeps an unreachable Healthchecks.io from hanging the job, and --retry 3 rides out a brief network blip.

    For a single command, passing the exit code in the URL is enough:

    kopia maintenance run --full; curl -fsS -m 10 --retry 3 -o /dev/null "$ping/$?"

    Give each job its own check. If the weekly restore check pinged the backup check, it would reset the backup clock and hide a missed night.

    What lands on your phone

    Connect ntfy on the Integrations tab using the same topic as Beszel and Gatus. Each alert includes the check name, state, reason, and last ping:

    web1-backup is DOWN
    Reason: received a failure signal.
    
    Schedule: *-*-* 03:00
    Time Zone: Europe/Berlin
    Last Ping: Failure, now

    Two reasons appear: received a failure signal means /fail or a non-zero exit code arrived; success signal did not arrive on time, grace time passed means a ping never came or /start wasn’t followed by success. The footer lists any other checks currently down, so one message shows if several jobs broke together.

    Beszel heartbeat

    Every minute the Beszel hub sends a POST to HEARTBEAT_URL, pointed at a Simple check with Period 1 minute and Grace Time 5 minutes. Pings keep going out even when an agent on another host is down — the hub reports that only in the body as "status":"error". Because Healthchecks.io ignores the body by default, the heartbeat proves one thing: the hub is alive and reaching the internet.

    Healthchecks.io can inspect the body: open Filtering Rules on the check’s page, tick “Request body of HTTP requests”, and add failure and success keywords. Matching is literal and case-sensitive, and failure keywords are checked first:

    Field Value
    Failure keywords "status":"error"
    Success keywords "status":"ok","status":"warn"

    With those rules in place, a ping carrying "status":"error" triggers a failure alert right away. The trade-off is zero delay: Beszel’s “Status” waits 2 minutes so an agent restart stays quiet, whereas Healthchecks.io alerts on the first ping that lands during those seconds. Any ping matching neither list is marked Ignored by default and leaves the state unchanged.

    If it doesn’t work

    A check stays in new with no alerts even though the job isn’t running

    Cause
    No ping has ever arrived. Until the first ping lands, Healthchecks.io has no baseline to count from and never alerts: the URL isn’t on the server yet, the timer is disabled, or the job fails before its first curl.
    Fix
    Trigger the job manually (sudo systemctl start kopia-backup.service) and read its journal. After the first ping the check moves to up, and the schedule takes over.

    The backup failed, yet the check is green

    Cause
    The script pings success unconditionally (command; curl "$ping"), or a second job pings the same URL — a weekly ping resets the clock and hides a missed night.
    Fix
    Send the success ping only after the command succeeds (&&, exit code in the URL, or /fail as in “Wrapping a script”). Give every job its own check.

    Alert success signal did not arrive on time, grace time passed right after a job starts

    Cause
    The job sent /start and ran longer than Grace Time without sending success. After /start, Grace Time also caps how long the run may take, beyond just covering a late start.
    Fix
    Set Grace Time longer than the job’s slowest normal run. If the job hung, check its systemd journal.

    An alert arrived, yet it doesn’t show what broke

    Cause
    Notifications don’t include the /fail body — only the reason (Reason: received a failure signal.) and the last ping type.
    Fix
    Open the check’s page and read the Failure entry in the event log; the tail of the output is stored there.

    The job’s journal logs curl: (22) The requested URL returned error: 404

    Cause
    No check exists at that URL: it was deleted or saved with a typo. Healthchecks.io answers not found, and curl -f turns that into an error.
    Fix
    Copy the full ping URL from the check’s page and write it cleanly: echo '<url>' | sudo tee /srv/secrets/kopia/hc-url > /dev/null.

    Beszel’s heartbeat sends "status":"error", yet the check stays green

    Cause
    Healthchecks.io ignores the ping body by default and treats any ping to the URL as success.
    Fix
    That’s intended: Beszel’s “Status” alert reports a dead agent. If you want a second signal through Healthchecks.io too, set up Filtering Rules — see “Beszel heartbeat”.

    After adding Filtering Rules, every ping shows Ignored in the event log and the check goes down

    Cause
    The body didn’t match any keyword in Filtering Rules, and “If no keywords match” is set to ignore. Usually a keyword has an extra space or wrong case — matching is exact.
    Fix
    Compare your keyword character by character against the actual ping body on the check’s page.

    How to check

    Test the alert by action (Test your server’s protection by action): send a manual failure and recovery without breaking the job.

    ping=$(sudo cat /srv/secrets/kopia/hc-url)
    curl -fsS -m 10 --data-raw 'alert test' "$ping/fail"
    # OK — on your phone: web1-backup is DOWN, Reason: received a failure signal.
    curl -fsS -m 10 "$ping"
    # OK — on your phone: web1-backup is UP

    The check’s event log shows a Failure entry with the body alert test. Don’t test “missed ping” by hand — the first night a timer fails to fire will cover that.