Adding delay between stop and start of a process in systemd
I have a really strange issue with systemd
. When I issue a systemctl restart
it will start the new process before the previous one finishes.
This can be seen in the log, where the final shutdown message ("closing log") is logged after the startup message ("opening log").
Is there any way to add a delay between the stop and the start of process?
systemd services
add a comment |
I have a really strange issue with systemd
. When I issue a systemctl restart
it will start the new process before the previous one finishes.
This can be seen in the log, where the final shutdown message ("closing log") is logged after the startup message ("opening log").
Is there any way to add a delay between the stop and the start of process?
systemd services
Nothing stopping you from runningsystemctl stop myservice && sleep 3 && systemctl start myservice
– don_crissti
Jul 11 '16 at 11:17
Why is that strange? It's a design feature to leave you alone to work around real world issues. Inject the sleep in your Unit start or use an ExecPre condition to ensure the old instance is fully gone.
– Florian Heigl
Dec 9 '16 at 15:53
add a comment |
I have a really strange issue with systemd
. When I issue a systemctl restart
it will start the new process before the previous one finishes.
This can be seen in the log, where the final shutdown message ("closing log") is logged after the startup message ("opening log").
Is there any way to add a delay between the stop and the start of process?
systemd services
I have a really strange issue with systemd
. When I issue a systemctl restart
it will start the new process before the previous one finishes.
This can be seen in the log, where the final shutdown message ("closing log") is logged after the startup message ("opening log").
Is there any way to add a delay between the stop and the start of process?
systemd services
systemd services
asked Feb 9 '16 at 12:15
Let_Me_BeLet_Me_Be
4,44483257
4,44483257
Nothing stopping you from runningsystemctl stop myservice && sleep 3 && systemctl start myservice
– don_crissti
Jul 11 '16 at 11:17
Why is that strange? It's a design feature to leave you alone to work around real world issues. Inject the sleep in your Unit start or use an ExecPre condition to ensure the old instance is fully gone.
– Florian Heigl
Dec 9 '16 at 15:53
add a comment |
Nothing stopping you from runningsystemctl stop myservice && sleep 3 && systemctl start myservice
– don_crissti
Jul 11 '16 at 11:17
Why is that strange? It's a design feature to leave you alone to work around real world issues. Inject the sleep in your Unit start or use an ExecPre condition to ensure the old instance is fully gone.
– Florian Heigl
Dec 9 '16 at 15:53
Nothing stopping you from running
systemctl stop myservice && sleep 3 && systemctl start myservice
– don_crissti
Jul 11 '16 at 11:17
Nothing stopping you from running
systemctl stop myservice && sleep 3 && systemctl start myservice
– don_crissti
Jul 11 '16 at 11:17
Why is that strange? It's a design feature to leave you alone to work around real world issues. Inject the sleep in your Unit start or use an ExecPre condition to ensure the old instance is fully gone.
– Florian Heigl
Dec 9 '16 at 15:53
Why is that strange? It's a design feature to leave you alone to work around real world issues. Inject the sleep in your Unit start or use an ExecPre condition to ensure the old instance is fully gone.
– Florian Heigl
Dec 9 '16 at 15:53
add a comment |
2 Answers
2
active
oldest
votes
In your systemd service files, you can set RestartSec option to add a delay for restart. See example below:
[Service]
Restart=always
RestartSec=30
Check this link for more examples.
afaikRestartSec
only applies to services configured with theRestart=
directive and is not taken into account when doing asystemctl restart someservice
– don_crissti
Jul 11 '16 at 11:17
add a comment |
RestartSec seems to only be used if that particular service is the one being restarted via the systemctl restart command.
For example, I have two services, A and B.
[Unit]
Requires=network-online.target
[Service]
ExecStart=A-stuff
Restart=always
and
[Unit]
Requires=A.service
After=A.service
[Service]
ExecStart=B-stuff
Restart=always
RestartSec=30
If you do a systemctl restart B, it works as expected... but if you do a systemctl restart A, both services are stopped and immediately started again, with no delay.
Systemd is apparently only using the configuration values for the one service you specify, and ignoring them for any dependencies.
This is not as uncommon as it sounds. If B talks to a remote server, starting and stopping quickly may fail due to the remote end rejecting the client. But restarting A directly will happen whenever A is updated without a change to B.
You can probably work around this by adding the delay to A as well, but you shouldn't NEED to do this, as it breaks object isolation by making A know about B when it's not a dependency.
add a comment |
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%2f260973%2fadding-delay-between-stop-and-start-of-a-process-in-systemd%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
In your systemd service files, you can set RestartSec option to add a delay for restart. See example below:
[Service]
Restart=always
RestartSec=30
Check this link for more examples.
afaikRestartSec
only applies to services configured with theRestart=
directive and is not taken into account when doing asystemctl restart someservice
– don_crissti
Jul 11 '16 at 11:17
add a comment |
In your systemd service files, you can set RestartSec option to add a delay for restart. See example below:
[Service]
Restart=always
RestartSec=30
Check this link for more examples.
afaikRestartSec
only applies to services configured with theRestart=
directive and is not taken into account when doing asystemctl restart someservice
– don_crissti
Jul 11 '16 at 11:17
add a comment |
In your systemd service files, you can set RestartSec option to add a delay for restart. See example below:
[Service]
Restart=always
RestartSec=30
Check this link for more examples.
In your systemd service files, you can set RestartSec option to add a delay for restart. See example below:
[Service]
Restart=always
RestartSec=30
Check this link for more examples.
answered Jul 11 '16 at 6:06
mmohammadmmohammad
19112
19112
afaikRestartSec
only applies to services configured with theRestart=
directive and is not taken into account when doing asystemctl restart someservice
– don_crissti
Jul 11 '16 at 11:17
add a comment |
afaikRestartSec
only applies to services configured with theRestart=
directive and is not taken into account when doing asystemctl restart someservice
– don_crissti
Jul 11 '16 at 11:17
afaik
RestartSec
only applies to services configured with the Restart=
directive and is not taken into account when doing a systemctl restart someservice
– don_crissti
Jul 11 '16 at 11:17
afaik
RestartSec
only applies to services configured with the Restart=
directive and is not taken into account when doing a systemctl restart someservice
– don_crissti
Jul 11 '16 at 11:17
add a comment |
RestartSec seems to only be used if that particular service is the one being restarted via the systemctl restart command.
For example, I have two services, A and B.
[Unit]
Requires=network-online.target
[Service]
ExecStart=A-stuff
Restart=always
and
[Unit]
Requires=A.service
After=A.service
[Service]
ExecStart=B-stuff
Restart=always
RestartSec=30
If you do a systemctl restart B, it works as expected... but if you do a systemctl restart A, both services are stopped and immediately started again, with no delay.
Systemd is apparently only using the configuration values for the one service you specify, and ignoring them for any dependencies.
This is not as uncommon as it sounds. If B talks to a remote server, starting and stopping quickly may fail due to the remote end rejecting the client. But restarting A directly will happen whenever A is updated without a change to B.
You can probably work around this by adding the delay to A as well, but you shouldn't NEED to do this, as it breaks object isolation by making A know about B when it's not a dependency.
add a comment |
RestartSec seems to only be used if that particular service is the one being restarted via the systemctl restart command.
For example, I have two services, A and B.
[Unit]
Requires=network-online.target
[Service]
ExecStart=A-stuff
Restart=always
and
[Unit]
Requires=A.service
After=A.service
[Service]
ExecStart=B-stuff
Restart=always
RestartSec=30
If you do a systemctl restart B, it works as expected... but if you do a systemctl restart A, both services are stopped and immediately started again, with no delay.
Systemd is apparently only using the configuration values for the one service you specify, and ignoring them for any dependencies.
This is not as uncommon as it sounds. If B talks to a remote server, starting and stopping quickly may fail due to the remote end rejecting the client. But restarting A directly will happen whenever A is updated without a change to B.
You can probably work around this by adding the delay to A as well, but you shouldn't NEED to do this, as it breaks object isolation by making A know about B when it's not a dependency.
add a comment |
RestartSec seems to only be used if that particular service is the one being restarted via the systemctl restart command.
For example, I have two services, A and B.
[Unit]
Requires=network-online.target
[Service]
ExecStart=A-stuff
Restart=always
and
[Unit]
Requires=A.service
After=A.service
[Service]
ExecStart=B-stuff
Restart=always
RestartSec=30
If you do a systemctl restart B, it works as expected... but if you do a systemctl restart A, both services are stopped and immediately started again, with no delay.
Systemd is apparently only using the configuration values for the one service you specify, and ignoring them for any dependencies.
This is not as uncommon as it sounds. If B talks to a remote server, starting and stopping quickly may fail due to the remote end rejecting the client. But restarting A directly will happen whenever A is updated without a change to B.
You can probably work around this by adding the delay to A as well, but you shouldn't NEED to do this, as it breaks object isolation by making A know about B when it's not a dependency.
RestartSec seems to only be used if that particular service is the one being restarted via the systemctl restart command.
For example, I have two services, A and B.
[Unit]
Requires=network-online.target
[Service]
ExecStart=A-stuff
Restart=always
and
[Unit]
Requires=A.service
After=A.service
[Service]
ExecStart=B-stuff
Restart=always
RestartSec=30
If you do a systemctl restart B, it works as expected... but if you do a systemctl restart A, both services are stopped and immediately started again, with no delay.
Systemd is apparently only using the configuration values for the one service you specify, and ignoring them for any dependencies.
This is not as uncommon as it sounds. If B talks to a remote server, starting and stopping quickly may fail due to the remote end rejecting the client. But restarting A directly will happen whenever A is updated without a change to B.
You can probably work around this by adding the delay to A as well, but you shouldn't NEED to do this, as it breaks object isolation by making A know about B when it's not a dependency.
answered Jan 19 at 0:45
Dread QuixadhalDread Quixadhal
1
1
add a comment |
add a comment |
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.
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%2f260973%2fadding-delay-between-stop-and-start-of-a-process-in-systemd%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
Nothing stopping you from running
systemctl stop myservice && sleep 3 && systemctl start myservice
– don_crissti
Jul 11 '16 at 11:17
Why is that strange? It's a design feature to leave you alone to work around real world issues. Inject the sleep in your Unit start or use an ExecPre condition to ensure the old instance is fully gone.
– Florian Heigl
Dec 9 '16 at 15:53