1

I have myscript.service and I want this service to start every hour. So I wrote myscript.timer

Description=My script timer

[Timer]
OnCalendar=hourly
;OnCalendar=*-*-* 0/2:00:00

[Install]
WantedBy=timers.target

I started systemctl enable --now myscript.timer, then systemctl status myscript.timer And I got

[user@localhost ~]$ sudo systemctl status myscript.timer
● myscript.timer - My script timer
     Loaded: loaded (/etc/systemd/system/myscript.timer; enabled; vendor preset: disabled)
     Active: active (waiting) since Tue 2020-09-01 12:10:54 +05; 4s ago
    Trigger: Tue 2020-09-01 16:31:29 +05; 4h 20min left
   Triggers: ● myscript.service

Sep 01 12:10:54 localhost.localdomain systemd[1]: Started My script timer.

And I can't understand why it's not trigger in an hour?

1 Answer 1

1

Unfortunately, I'm not reproducing the issue you're seeing. Judging by the commented ;OnCalendar=, you've been changing the field. Are you sure that you used systemctl daemon-reload between the edit and starting the timer?

When I test it out on my system I see:

$ systemctl --user cat mytime.timer
# /home/stew/.config/systemd/user/mytime.timer
[Unit]
Description=Test timer

[Timer]
OnCalendar=hourly


$ systemctl --user start mytime.timer
$ systemctl --user status mytime.timer
● mytime.timer - Test timer
     Loaded: loaded (/home/stew/.config/systemd/user/mytime.timer; static)
     Active: active (waiting) since Tue 2020-09-01 09:49:14 CEST; 7s ago
    Trigger: Tue 2020-09-01 10:00:00 CEST; 10min left
   Triggers: ● mytime.service

Sep 01 09:49:14 stewbian systemd[1691]: Started Test timer.

Then I waited 10m for the first timer to expire and got:


$ journalctl --user -u mytime.timer -u mytime.service
-- Logs begin at Mon 2020-07-06 04:41:08 CEST, end at Tue 2020-09-01 10:00:00 CEST. --
Sep 01 09:49:14 stewbian systemd[1691]: Started Test timer.
Sep 01 10:00:00 stewbian systemd[1691]: Starting mytime.service...
Sep 01 10:00:00 stewbian systemd[1691]: mytime.service: Succeeded.
Sep 01 10:00:00 stewbian systemd[1691]: Finished mytime.service.


$ systemctl --user status mytime.timer
● mytime.timer - Test timer
     Loaded: loaded (/home/stew/.config/systemd/user/mytime.timer; static)
     Active: active (waiting) since Tue 2020-09-01 09:49:14 CEST; 10min ago
    Trigger: Tue 2020-09-01 11:00:00 CEST; 59min left
   Triggers: ● mytime.service

Sep 01 09:49:14 stewbian systemd[1691]: Started Test timer.

In this case, I used OnCalendar=hourly. The first trigger was at the start of the next hour. The second trigger is set for the start of the following hour.


Since I suspect the issue is a daemon-reload, I tried to reproduce your problem by changing OnCalendar=. I found:

  1. If I use systemctl daemon-reload the change is applied
  2. If I systemctl stop then systemctl start, the change is applied, even without a daemon-reload.
  3. If I systemctl start without stopping the previous timer, the change is not applied and I get a warning about this:
$ systemctl --user start mytime.timer
Warning: The unit file, source configuration file or drop-ins of mytime.timer
  changed on disk. Run 'systemctl --user daemon-reload' to reload units.
4
  • I stopped the timer, just in case reloaded daemon and started timer again. But it doesn't work pastebin.com/K1Jvt6MR Commented Sep 1, 2020 at 8:22
  • That's a nice sterile log. You're definitely doing everything right, I'm not sure why this problem is happening. Commented Sep 1, 2020 at 8:51
  • I have no words... It's triggered at 16:31:29 and then it works correctly Commented Sep 1, 2020 at 17:16
  • Great! Fortunately the initial trigger is usually not so important when you are driving a timer on a machine that is always on. But it's super annoying when we are testing. Commented Sep 1, 2020 at 19:40

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.