systemctl + what is the meaning of Restart=alwaysLimit system reboot bursthow to start a systemd service before networking starts?Systemd Restart=always is not honoredHow do I launch the daytime service?Delay a respawn of a serviceConfusing systemd behaviour with OnFailure= and Restart=SystemD `Requires` fail when required unit fails for the first timeSystemd service isn't restarted, no explanation of failureShould systemctl stop honour Restart=always?how to update the log message about failure of service

How was Earth single-handedly capable of creating 3 of the 4 gods of chaos?

The plural of 'stomach"

Modify casing of marked letters

Ways to speed up user implemented RK4

voltage of sounds of mp3files

What would happen if the UK refused to take part in EU Parliamentary elections?

Is exact Kanji stroke length important?

apt-get update is failing in debian

Why Were Madagascar and New Zealand Discovered So Late?

Is there any reason not to eat food that's been dropped on the surface of the moon?

Go Pregnant or Go Home

Time travel short story where a man arrives in the late 19th century in a time machine and then sends the machine back into the past

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Coordinate position not precise

What is the oldest known work of fiction?

Why "be dealt cards" rather than "be dealing cards"?

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

Was Spock the First Vulcan in Starfleet?

What's the purpose of "true" in bash "if sudo true; then"

Is expanding the research of a group into machine learning as a PhD student risky?

Bash method for viewing beginning and end of file

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

Have I saved too much for retirement so far?



systemctl + what is the meaning of Restart=always


Limit system reboot bursthow to start a systemd service before networking starts?Systemd Restart=always is not honoredHow do I launch the daytime service?Delay a respawn of a serviceConfusing systemd behaviour with OnFailure= and Restart=SystemD `Requires` fail when required unit fails for the first timeSystemd service isn't restarted, no explanation of failureShould systemctl stop honour Restart=always?how to update the log message about failure of service













-1















I configured the service - calc_mem.service



as the following



Restart=on-failure
RestartSec=5
StartLimitInterval=400
StartLimitBurst=3


the configuration above should do the following from my understanding



the service have 3 retries when service exit with error



and before service start it will wait 5 seconds



also I found that "Restart" can be also:



Restart=always


I can understand that need to restart the service on failure
but what is the meaning of Restart=always ?



in which case we need to set - Restart=always










share|improve this question




























    -1















    I configured the service - calc_mem.service



    as the following



    Restart=on-failure
    RestartSec=5
    StartLimitInterval=400
    StartLimitBurst=3


    the configuration above should do the following from my understanding



    the service have 3 retries when service exit with error



    and before service start it will wait 5 seconds



    also I found that "Restart" can be also:



    Restart=always


    I can understand that need to restart the service on failure
    but what is the meaning of Restart=always ?



    in which case we need to set - Restart=always










    share|improve this question


























      -1












      -1








      -1


      0






      I configured the service - calc_mem.service



      as the following



      Restart=on-failure
      RestartSec=5
      StartLimitInterval=400
      StartLimitBurst=3


      the configuration above should do the following from my understanding



      the service have 3 retries when service exit with error



      and before service start it will wait 5 seconds



      also I found that "Restart" can be also:



      Restart=always


      I can understand that need to restart the service on failure
      but what is the meaning of Restart=always ?



      in which case we need to set - Restart=always










      share|improve this question
















      I configured the service - calc_mem.service



      as the following



      Restart=on-failure
      RestartSec=5
      StartLimitInterval=400
      StartLimitBurst=3


      the configuration above should do the following from my understanding



      the service have 3 retries when service exit with error



      and before service start it will wait 5 seconds



      also I found that "Restart" can be also:



      Restart=always


      I can understand that need to restart the service on failure
      but what is the meaning of Restart=always ?



      in which case we need to set - Restart=always







      systemd configuration services






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 9:45









      Jeff Schaller

      43.9k1161141




      43.9k1161141










      asked Mar 22 at 8:42









      yaelyael

      2,76432776




      2,76432776




















          3 Answers
          3






          active

          oldest

          votes


















          2














          The systemd.service man page has a description of the values Restart= takes, and a table of what options cause a restart when. Always pretty much does what it says on the lid:




          If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




          I don't know for sure what situation they had in mind for that feature, but we might hypothesise e.g. a service configured to only run for a fixed period of time or to serve fixed number of requests and to then stop to avoid any possible resource leaks. Having systemd do the restarting makes for a cleaner implementation of the service itself.



          In some sense, we might also ask why not include that option in systemd. Since it is capable of restarting services on failure, they might as well include the option of restarting the service always, just in case someone needs it. To provide tools, not policy.



          Note also that a "successful exit" here is defined rather broadly:




          If set to on-success, it will be restarted only when the service process exits cleanly. In this context, a clean exit means an exit code of 0, or one of the signals SIGHUP, SIGINT, SIGTERM or SIGPIPE, [...]




          SIGHUP is a common way of asking a process to restart, but it unhandled, it
          terminates the process. So having Restart=always (or Restart=on-success) allows to use SIGHUP for restarting, even without the service itself supporting that.



          Also, as far as I can read the man page, always doesn't mean it would override the limits set by StartLimitInterval and StartLimitBurst:




          Note that service restart is subject to unit start rate limiting configured with StartLimitIntervalSec= and StartLimitBurst=, see systemd.unit(5) for details. A restarted service enters the failed state only after the start limits are reached.







          share|improve this answer






























            1















            If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered. [...] If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




            Excerpt from https://www.freedesktop.org/software/systemd/man/systemd.service.html



            So if you set on-failure, it won't get restarted on clean exit.






            share|improve this answer























            • ok now its clearly , about my configuration , do you see some issue with my configuration ? or this is exactly what should be in order to restart 3 try on fail

              – yael
              Mar 22 at 9:03


















            0














            @JdeBP suggested there is another way to look at this question.



            Restart=always is simpler. Easier to implement, easier to understand. Why would we ever want check whether the service terminated with exit code 0 (EXIT_SUCCESS) ? There might even have been a weird bug / error in the service, that caused it to terminate with exit code 0 when it should not have done so.



            Answer 1: There are some units that must not use Restart=always. In particular, if the service exits after an idle timeout.



            Intriguingly, it would not matter so much if a bug/error causes such a service to exit "successfully", when it should not have done so. Because an idle timeout implies that the service has already been set up to start automatically when a new request is made.



            However Restart=on-failure might be used for a service which can exit on idle in some configurations, but not in others. systemd-networkd uses it for this reason.



            Answer 2: System administration practices may include killing or messaging service processes to stop them. Sometimes people use a plain kill command, but there are also scripts like apachectl. The advantage of Restart=on-failure is that it is less risky for systemd to recommend using it (as the man page does).



            However systemd is left in a strange position, where they also support Restart=always, and that is what they like to set for the majority of long-running services inside the systemd project... This does not seem very helpful when you are trying to learn about systemd service definitions.






            share|improve this answer




















            • 1





              This is somewhat backwards. Unconditional restart is actually the behaviour of long standing, from quite a number of existing service managers over the decades. It's adding all of the conditional restarts, based upon process exit code and status, that is the extra complexity that came later. I speak as one of the people who has implemented such things, several times over. And indeed this was the history of systemd development, too.

              – JdeBP
              Mar 22 at 11:50











            • @JdeBP edited. It is not so obvious when you are coming across this afterwards, and just see a list of possible options. Thanks for your perspective :-).

              – sourcejedi
              Mar 22 at 12:16











            • @JdeBP my guess that this was about various bus-activated units which terminate after inactivity does not seem to be right though. systemd-timedated.service does not bother with Restart=on-failure... and I guess there is no reason that it should. Hmm, plenty of other services seem to use it though, including systemd-networkd. So I wonder what they have in common.

              – sourcejedi
              Mar 22 at 12:24












            • too-conservative thinking

              – JdeBP
              yesterday












            • @JdeBP made me smile :-). networkd turns out to be a more complex compromise, I can understand that. But then leaving Restart=always in all the other systemd daemons seems so confusing to me. It's like there's a subtle advantage that systemd strongly cares about, and simultaneously doesn't think is important enough to document.

              – sourcejedi
              yesterday











            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%2f507911%2fsystemctl-what-is-the-meaning-of-restart-always%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            The systemd.service man page has a description of the values Restart= takes, and a table of what options cause a restart when. Always pretty much does what it says on the lid:




            If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




            I don't know for sure what situation they had in mind for that feature, but we might hypothesise e.g. a service configured to only run for a fixed period of time or to serve fixed number of requests and to then stop to avoid any possible resource leaks. Having systemd do the restarting makes for a cleaner implementation of the service itself.



            In some sense, we might also ask why not include that option in systemd. Since it is capable of restarting services on failure, they might as well include the option of restarting the service always, just in case someone needs it. To provide tools, not policy.



            Note also that a "successful exit" here is defined rather broadly:




            If set to on-success, it will be restarted only when the service process exits cleanly. In this context, a clean exit means an exit code of 0, or one of the signals SIGHUP, SIGINT, SIGTERM or SIGPIPE, [...]




            SIGHUP is a common way of asking a process to restart, but it unhandled, it
            terminates the process. So having Restart=always (or Restart=on-success) allows to use SIGHUP for restarting, even without the service itself supporting that.



            Also, as far as I can read the man page, always doesn't mean it would override the limits set by StartLimitInterval and StartLimitBurst:




            Note that service restart is subject to unit start rate limiting configured with StartLimitIntervalSec= and StartLimitBurst=, see systemd.unit(5) for details. A restarted service enters the failed state only after the start limits are reached.







            share|improve this answer



























              2














              The systemd.service man page has a description of the values Restart= takes, and a table of what options cause a restart when. Always pretty much does what it says on the lid:




              If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




              I don't know for sure what situation they had in mind for that feature, but we might hypothesise e.g. a service configured to only run for a fixed period of time or to serve fixed number of requests and to then stop to avoid any possible resource leaks. Having systemd do the restarting makes for a cleaner implementation of the service itself.



              In some sense, we might also ask why not include that option in systemd. Since it is capable of restarting services on failure, they might as well include the option of restarting the service always, just in case someone needs it. To provide tools, not policy.



              Note also that a "successful exit" here is defined rather broadly:




              If set to on-success, it will be restarted only when the service process exits cleanly. In this context, a clean exit means an exit code of 0, or one of the signals SIGHUP, SIGINT, SIGTERM or SIGPIPE, [...]




              SIGHUP is a common way of asking a process to restart, but it unhandled, it
              terminates the process. So having Restart=always (or Restart=on-success) allows to use SIGHUP for restarting, even without the service itself supporting that.



              Also, as far as I can read the man page, always doesn't mean it would override the limits set by StartLimitInterval and StartLimitBurst:




              Note that service restart is subject to unit start rate limiting configured with StartLimitIntervalSec= and StartLimitBurst=, see systemd.unit(5) for details. A restarted service enters the failed state only after the start limits are reached.







              share|improve this answer

























                2












                2








                2







                The systemd.service man page has a description of the values Restart= takes, and a table of what options cause a restart when. Always pretty much does what it says on the lid:




                If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




                I don't know for sure what situation they had in mind for that feature, but we might hypothesise e.g. a service configured to only run for a fixed period of time or to serve fixed number of requests and to then stop to avoid any possible resource leaks. Having systemd do the restarting makes for a cleaner implementation of the service itself.



                In some sense, we might also ask why not include that option in systemd. Since it is capable of restarting services on failure, they might as well include the option of restarting the service always, just in case someone needs it. To provide tools, not policy.



                Note also that a "successful exit" here is defined rather broadly:




                If set to on-success, it will be restarted only when the service process exits cleanly. In this context, a clean exit means an exit code of 0, or one of the signals SIGHUP, SIGINT, SIGTERM or SIGPIPE, [...]




                SIGHUP is a common way of asking a process to restart, but it unhandled, it
                terminates the process. So having Restart=always (or Restart=on-success) allows to use SIGHUP for restarting, even without the service itself supporting that.



                Also, as far as I can read the man page, always doesn't mean it would override the limits set by StartLimitInterval and StartLimitBurst:




                Note that service restart is subject to unit start rate limiting configured with StartLimitIntervalSec= and StartLimitBurst=, see systemd.unit(5) for details. A restarted service enters the failed state only after the start limits are reached.







                share|improve this answer













                The systemd.service man page has a description of the values Restart= takes, and a table of what options cause a restart when. Always pretty much does what it says on the lid:




                If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




                I don't know for sure what situation they had in mind for that feature, but we might hypothesise e.g. a service configured to only run for a fixed period of time or to serve fixed number of requests and to then stop to avoid any possible resource leaks. Having systemd do the restarting makes for a cleaner implementation of the service itself.



                In some sense, we might also ask why not include that option in systemd. Since it is capable of restarting services on failure, they might as well include the option of restarting the service always, just in case someone needs it. To provide tools, not policy.



                Note also that a "successful exit" here is defined rather broadly:




                If set to on-success, it will be restarted only when the service process exits cleanly. In this context, a clean exit means an exit code of 0, or one of the signals SIGHUP, SIGINT, SIGTERM or SIGPIPE, [...]




                SIGHUP is a common way of asking a process to restart, but it unhandled, it
                terminates the process. So having Restart=always (or Restart=on-success) allows to use SIGHUP for restarting, even without the service itself supporting that.



                Also, as far as I can read the man page, always doesn't mean it would override the limits set by StartLimitInterval and StartLimitBurst:




                Note that service restart is subject to unit start rate limiting configured with StartLimitIntervalSec= and StartLimitBurst=, see systemd.unit(5) for details. A restarted service enters the failed state only after the start limits are reached.








                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 22 at 9:06









                ilkkachuilkkachu

                62.7k10103180




                62.7k10103180























                    1















                    If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered. [...] If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




                    Excerpt from https://www.freedesktop.org/software/systemd/man/systemd.service.html



                    So if you set on-failure, it won't get restarted on clean exit.






                    share|improve this answer























                    • ok now its clearly , about my configuration , do you see some issue with my configuration ? or this is exactly what should be in order to restart 3 try on fail

                      – yael
                      Mar 22 at 9:03















                    1















                    If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered. [...] If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




                    Excerpt from https://www.freedesktop.org/software/systemd/man/systemd.service.html



                    So if you set on-failure, it won't get restarted on clean exit.






                    share|improve this answer























                    • ok now its clearly , about my configuration , do you see some issue with my configuration ? or this is exactly what should be in order to restart 3 try on fail

                      – yael
                      Mar 22 at 9:03













                    1












                    1








                    1








                    If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered. [...] If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




                    Excerpt from https://www.freedesktop.org/software/systemd/man/systemd.service.html



                    So if you set on-failure, it won't get restarted on clean exit.






                    share|improve this answer














                    If set to on-failure, the service will be restarted when the process exits with a non-zero exit code, is terminated by a signal (including on core dump, but excluding the aforementioned four signals), when an operation (such as service reload) times out, and when the configured watchdog timeout is triggered. [...] If set to always, the service will be restarted regardless of whether it exited cleanly or not, got terminated abnormally by a signal, or hit a timeout.




                    Excerpt from https://www.freedesktop.org/software/systemd/man/systemd.service.html



                    So if you set on-failure, it won't get restarted on clean exit.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 22 at 8:55









                    PankiPanki

                    838412




                    838412












                    • ok now its clearly , about my configuration , do you see some issue with my configuration ? or this is exactly what should be in order to restart 3 try on fail

                      – yael
                      Mar 22 at 9:03

















                    • ok now its clearly , about my configuration , do you see some issue with my configuration ? or this is exactly what should be in order to restart 3 try on fail

                      – yael
                      Mar 22 at 9:03
















                    ok now its clearly , about my configuration , do you see some issue with my configuration ? or this is exactly what should be in order to restart 3 try on fail

                    – yael
                    Mar 22 at 9:03





                    ok now its clearly , about my configuration , do you see some issue with my configuration ? or this is exactly what should be in order to restart 3 try on fail

                    – yael
                    Mar 22 at 9:03











                    0














                    @JdeBP suggested there is another way to look at this question.



                    Restart=always is simpler. Easier to implement, easier to understand. Why would we ever want check whether the service terminated with exit code 0 (EXIT_SUCCESS) ? There might even have been a weird bug / error in the service, that caused it to terminate with exit code 0 when it should not have done so.



                    Answer 1: There are some units that must not use Restart=always. In particular, if the service exits after an idle timeout.



                    Intriguingly, it would not matter so much if a bug/error causes such a service to exit "successfully", when it should not have done so. Because an idle timeout implies that the service has already been set up to start automatically when a new request is made.



                    However Restart=on-failure might be used for a service which can exit on idle in some configurations, but not in others. systemd-networkd uses it for this reason.



                    Answer 2: System administration practices may include killing or messaging service processes to stop them. Sometimes people use a plain kill command, but there are also scripts like apachectl. The advantage of Restart=on-failure is that it is less risky for systemd to recommend using it (as the man page does).



                    However systemd is left in a strange position, where they also support Restart=always, and that is what they like to set for the majority of long-running services inside the systemd project... This does not seem very helpful when you are trying to learn about systemd service definitions.






                    share|improve this answer




















                    • 1





                      This is somewhat backwards. Unconditional restart is actually the behaviour of long standing, from quite a number of existing service managers over the decades. It's adding all of the conditional restarts, based upon process exit code and status, that is the extra complexity that came later. I speak as one of the people who has implemented such things, several times over. And indeed this was the history of systemd development, too.

                      – JdeBP
                      Mar 22 at 11:50











                    • @JdeBP edited. It is not so obvious when you are coming across this afterwards, and just see a list of possible options. Thanks for your perspective :-).

                      – sourcejedi
                      Mar 22 at 12:16











                    • @JdeBP my guess that this was about various bus-activated units which terminate after inactivity does not seem to be right though. systemd-timedated.service does not bother with Restart=on-failure... and I guess there is no reason that it should. Hmm, plenty of other services seem to use it though, including systemd-networkd. So I wonder what they have in common.

                      – sourcejedi
                      Mar 22 at 12:24












                    • too-conservative thinking

                      – JdeBP
                      yesterday












                    • @JdeBP made me smile :-). networkd turns out to be a more complex compromise, I can understand that. But then leaving Restart=always in all the other systemd daemons seems so confusing to me. It's like there's a subtle advantage that systemd strongly cares about, and simultaneously doesn't think is important enough to document.

                      – sourcejedi
                      yesterday
















                    0














                    @JdeBP suggested there is another way to look at this question.



                    Restart=always is simpler. Easier to implement, easier to understand. Why would we ever want check whether the service terminated with exit code 0 (EXIT_SUCCESS) ? There might even have been a weird bug / error in the service, that caused it to terminate with exit code 0 when it should not have done so.



                    Answer 1: There are some units that must not use Restart=always. In particular, if the service exits after an idle timeout.



                    Intriguingly, it would not matter so much if a bug/error causes such a service to exit "successfully", when it should not have done so. Because an idle timeout implies that the service has already been set up to start automatically when a new request is made.



                    However Restart=on-failure might be used for a service which can exit on idle in some configurations, but not in others. systemd-networkd uses it for this reason.



                    Answer 2: System administration practices may include killing or messaging service processes to stop them. Sometimes people use a plain kill command, but there are also scripts like apachectl. The advantage of Restart=on-failure is that it is less risky for systemd to recommend using it (as the man page does).



                    However systemd is left in a strange position, where they also support Restart=always, and that is what they like to set for the majority of long-running services inside the systemd project... This does not seem very helpful when you are trying to learn about systemd service definitions.






                    share|improve this answer




















                    • 1





                      This is somewhat backwards. Unconditional restart is actually the behaviour of long standing, from quite a number of existing service managers over the decades. It's adding all of the conditional restarts, based upon process exit code and status, that is the extra complexity that came later. I speak as one of the people who has implemented such things, several times over. And indeed this was the history of systemd development, too.

                      – JdeBP
                      Mar 22 at 11:50











                    • @JdeBP edited. It is not so obvious when you are coming across this afterwards, and just see a list of possible options. Thanks for your perspective :-).

                      – sourcejedi
                      Mar 22 at 12:16











                    • @JdeBP my guess that this was about various bus-activated units which terminate after inactivity does not seem to be right though. systemd-timedated.service does not bother with Restart=on-failure... and I guess there is no reason that it should. Hmm, plenty of other services seem to use it though, including systemd-networkd. So I wonder what they have in common.

                      – sourcejedi
                      Mar 22 at 12:24












                    • too-conservative thinking

                      – JdeBP
                      yesterday












                    • @JdeBP made me smile :-). networkd turns out to be a more complex compromise, I can understand that. But then leaving Restart=always in all the other systemd daemons seems so confusing to me. It's like there's a subtle advantage that systemd strongly cares about, and simultaneously doesn't think is important enough to document.

                      – sourcejedi
                      yesterday














                    0












                    0








                    0







                    @JdeBP suggested there is another way to look at this question.



                    Restart=always is simpler. Easier to implement, easier to understand. Why would we ever want check whether the service terminated with exit code 0 (EXIT_SUCCESS) ? There might even have been a weird bug / error in the service, that caused it to terminate with exit code 0 when it should not have done so.



                    Answer 1: There are some units that must not use Restart=always. In particular, if the service exits after an idle timeout.



                    Intriguingly, it would not matter so much if a bug/error causes such a service to exit "successfully", when it should not have done so. Because an idle timeout implies that the service has already been set up to start automatically when a new request is made.



                    However Restart=on-failure might be used for a service which can exit on idle in some configurations, but not in others. systemd-networkd uses it for this reason.



                    Answer 2: System administration practices may include killing or messaging service processes to stop them. Sometimes people use a plain kill command, but there are also scripts like apachectl. The advantage of Restart=on-failure is that it is less risky for systemd to recommend using it (as the man page does).



                    However systemd is left in a strange position, where they also support Restart=always, and that is what they like to set for the majority of long-running services inside the systemd project... This does not seem very helpful when you are trying to learn about systemd service definitions.






                    share|improve this answer















                    @JdeBP suggested there is another way to look at this question.



                    Restart=always is simpler. Easier to implement, easier to understand. Why would we ever want check whether the service terminated with exit code 0 (EXIT_SUCCESS) ? There might even have been a weird bug / error in the service, that caused it to terminate with exit code 0 when it should not have done so.



                    Answer 1: There are some units that must not use Restart=always. In particular, if the service exits after an idle timeout.



                    Intriguingly, it would not matter so much if a bug/error causes such a service to exit "successfully", when it should not have done so. Because an idle timeout implies that the service has already been set up to start automatically when a new request is made.



                    However Restart=on-failure might be used for a service which can exit on idle in some configurations, but not in others. systemd-networkd uses it for this reason.



                    Answer 2: System administration practices may include killing or messaging service processes to stop them. Sometimes people use a plain kill command, but there are also scripts like apachectl. The advantage of Restart=on-failure is that it is less risky for systemd to recommend using it (as the man page does).



                    However systemd is left in a strange position, where they also support Restart=always, and that is what they like to set for the majority of long-running services inside the systemd project... This does not seem very helpful when you are trying to learn about systemd service definitions.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited yesterday

























                    answered Mar 22 at 10:28









                    sourcejedisourcejedi

                    25.5k445110




                    25.5k445110







                    • 1





                      This is somewhat backwards. Unconditional restart is actually the behaviour of long standing, from quite a number of existing service managers over the decades. It's adding all of the conditional restarts, based upon process exit code and status, that is the extra complexity that came later. I speak as one of the people who has implemented such things, several times over. And indeed this was the history of systemd development, too.

                      – JdeBP
                      Mar 22 at 11:50











                    • @JdeBP edited. It is not so obvious when you are coming across this afterwards, and just see a list of possible options. Thanks for your perspective :-).

                      – sourcejedi
                      Mar 22 at 12:16











                    • @JdeBP my guess that this was about various bus-activated units which terminate after inactivity does not seem to be right though. systemd-timedated.service does not bother with Restart=on-failure... and I guess there is no reason that it should. Hmm, plenty of other services seem to use it though, including systemd-networkd. So I wonder what they have in common.

                      – sourcejedi
                      Mar 22 at 12:24












                    • too-conservative thinking

                      – JdeBP
                      yesterday












                    • @JdeBP made me smile :-). networkd turns out to be a more complex compromise, I can understand that. But then leaving Restart=always in all the other systemd daemons seems so confusing to me. It's like there's a subtle advantage that systemd strongly cares about, and simultaneously doesn't think is important enough to document.

                      – sourcejedi
                      yesterday













                    • 1





                      This is somewhat backwards. Unconditional restart is actually the behaviour of long standing, from quite a number of existing service managers over the decades. It's adding all of the conditional restarts, based upon process exit code and status, that is the extra complexity that came later. I speak as one of the people who has implemented such things, several times over. And indeed this was the history of systemd development, too.

                      – JdeBP
                      Mar 22 at 11:50











                    • @JdeBP edited. It is not so obvious when you are coming across this afterwards, and just see a list of possible options. Thanks for your perspective :-).

                      – sourcejedi
                      Mar 22 at 12:16











                    • @JdeBP my guess that this was about various bus-activated units which terminate after inactivity does not seem to be right though. systemd-timedated.service does not bother with Restart=on-failure... and I guess there is no reason that it should. Hmm, plenty of other services seem to use it though, including systemd-networkd. So I wonder what they have in common.

                      – sourcejedi
                      Mar 22 at 12:24












                    • too-conservative thinking

                      – JdeBP
                      yesterday












                    • @JdeBP made me smile :-). networkd turns out to be a more complex compromise, I can understand that. But then leaving Restart=always in all the other systemd daemons seems so confusing to me. It's like there's a subtle advantage that systemd strongly cares about, and simultaneously doesn't think is important enough to document.

                      – sourcejedi
                      yesterday








                    1




                    1





                    This is somewhat backwards. Unconditional restart is actually the behaviour of long standing, from quite a number of existing service managers over the decades. It's adding all of the conditional restarts, based upon process exit code and status, that is the extra complexity that came later. I speak as one of the people who has implemented such things, several times over. And indeed this was the history of systemd development, too.

                    – JdeBP
                    Mar 22 at 11:50





                    This is somewhat backwards. Unconditional restart is actually the behaviour of long standing, from quite a number of existing service managers over the decades. It's adding all of the conditional restarts, based upon process exit code and status, that is the extra complexity that came later. I speak as one of the people who has implemented such things, several times over. And indeed this was the history of systemd development, too.

                    – JdeBP
                    Mar 22 at 11:50













                    @JdeBP edited. It is not so obvious when you are coming across this afterwards, and just see a list of possible options. Thanks for your perspective :-).

                    – sourcejedi
                    Mar 22 at 12:16





                    @JdeBP edited. It is not so obvious when you are coming across this afterwards, and just see a list of possible options. Thanks for your perspective :-).

                    – sourcejedi
                    Mar 22 at 12:16













                    @JdeBP my guess that this was about various bus-activated units which terminate after inactivity does not seem to be right though. systemd-timedated.service does not bother with Restart=on-failure... and I guess there is no reason that it should. Hmm, plenty of other services seem to use it though, including systemd-networkd. So I wonder what they have in common.

                    – sourcejedi
                    Mar 22 at 12:24






                    @JdeBP my guess that this was about various bus-activated units which terminate after inactivity does not seem to be right though. systemd-timedated.service does not bother with Restart=on-failure... and I guess there is no reason that it should. Hmm, plenty of other services seem to use it though, including systemd-networkd. So I wonder what they have in common.

                    – sourcejedi
                    Mar 22 at 12:24














                    too-conservative thinking

                    – JdeBP
                    yesterday






                    too-conservative thinking

                    – JdeBP
                    yesterday














                    @JdeBP made me smile :-). networkd turns out to be a more complex compromise, I can understand that. But then leaving Restart=always in all the other systemd daemons seems so confusing to me. It's like there's a subtle advantage that systemd strongly cares about, and simultaneously doesn't think is important enough to document.

                    – sourcejedi
                    yesterday






                    @JdeBP made me smile :-). networkd turns out to be a more complex compromise, I can understand that. But then leaving Restart=always in all the other systemd daemons seems so confusing to me. It's like there's a subtle advantage that systemd strongly cares about, and simultaneously doesn't think is important enough to document.

                    – sourcejedi
                    yesterday


















                    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%2f507911%2fsystemctl-what-is-the-meaning-of-restart-always%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







                    -configuration, services, systemd

                    Popular posts from this blog

                    Frič See also Navigation menuinternal link

                    Identify plant with long narrow paired leaves and reddish stems Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?What is this plant with long sharp leaves? Is it a weed?What is this 3ft high, stalky plant, with mid sized narrow leaves?What is this young shrub with opposite ovate, crenate leaves and reddish stems?What is this plant with large broad serrated leaves?Identify this upright branching weed with long leaves and reddish stemsPlease help me identify this bulbous plant with long, broad leaves and white flowersWhat is this small annual with narrow gray/green leaves and rust colored daisy-type flowers?What is this chilli plant?Does anyone know what type of chilli plant this is?Help identify this plant

                    fontconfig warning: “/etc/fonts/fonts.conf”, line 100: unknown “element blank” The 2019 Stack Overflow Developer Survey Results Are In“tar: unrecognized option --warning” during 'apt-get install'How to fix Fontconfig errorHow do I figure out which font file is chosen for a system generic font alias?Why are some apt-get-installed fonts being ignored by fc-list, xfontsel, etc?Reload settings in /etc/fonts/conf.dTaking 30 seconds longer to boot after upgrade from jessie to stretchHow to match multiple font names with a single <match> element?Adding a custom font to fontconfigRemoving fonts from fontconfig <match> resultsBroken fonts after upgrading Firefox ESR to latest Firefox