What is a dead man's switch monitor? (And when to use one)
A dead man's switch is a monitoring technique where your system pings a service on a schedule. If the ping is missing, an alert is fired. Learn how to use it for backups and workers.
If you've ever scheduled a backup script or a data pipeline, you've probably wondered: how do I know if it actually ran?
Most developers start by adding email or Slack alerts at the end of their script. If the script fails, it sends a message. Simple, right?
But what happens if the server crashes before the script even starts? What if the cron daemon dies? What if there's a typo in the crontab?
Your script fails silently. No errors, no emails, just a missing backup when you need it most.
This is where a dead man's switch (also known as heartbeat monitoring) comes in.
How it works
Instead of the monitoring service calling your system (like a traditional uptime monitor), your system calls the monitoring service.
- You create a monitor in a tool like CronSpark.
- It gives you a unique URL.
- You add a simple
curlrequest to the very end of your script to ping that URL. - You tell CronSpark: "Expect a ping on this URL every 24 hours."
If CronSpark doesn't receive that ping within the 24-hour window, it assumes the job failed (or never started) and triggers an alert.
When to use a dead man's switch
You should use a dead man's switch for any background task where a silent failure is dangerous:
- Database backups: Ensure your nightly
pg_dumpactually completes. - Data pipelines / ETL: Make sure data synchronization jobs finish on time.
- SSL certificate renewals: Certbot runs automatically, but if it breaks, you won't know until your site shows a security warning.
- Antivirus / Security scans: Verify that scheduled security audits are running as expected.
Setting it up in bash
It's incredibly simple to add. Just append a curl command to your existing script:
#!/bin/bash
# Your backup logic here
pg_dump mydb > backup.sql
# If the backup succeeds, ping the dead man's switch
if [ $? -eq 0 ]; then
curl -m 10 --retry 3 https://api.cronspark.com/ping/YOUR_UNIQUE_ID
fi
With this pattern, if the pg_dump fails, or if the server is offline, the ping never happens. The dead man's switch triggers, and you get a Slack message telling you to check your backups before it's too late.
Stop relying on your scripts to report their own failures. Use a dead man's switch and sleep better at night.