I cannot understand how systemd timers are supposed to behave when the host is suspended:
Here is a simple service: foo.service
[Unit]
Description=Test timer
[Service]
Type=simple
ExecStart=echo "TEST TIMER"
And the corresponding timer: foo.timer
[Unit]
Description=Run foo every day
[Timer]
OnCalendar=Mon..Sun 17:47:00
If I start the timer, suspend the host with systemctl suspend
a few seconds before the timer elapses, and wake the system up a few minutes later, the timer is triggered, and TEST TIMER is printed in journald.
The systemd debug log roughly says:
Nov 03 17:53:27 footest kernel: PM: suspend exit
Nov 03 17:53:27 footest kernel: random: crng reseeded on system resumption
Nov 03 17:53:27 footest kernel: Restarting tasks ... done.
Nov 03 17:53:27 footest systemd[1]: foo.timer: Timer elapsed.
Nov 03 17:53:27 footest kernel: OOM killer enabled.
Nov 03 17:53:27 footest kernel: ata1.00: configured for UDMA/133
Nov 03 17:53:27 footest kernel: ata1: SATA link up 3.0 Gbps (SStatus 123 SControl 300)
Nov 03 17:53:27 footest kernel: sd 0:0:0:0: [sda] Starting disk
and then
Nov 03 17:53:27 footest echo[434]: TEST TIMER
However that timer is not persistent, and should not be triggered as far as I understand. OnClockChange is also set to false.
Halting and restarting the host does not trigger the timer, probably because the whole timer is stopped before shutting down.
This is on a freshly installed Arch VM.
If this is the expected behavior, I take it the only way to disable the timer is to play with the sleep.target dependencies ?
My use case is the following if it matters: I'd like to suspend the host every day at a given time. However if I manually suspend the host some time before the timer elapses, the timer will trigger as soon as the host wakes up, which is not ideal…
EDIT: as per https://github.com/systemd/systemd/issues/26166#issuecomment-1581501093
This is the expected behaviour for a systemd timer:
Generally, system suspend/hibernate across the system is mostly treated as a large scheduling latency, and all programs will "catch up" on what they were missing when coming back from suspend. And so does systemd.