Love systemd timers

380 points · 263 comments on HN · read original →

Systemd timers offer advantages over traditional cron for scheduling tasks, including better output handling, execution history, and clearer syntax.

Systemd timers are units that schedule services on particular schedules, replacing cron with improvements in path handling, stdout/stderr capture, and execution history. A timer requires two files: a `.service` unit defining the task and a `.timer` unit specifying the schedule. Timer scheduling supports calendar expressions (e.g., `OnCalendar=10:00` for daily at 10 AM) and relative time spans (e.g., `OnBootSec=1h` then `OnUnitActiveSec=1h` for one hour after boot, then repeating hourly). The tool `systemd-analyze calendar` validates and explains time expressions. Advanced features include `WakeSystem=` to resume from suspend, `RandomizedOffsetSec=` to spread load across systems, and `Persistent=` to run missed activations immediately after downtime. The `systemctl list-timers` command provides a unified view of all scheduled tasks.

What HN community is saying

Commenters acknowledge systemd timers' practical value but criticize the INI file syntax as plain or ugly, with some noting that NixOS's Nix language wrapper improves the experience. Several defend the format as readable and better than alternatives like XML or shell scripts. A recurring theme: systemd's features (sandboxing, socket activation, btrfs scrub coordination) outweigh syntax complaints. Users report real-world success using timers for backups and maintenance tasks, particularly appreciating resilience to system downtime via `Persistent=`.