cron has been the default answer to “run this every night” for fifty years, and on a single VPS it still works. But cron has no concept of a job that missed its window because the box was rebooting, no built-in jitter to stop every instance in a fleet firing at 02:00:00, and no structured logging. systemd timers solve all three, and the directives that matter are fewer than you would expect.
This is a practical comparison: what each scheduler does with a missed run, how to spread load across instances, and the exact unit files to copy. The examples assume a small VPS running nightly backups, log rotation and a certificate renewal hook — the three jobs almost every server has.
Jitter: Why 02:00:00 Is a Bad Time
If you run twenty VPS instances from the same provisioning template, they all have the same backup cron entry and they all fire at the same second. The result is a coordinated spike in disk writes, network egress and upstream API calls — the worst possible load shape for both your provider and your backup target. cron has no way to avoid this short of editing each crontab by hand or adding a sleep $((RANDOM % 600)) at the start of the script.
systemd timers have jitter as a first-class directive: RandomizedDelaySec= adds a random delay within a window, and AccuracySec= (default 60 seconds) lets the scheduler coalesce wake-ups for power efficiency. Setting RandomizedDelaySec=1800 on a OnCalendar=*-*-* 02:00:00 timer spreads twenty instances across a 30-minute window with no script changes and no maintenance burden when you scale the fleet.
Directive Comparison Table
| Need | cron equivalent | systemd timer |
|---|---|---|
| Schedule at a wall-clock time | 0 2 * * * | OnCalendar=*-*-* 02:00:00 |
| Run every N minutes | */15 * * * * | OnUnitActiveSec=15min |
| Spread across instances | Manual sleep $RANDOM | RandomizedDelaySec=900 |
| Recover missed runs | None (anacron on some distros) | Persistent=true |
| Do not start if still running | flock wrapper | Built-in: oneshot refuses overlap |
| Run at boot + schedule | Separate @reboot line | OnBootSec=5min |
| Accuracy tolerance | None | AccuracySec=1min |
| Resource limits | None | MemoryMax=, IOWeight=, CPUQuota= |
| Structured logs | Manual redirect | journald, automatic |
Two rows deserve emphasis. The overlap protection is not a lock file that can go stale — systemd will simply not start a second instance of the same oneshot service while one is active, and it logs a skip. And the resource limits mean a runaway backup can be capped at IOWeight=100 instead of saturating the disk, which is the difference between a slow backup and an unresponsive application.
The trade-off is verbosity. A cron line is one line; a timer plus a service is two files with [Unit], [Service] and [Timer] sections. If you only ever run one trivial one-liner on one machine, cron is still the smaller total cost.
Persistent Catch-Up and Missed Runs
Persistent=true is the directive that changes operational behaviour most. systemd records the last time the timer fired in /var/lib/systemd/timers/stamp-<unit>.timer. On boot, if the scheduled time has passed since that stamp, the service runs once immediately. A VPS that reboots at 01:50 never misses its 02:00 backup; one that reboots at 02:30 runs the backup on the way up.
Compare this to cron, which simply skips the window. Most distributions ship anacron to cover the gap, but anacron is coarse — it works in days, not hours, and it will not help a job that runs every 15 minutes. Persistent=true works for any schedule, including sub-hourly timers, and it does not need a separate daemon.
Writing the Unit Files
Put the work in a service unit and the schedule in a timer unit. The service is Type=oneshot, has an ExecStart= pointing at your script, and can carry IOSchedulingClass=best-effort and IOSchedulingPriority=7 to keep background writes gentle. The timer has OnCalendar=, RandomizedDelaySec=, Persistent=true and WantedBy=timers.target in its [Install] section.
Enable with systemctl enable --now backup.timer, then verify with systemctl list-timers --all, which prints NEXT, LEFT, LAST and PASSED — the four values that tell you a timer is actually scheduled. Run it once manually with systemctl start backup.service before trusting the schedule, so you find script bugs in a controlled way rather than at 02:00.
Testing Jitter and Catch-Up Behaviour
You can inspect the computed next run without waiting: systemd-analyze calendar "*-*-* 02:00:00" validates the expression and shows the next elapses. For jitter, the NEXT column in list-timers includes the randomized delay, so restarting the timer repeatedly lets you see different next-run times — a quick way to confirm jitter is applied rather than silently ignored due to a typo.
To test Persistent=true, set a timer to a time a few minutes in the past, stop the timer, enable it, and reboot. Check systemctl status backup.service for a start at boot time and compare timestamps with journalctl -u backup.service. If it did not fire, your distro is probably using a read-only /var at boot or the stamp file is on a volume that is not yet mounted — mount ordering is the usual culprit.
Where cron Still Wins
Per-user crontabs are convenient in ways systemd is not. A developer can add a job without root, without touching /etc, and without knowing unit syntax. On a shared build box or a machine with rotating operators, that matters. cron is also present in minimal containers where systemd is not running at all, which is where many scheduled jobs actually live.
The pragmatic split is user-level convenience jobs in cron and anything an on-call person depends on in a systemd timer. Backups, certificate renewals, log shipping and database maintenance belong in timers because you need Persistent=true, resource limits and journald evidence when something goes wrong at 3 a.m. Ad-hoc scripting convenience belongs wherever it is easiest.
Timer Hygiene and Migration
Keep timers in /etc/systemd/system/ with a uniform naming scheme, and list them in your provisioning template so new instances inherit the same schedule. When migrating from cron, do it one job at a time and leave the cron entry disabled rather than deleted for a week — if the timer fails silently due to a mistake, you can re-enable the known-good line in seconds. On a fleet sourced from a managed VPS platform with snapshot-based rollback this makes failure recoverable rather than memorable. For sizing guidance on instances that run many scheduled jobs concurrently, see the cloud VPS benefits overview.
Finally, add a dead-man’s-switch check: a separate timer that alerts if journalctl -u backup.service --since "26 hours ago" returns nothing. Schedulers of either kind fail by not running, and the only reliable detection is an external check that the job ran — not a check that the timer is enabled.




Leave a Reply
You must be logged in to post a comment.