When you need this
An active timer does not prove backup.service produced a valid backup. A failure may be visible in journalctl long before anyone notices. Send the service result externally and track when completion is due.
How to connect
- 1
Create a monitor for 0 3 * * * in Europe/Moscow. Set a grace period and runtime limit appropriate for the job.
- 2
Split the example into backup.service and backup.timer in /etc/systemd/system. Replace the URL and ExecStart; use an account with the permissions required by the job.
- 3
Reload the configuration, enable the timer and verify a test service result. Connect an alert channel in Tickwatch.
Ready-to-use example
Requires systemd, /bin/sh and curl at the specified path. Save two separate unit files. backup.sh must be executable and return a nonzero code on failure. The leading "-" on signal commands prevents monitoring errors from failing the job. Do not add RemainAfterExit=yes to this periodic oneshot.
# /etc/systemd/system/backup.service
[Unit]
Description=Nightly backup with Tickwatch
[Service]
Type=oneshot
Environment=PING=https://ping.tickwatch.dev/YOUR_PING_KEY
TimeoutStartSec=30min
ExecStartPre=-/bin/sh -c '/usr/bin/curl -fsS --max-time 5 -X POST "$$PING/start"'
ExecStart=/usr/local/sbin/backup.sh
ExecStopPost=-/bin/sh -c 'if [ "$$SERVICE_RESULT" = success ]; then /usr/bin/curl -fsS --max-time 5 -X POST "$$PING"; else /usr/bin/curl -fsS --max-time 5 -X POST "$$PING/fail"; fi'
# /etc/systemd/system/backup.timer
[Unit]
Description=Run the nightly backup
[Timer]
OnCalendar=*-*-* 03:00:00 Europe/Moscow
Persistent=true
[Install]
WantedBy=timers.targetsudo systemctl daemon-reload
sudo systemctl enable --now backup.timer
systemctl list-timers backup.timerCheck before going live
ExecStopPost also reports startup failures. The double $$ passes SERVICE_RESULT to the shell rather than expanding it early in systemd.
Persistent=true catches up when the timer becomes active again; it does not prove every missed backup was produced. Validate file freshness separately.
Stop a test timer for one interval and verify the alert. If the host goes offline, the deadline detects the missing completion.
Common questions
Why not just ExecStartPost?
It does not cover an ExecStart failure. The example checks the result in ExecStopPost so a failed start also sends /fail.
What if the timer fires while the service is active?
The same active unit is not launched as a second concurrent instance. Monitor runtime and choose an interval appropriate for the job duration.