4

This question already has an answer here:

I use systemd-cron which creates unit files under /lib/systemd. The unit file for cron-daily.timer has

[Timer]
OnCalendar=daily

This triggers the scripts at midnight. I want them to trigger at 3am instead.

If I create override.conf in the cron-daily.timer.d directory under /etc/systemd/system to have

[Timer]
OnCalendar=*-*-* 03:00:00

and run daemon-reload, restart the timer and run systemctl list-timers it still wants to run at 00:00:00. However, if I change my override.conf to have

[Timer]
OnCalendar=hourly

then it wants to run hourly as expected. Why can I not override the service to run at a specific time?

marked as duplicate by JdeBP, Community Nov 4 '18 at 17:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4

systemd timer units can take multiple OnCalendar= specifications, so when you're creating your override to run at 3am, you're actually adding that time (making it run twice daily, at midnight and 3am.)

When you list the timer, it will show you the next schedule for it and, unless you're running that command between midnight and 3am, what you'll see is the original run at midnight, possibly giving you the impression that your configuration didn't work. (When you set it to hourly you'll likely see a change, unless you run the command between 11pm and midnight.)

To change the cron daily runs so they run at 3am using an override file, simply clear the previous definition (daily) first, which you can do by setting OnCalendar= to an empty value.

[Timer]
OnCalendar=
OnCalendar=*-*-* 03:00:00

systemd man page for timer units actually documents this, though you'll find it under OnActiveSec= and friends, which says:

If the empty string is assigned to any of these options, the list of timers is reset, and all prior assignments will have no effect.

  • 1
    Thanks, I read the docs a few times and obviously missed the bit about it being additive unless cleared. – Steven Davies Nov 4 '18 at 16:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.