“Require” seems doesn't work in systemd












1















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!










share|improve this question

























  • 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





    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











  • kubelet looks like it's a daemon, in which case it should not be Type=oneshot.

    – sourcejedi
    Aug 27 '17 at 11:42






  • 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
















1















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!










share|improve this question

























  • 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





    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











  • kubelet looks like it's a daemon, in which case it should not be Type=oneshot.

    – sourcejedi
    Aug 27 '17 at 11:42






  • 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














1












1








1








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!










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 26 '17 at 9:34







workhardcc

















asked Aug 26 '17 at 9:17









workhardccworkhardcc

84




84













  • 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





    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











  • kubelet looks like it's a daemon, in which case it should not be Type=oneshot.

    – sourcejedi
    Aug 27 '17 at 11:42






  • 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



















  • 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





    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











  • kubelet looks like it's a daemon, in which case it should not be Type=oneshot.

    – sourcejedi
    Aug 27 '17 at 11:42






  • 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

















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










1 Answer
1






active

oldest

votes


















0














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






share|improve this answer

























    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%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









    0














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






    share|improve this answer






























      0














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






      share|improve this answer




























        0












        0








        0







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






        share|improve this answer















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







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 14 at 10:27

























        answered Aug 27 '17 at 11:43









        sourcejedisourcejedi

        23.4k437103




        23.4k437103






























            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.




            draft saved


            draft discarded














            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





















































            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 make a Squid Proxy server?

            Is this a new Fibonacci Identity?

            Touch on Surface Book