Guide · systemd
Monitor a systemd timer
Write the timer's OnCalendar schedule as cron, then ping from the service unit.
1. Create the monitor from the timer
OnCalendar is not cron syntax, so write the same schedule as a Unix cron expression, or use an interval monitor for OnUnitActiveSec timers. Pick the server's time zone, unless the OnCalendar value names its own.
OnCalendar | Cron |
|---|---|
*-*-* 02:00:00 | 0 2 * * * |
Mon *-*-* 04:00:00 | 0 4 * * 1 |
*-*-* *:00/15:00 | */15 * * * * |
2. Ping from the service
With Type=oneshot, ExecStartPost only runs after ExecStart has exited successfully. The - prefix keeps a failed ping from failing the job.
# /etc/systemd/system/backup.service
[Unit]
Description=Nightly backup
OnFailure=backup-failed.service
[Service]
Type=oneshot
ExecStartPre=-/usr/bin/curl -fsS -m 10 -o /dev/null https://ping.cronwize.com/YOUR-KEY/start
ExecStart=/usr/local/bin/backup.sh
ExecStartPost=-/usr/bin/curl -fsS -m 10 -o /dev/null https://ping.cronwize.com/YOUR-KEYOnFailure starts a second unit when the service fails, which reports the failure at once.
# /etc/systemd/system/backup-failed.service
[Unit]
Description=Report a failed backup to Cronwize
[Service]
Type=oneshot
ExecStart=/usr/bin/curl -fsS -m 10 -o /dev/null https://ping.cronwize.com/YOUR-KEY/failThe timer itself does not change.
# /etc/systemd/system/backup.timer
[Unit]
Description=Run the nightly backup
[Timer]
OnCalendar=*-*-* 02:00:00
[Install]
WantedBy=timers.targetUnit files are readable by users on the machine by default. Restrict them if the key in the URL should stay private.
3. Check the first ping
Reload the units, then run the service once. The monitor turns from new to up.
sudo systemctl daemon-reloadsudo systemctl start backup.service