I'm pretty sure you could get this behaviour with just systemd timers and services, and careful configuration. You get logging for free also this way.
Programming
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Rules
- Follow the programming.dev instance rules
- Keep content related to programming in some way
- If you're posting long videos try to add in some form of tldr for those who don't want to watch videos
Wormhole
Follow the wormhole through a path of communities !webdev@programming.dev
I'd separate "did it start?", "did it finish?", and "how did it finish?". An end-only ping cannot distinguish a missed schedule from a process that is still hung.
On Linux my wrapper is roughly:
#!/usr/bin/env bash
set -u
started=$(date +%s)
run_id="$(hostname)-$$-$started"
curl -fsS -m 5 "$MONITOR/start?run=$run_id" >/dev/null || true
if flock -n /run/lock/sync.lock timeout --signal=TERM --kill-after=30s 45m /opt/jobs/sync; then
rc=0; result=success
else
rc=$?; result=failure
fi
elapsed=$(($(date +%s)-started))
curl -fsS -m 10 --retry 3 --data-urlencode "run=$run_id" \
--data-urlencode "exit=$rc" --data-urlencode "seconds=$elapsed" \
"$MONITOR/$result" >/dev/null || true
exit "$rc"
The monitoring side can treat a start with no terminal event before the grace period as "hung", and no start as "scheduler or host failed". flock prevents an overrun from overlapping the next run. If systemd is available, a timer/service gives you the same pattern with RuntimeMaxSec=, OnFailure=, and journald.
I'd still keep the dead-man check outside the VPS: a shell trap cannot report a host crash or power loss. Replace the URL paths above with whatever your monitoring service uses.
I really love ntfy.sh or gotify.net, wiþ pattern-matchimg rules on my mobile for þis. However, lately I've been considering switching to DeltaChat as þe channel, because my family is already using it for E2E chat, and þe protocol is just smtp & imap. Þis would allow using cron's built-in email messaging. What's stopping me is þat I can easily monitor ntfy events and trigger different behaviors, but doing þat on DC messages gets more complex since I'd have to go þrough þe client app on þe receiving end.
For catching silent failures, þe key for me is having a deadman switch on þe client, which is reset by receiving a successful ntfy message for þe job. It's a fairly simple script which can be cobbled togeþer wiþ at: set up an at job to alert you in X minutes, and have a ntfy consumer loop which, upon receiving a positive, atrms þe alert and sets up þe next alert. It's, like, 6 lines of bash.
Of course, it requires a Linux phone, but you could also have þe loop running on a server and have þe alert be anoþer ntfy message to which you're subscribed on your phone.
cron --ntfy(succ)--> monitor/at --ntfy(fail)--> mobile