Is there a way to know when a systemd timer will run next?
The state of currently active timers can be shown using
systemctl list-timers
:
$ systemctl list-timers --all
NEXT LEFT LAST PASSED UNIT ACTIVATES
Wed 2016-12-14 08:06:15 CET 21h left Tue 2016-12-13 08:06:15 CET 2h 18min ago systemd-tmpfiles-clean.timer systemd-tmpfiles-clean.service
1 timers listed.
From @phg comment and answer, I found a page with the answer. The timers are cumulative and you need to reset them first otherwise the previous entry stays around. This is useful for calendars, but it works the same with all timers.
Having one entry which resets the timer before changing it to a new value works as expected:
# This file was auto-generated by snapmanager.cgi
# Feel free to do additional modifications here as
# snapmanager.cgi will be aware of them as expected.
[Timer]
OnUnitActiveSec=
OnUnitActiveSec=30min
No, there does not appear a way see exactly when a timer when will run next. systemd
offers systemctl list-timers
and systemctl status something.timer
, but those don't show the affect of AccuracySec=
and possibly other directives that shift the time.
If you set AccuracySec=1h
on two servers, they will both report that the same timer on both servers will fire at the exact same time, but in fact they could start up to an hour apart! If you are interested to know if two randomized timers might collide, there appears to be no way to check the final calculated run time to find out.
There is a systemd issue open to make the output of list-timers more accurate / less confusing.
Additionally, there is RandomizedDelaySec
option that will be combined with AccuracySec
as per the man page.