“Require” seems doesn't work in systemd
There are two services in my system : A and B.
Before start service A I want take some check automate. If check failed service A no need to start.
You may say that I can use ExecStartPre or ExecStartPre. Yes, but it can not stop service A start.
So I want use "require" in systemd, create a new service B who config file like below:
[Unit]
Description=api
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
Before=kubelet.service
[Service]
ExecStart=/bin/bash /root/check_init.sh
Restart=no
[Install]
WantedBy=multi-user.target
/root/check_init.sh like this :
#!/bin/bash
exit 1
service A config as below:
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
After=api.service
Requires=api.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet
$KUBE_LOGTOSTDERR
$KUBE_LOG_LEVEL
$KUBELET_API_SERVER
$KUBELET_ADDRESS
$KUBELET_PORT
$KUBELET_HOSTNAME
$KUBE_ALLOW_PRIV
$KUBELET_POD_INFRA_CONTAINER
$KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
I thought service B start failed, so service A must failed too. However, service A started.
Is there any thing wrong for my config?
Thanks!
linux systemd
add a comment |
There are two services in my system : A and B.
Before start service A I want take some check automate. If check failed service A no need to start.
You may say that I can use ExecStartPre or ExecStartPre. Yes, but it can not stop service A start.
So I want use "require" in systemd, create a new service B who config file like below:
[Unit]
Description=api
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
Before=kubelet.service
[Service]
ExecStart=/bin/bash /root/check_init.sh
Restart=no
[Install]
WantedBy=multi-user.target
/root/check_init.sh like this :
#!/bin/bash
exit 1
service A config as below:
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
After=api.service
Requires=api.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet
$KUBE_LOGTOSTDERR
$KUBE_LOG_LEVEL
$KUBELET_API_SERVER
$KUBELET_ADDRESS
$KUBELET_PORT
$KUBELET_HOSTNAME
$KUBE_ALLOW_PRIV
$KUBELET_POD_INFRA_CONTAINER
$KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
I thought service B start failed, so service A must failed too. However, service A started.
Is there any thing wrong for my config?
Thanks!
linux systemd
unclear why you don't wantExecStartPre
instead, is it that you don't want the main service to be marked failed, but it's ok if this auxilaryapi.service
is?
– sourcejedi
Aug 26 '17 at 10:56
1
Thanks for your answer. I try to useExecStartPre
yesterday, systemd will restart service A again and again until execExecStartPre
script success. The service A inactivating
status, it's worked for me. I also tryType=oneshot
andRemainAfterExit=yes
for service B, its useful too. Service B run one time and if its failed service A will not start successful. The different for those two ways I think is:ExecStartPre
will try to start service A again and again but theType=oneshot
andRemainAfterExit=yes
just only one time. Am I right?
– workhardcc
Aug 27 '17 at 9:21
Ah, that makes sense! I hadn't considered that you had setRestart=
, sorry.
– sourcejedi
Aug 27 '17 at 11:35
kubelet
looks like it's a daemon, in which case it should not beType=oneshot
.
– sourcejedi
Aug 27 '17 at 11:42
1
Yes,kubelet
is a daemon.Type=oneshot
forservice B
not for kubelet(service A),kubelet
needrestart=on-failure
. I think useservice B
notExecStartPre
is better for me. Because I actually want make some test before start the service
– workhardcc
Aug 27 '17 at 12:22
add a comment |
There are two services in my system : A and B.
Before start service A I want take some check automate. If check failed service A no need to start.
You may say that I can use ExecStartPre or ExecStartPre. Yes, but it can not stop service A start.
So I want use "require" in systemd, create a new service B who config file like below:
[Unit]
Description=api
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
Before=kubelet.service
[Service]
ExecStart=/bin/bash /root/check_init.sh
Restart=no
[Install]
WantedBy=multi-user.target
/root/check_init.sh like this :
#!/bin/bash
exit 1
service A config as below:
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
After=api.service
Requires=api.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet
$KUBE_LOGTOSTDERR
$KUBE_LOG_LEVEL
$KUBELET_API_SERVER
$KUBELET_ADDRESS
$KUBELET_PORT
$KUBELET_HOSTNAME
$KUBE_ALLOW_PRIV
$KUBELET_POD_INFRA_CONTAINER
$KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
I thought service B start failed, so service A must failed too. However, service A started.
Is there any thing wrong for my config?
Thanks!
linux systemd
There are two services in my system : A and B.
Before start service A I want take some check automate. If check failed service A no need to start.
You may say that I can use ExecStartPre or ExecStartPre. Yes, but it can not stop service A start.
So I want use "require" in systemd, create a new service B who config file like below:
[Unit]
Description=api
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
Before=kubelet.service
[Service]
ExecStart=/bin/bash /root/check_init.sh
Restart=no
[Install]
WantedBy=multi-user.target
/root/check_init.sh like this :
#!/bin/bash
exit 1
service A config as below:
[Unit]
Description=Kubernetes Kubelet Server
Documentation=https://github.com/GoogleCloudPlatform/kubernetes
After=docker.service
After=api.service
Requires=api.service
[Service]
WorkingDirectory=/var/lib/kubelet
EnvironmentFile=-/etc/kubernetes/config
EnvironmentFile=-/etc/kubernetes/kubelet
ExecStart=/usr/bin/kubelet
$KUBE_LOGTOSTDERR
$KUBE_LOG_LEVEL
$KUBELET_API_SERVER
$KUBELET_ADDRESS
$KUBELET_PORT
$KUBELET_HOSTNAME
$KUBE_ALLOW_PRIV
$KUBELET_POD_INFRA_CONTAINER
$KUBELET_ARGS
Restart=on-failure
[Install]
WantedBy=multi-user.target
I thought service B start failed, so service A must failed too. However, service A started.
Is there any thing wrong for my config?
Thanks!
linux systemd
linux systemd
edited Aug 26 '17 at 9:34
workhardcc
asked Aug 26 '17 at 9:17
workhardccworkhardcc
84
84
unclear why you don't wantExecStartPre
instead, is it that you don't want the main service to be marked failed, but it's ok if this auxilaryapi.service
is?
– sourcejedi
Aug 26 '17 at 10:56
1
Thanks for your answer. I try to useExecStartPre
yesterday, systemd will restart service A again and again until execExecStartPre
script success. The service A inactivating
status, it's worked for me. I also tryType=oneshot
andRemainAfterExit=yes
for service B, its useful too. Service B run one time and if its failed service A will not start successful. The different for those two ways I think is:ExecStartPre
will try to start service A again and again but theType=oneshot
andRemainAfterExit=yes
just only one time. Am I right?
– workhardcc
Aug 27 '17 at 9:21
Ah, that makes sense! I hadn't considered that you had setRestart=
, sorry.
– sourcejedi
Aug 27 '17 at 11:35
kubelet
looks like it's a daemon, in which case it should not beType=oneshot
.
– sourcejedi
Aug 27 '17 at 11:42
1
Yes,kubelet
is a daemon.Type=oneshot
forservice B
not for kubelet(service A),kubelet
needrestart=on-failure
. I think useservice B
notExecStartPre
is better for me. Because I actually want make some test before start the service
– workhardcc
Aug 27 '17 at 12:22
add a comment |
unclear why you don't wantExecStartPre
instead, is it that you don't want the main service to be marked failed, but it's ok if this auxilaryapi.service
is?
– sourcejedi
Aug 26 '17 at 10:56
1
Thanks for your answer. I try to useExecStartPre
yesterday, systemd will restart service A again and again until execExecStartPre
script success. The service A inactivating
status, it's worked for me. I also tryType=oneshot
andRemainAfterExit=yes
for service B, its useful too. Service B run one time and if its failed service A will not start successful. The different for those two ways I think is:ExecStartPre
will try to start service A again and again but theType=oneshot
andRemainAfterExit=yes
just only one time. Am I right?
– workhardcc
Aug 27 '17 at 9:21
Ah, that makes sense! I hadn't considered that you had setRestart=
, sorry.
– sourcejedi
Aug 27 '17 at 11:35
kubelet
looks like it's a daemon, in which case it should not beType=oneshot
.
– sourcejedi
Aug 27 '17 at 11:42
1
Yes,kubelet
is a daemon.Type=oneshot
forservice B
not for kubelet(service A),kubelet
needrestart=on-failure
. I think useservice B
notExecStartPre
is better for me. Because I actually want make some test before start the service
– workhardcc
Aug 27 '17 at 12:22
unclear why you don't want
ExecStartPre
instead, is it that you don't want the main service to be marked failed, but it's ok if this auxilary api.service
is?– sourcejedi
Aug 26 '17 at 10:56
unclear why you don't want
ExecStartPre
instead, is it that you don't want the main service to be marked failed, but it's ok if this auxilary api.service
is?– sourcejedi
Aug 26 '17 at 10:56
1
1
Thanks for your answer. I try to use
ExecStartPre
yesterday, systemd will restart service A again and again until exec ExecStartPre
script success. The service A in activating
status, it's worked for me. I also try Type=oneshot
and RemainAfterExit=yes
for service B, its useful too. Service B run one time and if its failed service A will not start successful. The different for those two ways I think is: ExecStartPre
will try to start service A again and again but the Type=oneshot
and RemainAfterExit=yes
just only one time. Am I right?– workhardcc
Aug 27 '17 at 9:21
Thanks for your answer. I try to use
ExecStartPre
yesterday, systemd will restart service A again and again until exec ExecStartPre
script success. The service A in activating
status, it's worked for me. I also try Type=oneshot
and RemainAfterExit=yes
for service B, its useful too. Service B run one time and if its failed service A will not start successful. The different for those two ways I think is: ExecStartPre
will try to start service A again and again but the Type=oneshot
and RemainAfterExit=yes
just only one time. Am I right?– workhardcc
Aug 27 '17 at 9:21
Ah, that makes sense! I hadn't considered that you had set
Restart=
, sorry.– sourcejedi
Aug 27 '17 at 11:35
Ah, that makes sense! I hadn't considered that you had set
Restart=
, sorry.– sourcejedi
Aug 27 '17 at 11:35
kubelet
looks like it's a daemon, in which case it should not be Type=oneshot
.– sourcejedi
Aug 27 '17 at 11:42
kubelet
looks like it's a daemon, in which case it should not be Type=oneshot
.– sourcejedi
Aug 27 '17 at 11:42
1
1
Yes,
kubelet
is a daemon. Type=oneshot
for service B
not for kubelet(service A), kubelet
need restart=on-failure
. I think use service B
not ExecStartPre
is better for me. Because I actually want make some test before start the service– workhardcc
Aug 27 '17 at 12:22
Yes,
kubelet
is a daemon. Type=oneshot
for service B
not for kubelet(service A), kubelet
need restart=on-failure
. I think use service B
not ExecStartPre
is better for me. Because I actually want make some test before start the service– workhardcc
Aug 27 '17 at 12:22
add a comment |
1 Answer
1
active
oldest
votes
You're missing Type=oneshot
in the first service - you're not actually waiting for the check to finish!
(Originally I suggested also using RemainAfterExit=yes
in the first service. But I think that was not necessary).
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%2f388449%2frequire-seems-doesnt-work-in-systemd%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You're missing Type=oneshot
in the first service - you're not actually waiting for the check to finish!
(Originally I suggested also using RemainAfterExit=yes
in the first service. But I think that was not necessary).
add a comment |
You're missing Type=oneshot
in the first service - you're not actually waiting for the check to finish!
(Originally I suggested also using RemainAfterExit=yes
in the first service. But I think that was not necessary).
add a comment |
You're missing Type=oneshot
in the first service - you're not actually waiting for the check to finish!
(Originally I suggested also using RemainAfterExit=yes
in the first service. But I think that was not necessary).
You're missing Type=oneshot
in the first service - you're not actually waiting for the check to finish!
(Originally I suggested also using RemainAfterExit=yes
in the first service. But I think that was not necessary).
edited Jan 14 at 10:27
answered Aug 27 '17 at 11:43
sourcejedisourcejedi
23.4k437103
23.4k437103
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%2f388449%2frequire-seems-doesnt-work-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
unclear why you don't want
ExecStartPre
instead, is it that you don't want the main service to be marked failed, but it's ok if this auxilaryapi.service
is?– sourcejedi
Aug 26 '17 at 10:56
1
Thanks for your answer. I try to use
ExecStartPre
yesterday, systemd will restart service A again and again until execExecStartPre
script success. The service A inactivating
status, it's worked for me. I also tryType=oneshot
andRemainAfterExit=yes
for service B, its useful too. Service B run one time and if its failed service A will not start successful. The different for those two ways I think is:ExecStartPre
will try to start service A again and again but theType=oneshot
andRemainAfterExit=yes
just only one time. Am I right?– workhardcc
Aug 27 '17 at 9:21
Ah, that makes sense! I hadn't considered that you had set
Restart=
, sorry.– sourcejedi
Aug 27 '17 at 11:35
kubelet
looks like it's a daemon, in which case it should not beType=oneshot
.– sourcejedi
Aug 27 '17 at 11:42
1
Yes,
kubelet
is a daemon.Type=oneshot
forservice B
not for kubelet(service A),kubelet
needrestart=on-failure
. I think useservice B
notExecStartPre
is better for me. Because I actually want make some test before start the service– workhardcc
Aug 27 '17 at 12:22