All articles

Test a systemd Timer Before You Enable It

7 minutes read


Linux publication

Share this article

𝕏✉

Illustration for Test a systemd Timer Before You Enable It

A timer defines when systemd activates a unit. The paired service defines the work. Validate both files before copying them into /etc/systemd/system.

This workflow was tested with systemd 255 on Ubuntu 24.04.4. The lab parses and verifies local files without installing, enabling, or starting a unit.

Parse the calendar in the host’s timezone

systemd-analyze calendar --iterations=3 'Mon..Fri *-*-* 09:00:00'

The 31 August lab in Europe/Berlin reported:

Normalized form: Mon..Fri *-*-* 09:00:00
    Next elapse: Mon 2026-08-31 09:00:00 CEST
       (in UTC): Mon 2026-08-31 07:00:00 UTC
   Iteration #2: Tue 2026-09-01 09:00:00 CEST
       (in UTC): Tue 2026-09-01 07:00:00 UTC
   Iteration #3: Wed 2026-09-02 09:00:00 CEST
       (in UTC): Wed 2026-09-02 07:00:00 UTC

Exact relative-time lines depend on when you run it. systemd.time defines the calendar grammar, including weekday ranges and explicit timezone suffixes 2. If the job must follow UTC rather than local civil time, say so:

systemd-analyze calendar --iterations=3 'Mon..Fri *-*-* 09:00:00 UTC'

Test dates across daylight-saving changes when local wall time matters.

Build the service and timer as a pair

Create two files in a working directory first.

report.service:

[Unit]
Description=Example report

[Service]
Type=oneshot
ExecStart=/usr/bin/printf report-ready\n

report.timer:

[Unit]
Description=Run example report on weekdays

[Timer]
OnCalendar=Mon..Fri *-*-* 09:00:00
Persistent=true
RandomizedDelaySec=5m
Unit=report.service

[Install]
WantedBy=timers.target

A timer activates the named unit; by convention, a same-basename .timer activates the corresponding .service when Unit= is omitted 1. Keeping Unit= here makes the relationship visible during review.

Persistent=true lets an OnCalendar timer notice that it missed an event while inactive. RandomizedDelaySec=5m deliberately adds bounded jitter, so 09:00 is the base rather than a guaranteed start second 1.

Replace the demonstration printf with one absolute, reviewed executable path. Do not put a shell pipeline directly in ExecStart= and assume shell parsing; systemd does not implicitly run it through a shell.

Verify syntax and references locally

systemd-analyze verify ./report.service ./report.timer
printf 'verify status=%s\n' "$?"

The tested files produced no diagnostic and status 0. systemd-analyze verify loads unit files and reports errors such as unknown directives, missing dependencies, and unavailable executables where it can detect them 3. It cannot prove that the job’s business logic is correct.

Review runtime and overlap behavior

Ask four questions before installation:

  1. What happens if the previous invocation is still active?
  2. Is a missed invocation useful after a long outage?
  3. Should ten hosts run simultaneously, or is jitter desirable?
  4. Which user, environment, working directory, and credentials does the service require?

For a oneshot service, systemd will not start a second copy while the unit is already activating. That is not a universal job queue. Design explicit locking or idempotence when overlapping work matters.

Install only after review

Caution: The next commands persist root-owned unit files, reload the system manager, and enable a timer that can execute future work. Review both files and replace the example action first.

sudo install -m 0644 ./report.service /etc/systemd/system/report.service
sudo install -m 0644 ./report.timer /etc/systemd/system/report.timer
sudo systemctl daemon-reload
sudo systemctl enable --now report.timer

Observe the manager’s calculation and the service’s journal:

systemctl list-timers report.timer --all
systemctl status report.timer --no-pager
journalctl -u report.service --since today --no-pager

To test the action independently of the schedule, use systemctl start report.service only when running the real job now is safe.

Parse the calendar and verify both units first. Then review missed and overlapping runs, install the files, and observe the timer. Enable it only after those checks pass.

Sources and further reading
  1. systemd.timer manual
  2. systemd.time manual
  3. systemd-analyze manual