What is the difference between `OnCalendar=`, `OnBootSec=` and `OnUnitActiveSec=`?
AdvancedConceptcron and systemd timers
Answer
OnCalendar=is wall-clock time (realtime timer):daily,Mon..Fri 09:00,*-*-01 00:00:00,*:0/15(every 15 minutes).OnBootSec=is time since boot (monotonic).OnUnitActiveSec=is time since the service was last activated;OnUnitInactiveSec=since it last finished.
[Timer]
OnBootSec=2min
OnUnitActiveSec=5min # every 5 minutes after the first run
Monotonic timers need a starting point: OnUnitActiveSec= alone never fires if the service has never run, which is why it is paired with OnBootSec= (or OnActiveSec=).
More on cron and systemd timers
Explain the five cron time fields with examples.BeginnerWhat is different about the environment a cron job runs in?BeginnerWhat is the difference between a user crontab, `/etc/crontab`, `/etc/cron.d/` and `/etc/cron.daily/`?IntermediateHow do you prevent overlapping cron runs and capture output properly?IntermediateWhat is a systemd timer and how does it compare to cron?IntermediateWrite a minimal systemd service and timer that run a backup at 02:30 daily.Intermediate