Adding delay between stop and start of a process in systemd












7















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?










share|improve this question























  • 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
















7















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?










share|improve this question























  • 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














7












7








7








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Feb 9 '16 at 12:15









Let_Me_BeLet_Me_Be

4,44483257




4,44483257













  • 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



















  • 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

















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










2 Answers
2






active

oldest

votes


















9














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.






share|improve this answer
























  • 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





















0














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.






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









    9














    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.






    share|improve this answer
























    • 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


















    9














    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.






    share|improve this answer
























    • 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
















    9












    9








    9







    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.






    share|improve this answer













    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.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jul 11 '16 at 6:06









    mmohammadmmohammad

    19112




    19112













    • 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



















    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















    0














    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.






    share|improve this answer




























      0














      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.






      share|improve this answer


























        0












        0








        0







        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.






        share|improve this answer













        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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 19 at 0:45









        Dread QuixadhalDread Quixadhal

        1




        1






























            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%2f260973%2fadding-delay-between-stop-and-start-of-a-process-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?

            19世紀