Systemd timers
Quick answer
A systemd timer schedules activation of another unit, usually a service. Separate the schedule from the task so each can be inspected and tested independently.
Prepare the practice environment
Run python3 lab-fixtures/logs-time/setup.py from the extracted package root as an ordinary user. Enter the printed path and check pwd. Use a fresh fixture and Bash with LC_ALL=C and set -o pipefail for each example. Never install the sample schedules, change system time or use the global logrotate configuration. Manual inspection requires an authorized disposable VM.
How it works
OnCalendar uses wall-clock expressions; OnBootSec and OnUnitActiveSec use relative monotonic intervals. Persistent=true on calendar timers can trigger a catch-up activation when at least one event was missed during inactivity, not one run per missed event. AccuracySec and randomized delay may affect actual start time. A timer does not restart an already active target unit; use a finite oneshot task for this lab. systemd-analyze calendar parses expressions offline and verify checks units, neither starts the scheduler. systemctl list-timers queries live timers only in a systemd environment.
Choose the time basis from the requirement: a daily report at a fixed UTC hour uses a calendar expression, whereas a recurring interval after the last activation can use OnUnitActiveSec= with an initial trigger. A calendar calculation with a fixed base time predicts a matching occurrence, not an actual service execution. The timer may delay activation within its configured accuracy and delay settings; check both the timer and the resulting service in an authorized VM.
Try the examples
Explicit UTC avoids ambiguity in the example.
Expected stdout:
OnCalendar=*-*-* 02:30:00 UTCPersistent=trueUnit=bm-report.serviceTZ=UTC systemd-analyze calendar --base-time='2025-01-01 00:00:00 UTC' '*-*-* 02:30:00 UTC' | grep 'Next elapse:' | sed 's/^ *//'The reference time is fixed so the next occurrence is reproducible.
Expected stdout:
Next elapse: Wed 2025-01-01 02:30:00 UTCsystemd-analyze verify ./bm-report.timer ./bm-report.service && printf "units verified\n"Offline validation is not evidence that the service was activated.
Expected stdout:
units verifiedCommon mistakes
Do not assume Persistent applies to monotonic timers or means every missed run is replayed. Do not enable the sample on the host.
Practice
In a fresh fixture, replace the calendar expression with OnBootSec=5min and remove Persistent; verify the pair and explain the different time basis.
Related references
Study: systemctl, systemd-analyze. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Systemd timers — Knowledge Check
Apply log, clock and scheduling concepts to private fixtures and VM-only scenarios.
Which directive specifies wall-clock scheduling?
What can Persistent=true do for a calendar timer?
What does systemd-analyze verify prove?
What does OnBootSec=5min express?