Timers (.timer)

Run a job N minutes after boot, then on an interval (OnBootSec / OnUnitActiveSec)

3 min read

OnCalendar= is wall-clock. Sometimes you want relative timing instead: “a bit after boot, then every so often.” That’s what the monotonic timer options do — ideal for pollers, health checks, and report jobs that shouldn’t all fire at midnight.

The timer

/etc/systemd/system/healthcheck.timer:

[Unit]
Description=Health check shortly after boot, then every 15 min

[Timer]
OnBootSec=2min
OnUnitActiveSec=15min

[Install]
WantedBy=timers.target

With its paired healthcheck.service (a Type=oneshot, no [Install]):

[Unit]
Description=Run health check

[Service]
Type=oneshot
ExecStart=/usr/local/bin/healthcheck.sh

The monotonic options

All accept friendly spans: 30s, 2min, 15min, 1h, 1h30min.

Enable and verify

sudo systemctl daemon-reload
sudo systemctl enable --now healthcheck.timer
systemctl list-timers healthcheck.timer

Calendar vs monotonic: use OnCalendar= for “at 03:30”, monotonic options for “every 15 min from boot”. You can combine several On*Sec= lines in one timer (any of them firing triggers the service). Gotcha: OnUnitActiveSec= only repeats if the service actually ran at least once — that’s why pairing it with OnBootSec= (the first kick) is the usual pattern.

Open the full version (with copy buttons) ↗

← All recipes