30

I'm trying to make a systemd timer that runs every 15 minutes. Right now I have:

  • timer-fifteen.timer:

    [Unit]
    Description=15min timer
    
    [Timer]
    OnBootSec=0min
    OnCalendar=*:*:0,15,30,45
    Unit=timer-fifteen.target
    
    [Install]
    WantedBy=basic.target  
    
  • timer-fifteen.target:

    [Unit]
    Description=15min Timer Target
    StopWhenUnneeded=yes
    

This runs over and over again without stopping. Does it need to be *:0,15,30,45:* instead? How can I make this work?

  • 2
    Doesn't your syntax mean every 15 seconds? – Pavel Šimerda Apr 27 '14 at 18:04
38

Your syntax translates to every 15 seconds, if you want every 15 minutes, IMO the most readable way is:

OnCalendar=*:0/15

An answer most similar to what you use in your question is:

OnCalendar=*:0,15,30,45

More information:

  • 3
    OnCalendar=0/8:00:00 is correct for saying "run every 8 hours"? – shackra Dec 26 '15 at 20:01
  • 4
    Yes. But you probably already know that by now. :) – Pavel Šimerda Jan 5 '16 at 12:47
  • I didn't, but I used that anyway lol. Thank you for confirming! – shackra Jan 7 '16 at 3:06
  • OnCalendar=*:0/15 should translate to OnCalendar=*:0,15,30,45 exactly (given I read it correctly in the docs). Every 8 hours would be realised with OnUnitActiveSec=8hours. – Debilski Jul 6 '16 at 10:53
  • 3
    When specifying an interval, the output of systemd-analyze may come in handy, for example try systemd-analyze calendar *:0/15. – sebastian Mar 5 '18 at 8:28
12

According to the systemd.time, the setting

OnCalendar=*:0/15

translates exactly to

OnCalendar=*:0,15,30,45

ie. it activates the unit exactly at the full hour, as well as at quarter past, half past and half to.

Depending on your service, this may not be what you want, nor what you need in all cases.

A timer that runs every 15 minutes – for example at 1:02, 1:17, 1:32, 1:47, 2:02, … – always depending on the time it was last run – can be accomplished with the systemd.timer setting

OnUnitActiveSec=15min

Now, you will also want the unit to start some time after boot (unless you want to activate the unit manually or have a dependency which does that), so you should maybe specify

OnBootSec=10min
OnUnitActiveSec=15min

to have the unit started 10 minutes after boot and then every 15 minutes after that first time.

Additionally, there is the setting OnUnitInactiveSec which starts counting the time after the service has stopped (or, more generally, the unit has inactivated).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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