systemd timer every 15 minutes

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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:

Method 2

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 quarter 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).


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x