How to make systemd timer run exactly every 10 minutes, with a task that lasts slightly longer than that?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












1














I have a rather annoying issue with systemd timers and drifting start time. I had an old cron.d script (which executed faithfully once every 10 minutes) that I'm trying to modernize. The problem is that the service it starts runs a while longer than 10 minutes. With cron this was not an issue, I simply had two instances running for a while, but systemd does not work the same.



The timer is as follows:



[Timer]
OnCalendar=*:0/10:0
Persistent=false
AccuracySec=1s


and from what I understand, this is supposed to run at exactly 08:00:00, 08:10:00, 08:20:00, and so on and so forth. But the associated service it starts runs slightly longer than 10 minutes, and this causes the timer to gradually drift by about 10 seconds per run. Meaning the start times are 08:00:00, 08:10:10, 08:20:20 and so on. Is there any way to force the timer to do exactly as I want?



I've also attempted to make the service to run in the background, unmonitored by systemd, but I have not had much success with this. Tried things like ExecStart=/bin/sh -c "/run/my/cmd -options &" and with nohup and putting the whole command in a separate shell script to no avail. The cmd is not started or dies immediately.



So how can I make my systemd timer behave like the old cron script? My only remaining idea/workaround is to make two timers, set at 20 minute intervals, but that sounds like a really dumb idea..










share|improve this question





















  • Not an exact duplicate, but close: unix.stackexchange.com/q/203254/173368
    – Haxiel
    Dec 12 at 13:09










  • Yes I've seen that post, and I want exactly the kind of behavior they're trying to avoid. This is what led me to thinking I should figure out some good way of starting the service "in the background" without systemd being aware of it or monitoring it in any way.
    – Teemu Karimerto
    Dec 12 at 13:53















1














I have a rather annoying issue with systemd timers and drifting start time. I had an old cron.d script (which executed faithfully once every 10 minutes) that I'm trying to modernize. The problem is that the service it starts runs a while longer than 10 minutes. With cron this was not an issue, I simply had two instances running for a while, but systemd does not work the same.



The timer is as follows:



[Timer]
OnCalendar=*:0/10:0
Persistent=false
AccuracySec=1s


and from what I understand, this is supposed to run at exactly 08:00:00, 08:10:00, 08:20:00, and so on and so forth. But the associated service it starts runs slightly longer than 10 minutes, and this causes the timer to gradually drift by about 10 seconds per run. Meaning the start times are 08:00:00, 08:10:10, 08:20:20 and so on. Is there any way to force the timer to do exactly as I want?



I've also attempted to make the service to run in the background, unmonitored by systemd, but I have not had much success with this. Tried things like ExecStart=/bin/sh -c "/run/my/cmd -options &" and with nohup and putting the whole command in a separate shell script to no avail. The cmd is not started or dies immediately.



So how can I make my systemd timer behave like the old cron script? My only remaining idea/workaround is to make two timers, set at 20 minute intervals, but that sounds like a really dumb idea..










share|improve this question





















  • Not an exact duplicate, but close: unix.stackexchange.com/q/203254/173368
    – Haxiel
    Dec 12 at 13:09










  • Yes I've seen that post, and I want exactly the kind of behavior they're trying to avoid. This is what led me to thinking I should figure out some good way of starting the service "in the background" without systemd being aware of it or monitoring it in any way.
    – Teemu Karimerto
    Dec 12 at 13:53













1












1








1







I have a rather annoying issue with systemd timers and drifting start time. I had an old cron.d script (which executed faithfully once every 10 minutes) that I'm trying to modernize. The problem is that the service it starts runs a while longer than 10 minutes. With cron this was not an issue, I simply had two instances running for a while, but systemd does not work the same.



The timer is as follows:



[Timer]
OnCalendar=*:0/10:0
Persistent=false
AccuracySec=1s


and from what I understand, this is supposed to run at exactly 08:00:00, 08:10:00, 08:20:00, and so on and so forth. But the associated service it starts runs slightly longer than 10 minutes, and this causes the timer to gradually drift by about 10 seconds per run. Meaning the start times are 08:00:00, 08:10:10, 08:20:20 and so on. Is there any way to force the timer to do exactly as I want?



I've also attempted to make the service to run in the background, unmonitored by systemd, but I have not had much success with this. Tried things like ExecStart=/bin/sh -c "/run/my/cmd -options &" and with nohup and putting the whole command in a separate shell script to no avail. The cmd is not started or dies immediately.



So how can I make my systemd timer behave like the old cron script? My only remaining idea/workaround is to make two timers, set at 20 minute intervals, but that sounds like a really dumb idea..










share|improve this question













I have a rather annoying issue with systemd timers and drifting start time. I had an old cron.d script (which executed faithfully once every 10 minutes) that I'm trying to modernize. The problem is that the service it starts runs a while longer than 10 minutes. With cron this was not an issue, I simply had two instances running for a while, but systemd does not work the same.



The timer is as follows:



[Timer]
OnCalendar=*:0/10:0
Persistent=false
AccuracySec=1s


and from what I understand, this is supposed to run at exactly 08:00:00, 08:10:00, 08:20:00, and so on and so forth. But the associated service it starts runs slightly longer than 10 minutes, and this causes the timer to gradually drift by about 10 seconds per run. Meaning the start times are 08:00:00, 08:10:10, 08:20:20 and so on. Is there any way to force the timer to do exactly as I want?



I've also attempted to make the service to run in the background, unmonitored by systemd, but I have not had much success with this. Tried things like ExecStart=/bin/sh -c "/run/my/cmd -options &" and with nohup and putting the whole command in a separate shell script to no avail. The cmd is not started or dies immediately.



So how can I make my systemd timer behave like the old cron script? My only remaining idea/workaround is to make two timers, set at 20 minute intervals, but that sounds like a really dumb idea..







systemd cron systemd-timer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 12 at 12:04









Teemu Karimerto

465




465











  • Not an exact duplicate, but close: unix.stackexchange.com/q/203254/173368
    – Haxiel
    Dec 12 at 13:09










  • Yes I've seen that post, and I want exactly the kind of behavior they're trying to avoid. This is what led me to thinking I should figure out some good way of starting the service "in the background" without systemd being aware of it or monitoring it in any way.
    – Teemu Karimerto
    Dec 12 at 13:53
















  • Not an exact duplicate, but close: unix.stackexchange.com/q/203254/173368
    – Haxiel
    Dec 12 at 13:09










  • Yes I've seen that post, and I want exactly the kind of behavior they're trying to avoid. This is what led me to thinking I should figure out some good way of starting the service "in the background" without systemd being aware of it or monitoring it in any way.
    – Teemu Karimerto
    Dec 12 at 13:53















Not an exact duplicate, but close: unix.stackexchange.com/q/203254/173368
– Haxiel
Dec 12 at 13:09




Not an exact duplicate, but close: unix.stackexchange.com/q/203254/173368
– Haxiel
Dec 12 at 13:09












Yes I've seen that post, and I want exactly the kind of behavior they're trying to avoid. This is what led me to thinking I should figure out some good way of starting the service "in the background" without systemd being aware of it or monitoring it in any way.
– Teemu Karimerto
Dec 12 at 13:53




Yes I've seen that post, and I want exactly the kind of behavior they're trying to avoid. This is what led me to thinking I should figure out some good way of starting the service "in the background" without systemd being aware of it or monitoring it in any way.
– Teemu Karimerto
Dec 12 at 13:53















active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487562%2fhow-to-make-systemd-timer-run-exactly-every-10-minutes-with-a-task-that-lasts-s%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487562%2fhow-to-make-systemd-timer-run-exactly-every-10-minutes-with-a-task-that-lasts-s%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown






Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay