What systemd timer directives seem to be used in practice

September 7, 2022

Systemd .timer units have a bunch of different On<Thing> directives to define the time when the timer(s) trigger, including OnCalendar=. As I discovered when looking into using timers to run things very frequently, there can be more than one way to get what you want with all of these directives. This variety of options raises a straightforward question, namely what do people seem to do in practice.

I'm not energetic enough to download every Ubuntu or Fedora package that has a timer and look at them all. Instead, I'm looking (only) at the packages installed on the Fedora and Ubuntu systems I have ready access to, and especially the timer units that are actually enabled (things that aren't enabled can have weird things lurking in their depths). Widely installed and enabled timer units sort of set the standard for what people expect.

By far the most popular option is OnCalendar. Unsurprisingly there's a bunch of packages that use 'daily' or 'weekly' as basically a replacement for cron.daily and cron.weekly. Even the Certbot timer unit (on both Ubuntu and Fedora) uses OnCalendar, although it has an interesting trick; it sets itself to run at 00:00 and 12:00 but also has a 12 hour randomized delay, so the actual activation time of all of those Certbot timers is (hopefully) randomized very broadly across the day. This same trick is used by fwupd-refresh.timer, motd-news.timer (in Ubuntu), man-db.timer, and plocate-updatedb.timer (although it only activates once a day so it's not quite the same).

There are a certain number of periodic timer units that don't use OnCalendar, such as update-notifier-download.timer (Ubuntu), systemd-tmpfiles-clean.timer (Fedora), and dnf-makecache.timer (Fedora), along with some non-enabled timers from other things. These three timer units vary both in how they start the timer (OnStartupSec or OnBootSec) and how they repeat it (dnf-makecache uses OnUnitInactiveSec while the other two use OnUnitActiveSec).

(In things we don't have enabled but other people probably do, there's also Ubuntu's apport-autoreport.timer and ua-timer.timer.)

Some timer units combine OnCalendar with a system startup based trigger, such as motd-news.timer (Ubuntu) using OnCalendar and also OnStartupSec. Presumably Ubuntu really wanted the motd news to be refreshed soon after system boot.

On the whole it seems that OnCalendar is the consensus way of doing almost everything, to the point where I'm actually surprised by how few timer units use the other approach. And if you want to run N times a day at random times, you use OnCalendar and then a random delay of your time interval.

Written on 07 September 2022.
« Machine room temperatures and the value of long Prometheus metrics history
Grafana's problem with the order of dashboard panel legends and Prometheus »

Page tools: View Source, Add Comment.
Search:
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Sep 7 22:29:53 2022
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.