Skip to content

Healthchecks: notice missed cron jobs

Monitoring ยท Cron
Not studied

Added 2026-10-11. Requires Bash, curl and a dedicated check in Healthchecks.

Problem

The backup job stopped running. There are no errors in the logs: the process never started. Regular CPU monitoring doesn't notice.

Solution

Healthchecks is "a cron job monitoring service. It listens for HTTP requests and email messages ("pings") from your cron jobs and scheduled tasks ("checks"). When a ping does not arrive on time, Healthchecks sends out alerts." The /start, plain ping and /fail signals distinguish start, success and failure. Give the check a schedule, a time zone and a Grace Time longer than the job's normal run time.

The monitor must live outside the VPS failure domain: if the shared host goes down, a local Healthchecks goes down with it. Use a separate server or the hosted service.

Example

The monitored-job.sh wrapper takes a command with arguments. Get HC_PING_URL from the created check, store it as a job secret, and don't enable set -x tracing. The URL here has no trailing / and no query parameters.

#!/usr/bin/env bash
set -uo pipefail
: "${HC_PING_URL:?Set the check ping URL}"
if (( $# == 0 )); then
  printf 'A job command is required\n' >&2
  exit 64
fi

signal_check() {
  if ! curl --fail --silent --output /dev/null \
      --connect-timeout 3 --max-time 10 --retry 2 \
      "${HC_PING_URL}${1}"; then
    printf 'Failed to send the monitoring signal\n' >&2
  fi
}

signal_check /start
if "$@"; then
  job_status=0
  signal_check ''
else
  job_status=$?
  signal_check /fail
fi
exit "$job_status"

Call it from the existing job once the environment variable is set:

/usr/local/bin/monitored-job.sh /usr/local/bin/backup-devops-kb.sh

The backup script must return a non-zero code on error by itself. A failed ping doesn't cancel the backup or replace its exit code. If the job hangs or can't send a signal, the monitor finds out via the timeout. Concurrent runs need separate checks or run IDs (rid); the example assumes one job without overlaps.

When to use

Backups, temp data cleanup, syncs, periodic reports. Checking that a backup finished complements the restore drill.

Source

How to apply it yourself

  1. Set up the notification recipient and the grace time.
  2. On a test check, run the wrapper with true, then with false.
  3. Skip one test run and wait for the notification; check that the next successful ping restores the state.
  4. Mark it "Studied" once you have received both a failure and a missed-run notification.