brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: send a Healthchecks /start ping to see how long a cron job runs

Cron
~/tips/tip-healthchecks-start-ping-rid

curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/your-uuid-here/start

Adds a start ping so Healthchecks.io can show the run time of every job.

A cron monitor that only says “the job pinged” tells half the story. I want to know how long the backup took, and Healthchecks.io can show that if the job sends one extra ping before it starts.

curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/your-uuid-here/start
/home/me/backup.sh
curl -fsS -m 10 --retry 5 -o /dev/null https://hc-ping.com/your-uuid-here

The first request appends /start to the normal ping URL. The check then shows as Started, and the run time is the gap between the start and the success ping. Healthchecks.io displays that duration only when the two events are less than 72 hours apart.

The -m 10 matters more here than on the final ping. The documentation recommends a time limit on every ping, because a stuck start ping would otherwise keep the actual job from running.

One side effect to plan for: once a check has sent a start signal, the grace time also becomes the maximum time allowed between start and success. If no success ping arrives within the grace time, Healthchecks.io marks the check as down and alerts you. A job that normally takes 40 minutes needs a grace time above 40 minutes.

If the same job can run twice at once, the durations can come out wrong, because Healthchecks.io cannot tell which success belongs to which start. Give both pings a run ID in the rid parameter. It has to be a UUID, and uuidgen makes one:

RID=$(uuidgen)
curl -fsS -m 10 --retry 5 -o /dev/null "https://hc-ping.com/your-uuid-here/start?rid=$RID"
# ... run the job ...
curl -fsS -m 10 --retry 5 -o /dev/null "https://hc-ping.com/your-uuid-here?rid=$RID"

The caveat with run IDs is that Healthchecks.io only watches the execution time of the most recently started run. A slow earlier run can overshoot the grace time without any alert. This tip follows the Healthchecks.io documentation and was not run against a live account.

Further reading: Measuring script run time, Pinging reliability tips

Going deeper: Keep a domain pointed at your home with Cloudflare DDNS on Unraid

More Cron tips echo 'systemctl restart myapp' | at 03:00 tomorrow 55 23 28-31 * * [ "$(date -d tomorrow +\%d)" = 01 ] && /usr/local/bin/month-end.sh EDITOR=nano crontab -e 30 6 * * mon /usr/local/bin/weekly-report.sh @daily /usr/local/bin/backup.sh All Cron tips (33) All topics

Link