[systemd-devel] "OnUnitInactiveSec Timer not firing" issue
Andrei Borzenkov
arvidjaar at gmail.com
Mon Jul 29 07:21:11 UTC 2024
On Mon, Jul 29, 2024 at 9:33 AM Windl, Ulrich <u.windl at ukr.de> wrote:
>
> Hi!
>
>
>
> I tried to use my first systemd timer, but failed: Either I don’t understand it correctly, or there is a bug in systemd (228 of SLES12 SP5):
>
> (See also https://unix.stackexchange.com/q/779714/320598)
>
>
>
> It seems it’s not enough to “enable” the timer, but also “start” it (well, it may seem logical from the systemd point of view, but from a cron user’s point of view enabling should be enough)
>
That is how all systemd units work, it is not specific to timers.
> Furthermore it seems to be necessary to run the service unit itself, too (assuming it must be enabled also, right?)
>
Well, OnUnitInactiveSec is relative to when the unit was last
deactivated. To deactivate a unit it needs to be active first.
> But the biggest thing is that systemd seems to lose the point-in-time of the last activation, so the timer won’t fire any more (e.g. after package upgrade when everything enabled would be re-enabled, and everything started would be re-started).
>
> But most of all if the system reboots, the timer also won’t fire any more.
>
I am not sure about package updates, but if your unit is not started
on boot by some other means, it will not be started by your timer
(because the unit will never be deactivated in the first place).
Try adding Persistent=yes, it should make it behave as you expect (you
still need to start the unit manually at least once to initially
trigger the timer).
Or as described in `man systemd.timer` try adding OnBootSec condition
to start unit after reboot.
>
>
> So can anybody explain how things should work?
>
>
>
> My expectation was that an OnUnitInactiveSec timer would fire immediately if it never ran, and then every day from that.
>
It is not how it is described in the documentation. "Was never active"
is not the same as "was deactivated" which by definition implies that
the unit *was* active.
More information about the systemd-devel
mailing list