How to make systemd timer run exactly every 10 minutes, with a task that lasts slightly longer than that?
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
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
add a comment |
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
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
systemd cron systemd-timer
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
add a comment |
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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