5

I have a service that runs every hour (using OnCalendar=hourly). This works great if the system is on 24/7, but gets messed up after coming out of suspend/hibernation. The service will run immediately - which is what I want - but then it runs again at the top of each hour, regardless of how much time has elapsed since the last run.

Is there a way to configure timers to run in 1-hour intervals?

0

1 Answer 1

4

You can see detailed examples into the Arch-wiki for systemd timers.

For your case, you can use a monotonic timer, something like:

[Timer]
OnBootSec=1min
OnUnitActiveSec=1h

The realtime timer OnCalendar=hourly will run after boot (for the missed hour, because of your Persistent=true I guess) and then will follow fixed datetime values, so as you describe, the interval between the first two runs after boot, can be less than an hour.

But you maybe don't want to use the monotonic timer, although it is covering what you want about suspendings, if you don't want this behaviour when rebooting. Persistent=false would fit for your case then, but all runs will be on fixed times.

5
  • I tried both "Persistent=" settings and neither worked. I'll give this a test and let you know. Commented May 27, 2022 at 19:33
  • I added a small update. What about reboots (not suspends)? It always run at boot with the first case.
    – thanasisp
    Commented May 27, 2022 at 19:34
  • I only reboot when I update the system, so the hourly timer has already triggered. Like I said, I don't care if the timer runs after suspend/reboot at 8:59, just don't want it to run again at 9:00. Commented May 27, 2022 at 19:36
  • Then probably hourly, no Persistent, don't run at boot, only at fixed times. If avoiding close runs is more important. I mean if rebooting at 8:10, you 'll run 8:00,8:10,9:10 etc with the first. 8 and 9 with no persistent & hourly.
    – thanasisp
    Commented May 27, 2022 at 20:03
  • OK, using OnUnitActiveSec=1h and removing OnCalendar= seems to have worked. Thanks! Commented May 28, 2022 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .