You are not logged in.
Hi all,
I'm in the midst of switching from cron to systemd timers, and confused by a behavior I'm seeing: If I configure a timer unit to fire once a minute on the :00 second, it runs every minute, but rarely/never actually runs at :00. I have seen this happen where the second on which it runs changes regularly, but most of the time it keeps running at the same time (e.g., on the :32 second of the minute currently).
Minimal example that reproduces this on my machine:
# ~/.config/systemd/user/foo.service
[Unit]
Description=Run doit.sh
[Service]
ExecStart="/home/ada/doit.sh"
# ~/.config/systemd/user/foo.timer
[Unit]
Description=Run foo.service once a minute at :00
[Timer]
OnCalendar=*-*-* *:*:00
Unit=foo.service
[Install]
WantedBy=timers.target
# ~/doit.sh
#!/usr/bin/sh
echo $(date)
Example output of systemctl --user list-timers showing that systemd intends to run the service on the next :00 second, but that its last run didn't occur at :00
NEXT LEFT LAST PASSED UNIT ACTIVATES
Tue 2025-06-17 08:45:00 EDT 20s Tue 2025-06-17 08:44:12 EDT 26s ago foo.timer foo.service
Possibly related: a lot of the time (but not all the time, haven't figured out if there's a pattern yet) when I run systemctl --user list-timers, I see output that looks like this, with NEXT blank and it claiming that the job ran 1ms ago. But if I run it again, I get an output similar to the previous one.
NEXT LEFT LAST PASSED UNIT ACTIVATES
- - Tue 2025-06-17 08:46:12 EDT 1ms ago foo.timer foo.service
Finally, the relveant journal entries:
> journalctl --user -S '5 minutes ago' --unit foo.service --unit foo.timer
Jun 17 08:53:14 mosscap systemd[1055]: Started Run foo.service once a minute at :00.
Jun 17 08:53:14 mosscap systemd[1055]: Started Run doit.sh.
Jun 17 08:53:14 mosscap doit.sh[3178774]: Tue Jun 17 08:53:14 AM EDT 2025
Jun 17 08:54:32 mosscap systemd[1055]: Started Run doit.sh.
Jun 17 08:54:32 mosscap doit.sh[3178925]: Tue Jun 17 08:54:32 AM EDT 2025
Jun 17 08:55:32 mosscap systemd[1055]: Started Run doit.sh.
Jun 17 08:55:32 mosscap doit.sh[3179047]: Tue Jun 17 08:55:32 AM EDT 2025
Jun 17 08:56:32 mosscap systemd[1055]: Started Run doit.sh.
Jun 17 08:56:32 mosscap doit.sh[3179144]: Tue Jun 17 08:56:32 AM EDT 2025
tl;dr: Why does my "every minute on the :00th second" OnCalendar timer instead run "every minute on the :32nd second"?
Last edited by eletari (2025-06-17 13:33:37)
Offline
Seems to be related to RandomizedDelaySec
Offline
Note that timers do not necessarily expire at the precise time configured with this setting, as it is subject to the AccuracySec= setting below.
Inofficial first vice president of the Rust Evangelism Strike Force
Offline
systemd.timer wrote:Note that timers do not necessarily expire at the precise time configured with this setting, as it is subject to the AccuracySec= setting below.
Ha, simple enough! That fixes it, thanks for the pointer, I spent a lot of time digging through man pages and search results but hadn't noticed that setting. Gives me the confidence that things are working as intended, rather than exhibiting enough confusing behavior that I wouldn't have been confident I'd set things up right.
Offline