How does systemd interpret the return codes of scripts it launches in ExecStartPre and ExecStartPost?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Systemd, when processing a .service file, is able to execute scripts in the ExecStartPre and ExecStartPost clauses. These scripts can return values to systemd.



In the documentation for systemd, it indicates that a return value of anything but 0 is considered a failure, and unless that clause was prefixed with '-' indicates that this attempt to launch the service will be aborted.



An aborted launch attempt is no big deal, because systemd will simply reattempt to launch the service, unless the service is marked as simple (I think).



In a script that I've inherited, the author indicates that a return value of 111 informs systemd that not only should the launch be aborted, but that no further launches are to be attempted. Elsewhere the script conditionally returns 10, or 11, in addition to the more typical 0. These return conditions seem integral to the functioning of the script.



I have been unable to find anything describing the interpretation of these return codes by systemd.










share|improve this question



























    up vote
    0
    down vote

    favorite












    Systemd, when processing a .service file, is able to execute scripts in the ExecStartPre and ExecStartPost clauses. These scripts can return values to systemd.



    In the documentation for systemd, it indicates that a return value of anything but 0 is considered a failure, and unless that clause was prefixed with '-' indicates that this attempt to launch the service will be aborted.



    An aborted launch attempt is no big deal, because systemd will simply reattempt to launch the service, unless the service is marked as simple (I think).



    In a script that I've inherited, the author indicates that a return value of 111 informs systemd that not only should the launch be aborted, but that no further launches are to be attempted. Elsewhere the script conditionally returns 10, or 11, in addition to the more typical 0. These return conditions seem integral to the functioning of the script.



    I have been unable to find anything describing the interpretation of these return codes by systemd.










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Systemd, when processing a .service file, is able to execute scripts in the ExecStartPre and ExecStartPost clauses. These scripts can return values to systemd.



      In the documentation for systemd, it indicates that a return value of anything but 0 is considered a failure, and unless that clause was prefixed with '-' indicates that this attempt to launch the service will be aborted.



      An aborted launch attempt is no big deal, because systemd will simply reattempt to launch the service, unless the service is marked as simple (I think).



      In a script that I've inherited, the author indicates that a return value of 111 informs systemd that not only should the launch be aborted, but that no further launches are to be attempted. Elsewhere the script conditionally returns 10, or 11, in addition to the more typical 0. These return conditions seem integral to the functioning of the script.



      I have been unable to find anything describing the interpretation of these return codes by systemd.










      share|improve this question















      Systemd, when processing a .service file, is able to execute scripts in the ExecStartPre and ExecStartPost clauses. These scripts can return values to systemd.



      In the documentation for systemd, it indicates that a return value of anything but 0 is considered a failure, and unless that clause was prefixed with '-' indicates that this attempt to launch the service will be aborted.



      An aborted launch attempt is no big deal, because systemd will simply reattempt to launch the service, unless the service is marked as simple (I think).



      In a script that I've inherited, the author indicates that a return value of 111 informs systemd that not only should the launch be aborted, but that no further launches are to be attempted. Elsewhere the script conditionally returns 10, or 11, in addition to the more typical 0. These return conditions seem integral to the functioning of the script.



      I have been unable to find anything describing the interpretation of these return codes by systemd.







      systemd






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 7 at 23:43









      Rui F Ribeiro

      38.7k1479128




      38.7k1479128










      asked Dec 9 '16 at 16:16









      David Lawson

      32




      32




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          You have options for the main ExecStart command. I do not know, but suspect that the -Post and -Pre do not use those.



          Accepting 10 and 11 as valid: SuccessExitStatus=



          Viewing 111 as a total deal breaker: RestartPreventExitStatus=



          Otherwise, you can always write a quick wrapper shell script to palliate to the lack of support in systemd.



          I would do something like this:



          #!/bin/sh

          if [ -f /run/my-script-is-dead ]
          then
          # to avoid very fast loop, sleep for a bit
          sleep 10
          exit 1
          fi

          # Run the script itself
          /path/and/usual-command

          # check result
          RESULT=$?

          if [ $RESULT -eq 10 ] || [ RESULT -eq 11 ]
          then
          exit 0
          fi

          if [ $RESULT -eq 111 ]
          then
          touch /run/my-script-is-dead
          exit 1
          fi

          exit $RESULT


          But putting a file under /run, it will automatically disappear on each reboot. If you want something more permanent, then you'll have to create a file somewhere else (i.e. /var/cache/...)






          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',
            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%2f329242%2fhow-does-systemd-interpret-the-return-codes-of-scripts-it-launches-in-execstartp%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








            up vote
            0
            down vote



            accepted










            You have options for the main ExecStart command. I do not know, but suspect that the -Post and -Pre do not use those.



            Accepting 10 and 11 as valid: SuccessExitStatus=



            Viewing 111 as a total deal breaker: RestartPreventExitStatus=



            Otherwise, you can always write a quick wrapper shell script to palliate to the lack of support in systemd.



            I would do something like this:



            #!/bin/sh

            if [ -f /run/my-script-is-dead ]
            then
            # to avoid very fast loop, sleep for a bit
            sleep 10
            exit 1
            fi

            # Run the script itself
            /path/and/usual-command

            # check result
            RESULT=$?

            if [ $RESULT -eq 10 ] || [ RESULT -eq 11 ]
            then
            exit 0
            fi

            if [ $RESULT -eq 111 ]
            then
            touch /run/my-script-is-dead
            exit 1
            fi

            exit $RESULT


            But putting a file under /run, it will automatically disappear on each reboot. If you want something more permanent, then you'll have to create a file somewhere else (i.e. /var/cache/...)






            share|improve this answer
























              up vote
              0
              down vote



              accepted










              You have options for the main ExecStart command. I do not know, but suspect that the -Post and -Pre do not use those.



              Accepting 10 and 11 as valid: SuccessExitStatus=



              Viewing 111 as a total deal breaker: RestartPreventExitStatus=



              Otherwise, you can always write a quick wrapper shell script to palliate to the lack of support in systemd.



              I would do something like this:



              #!/bin/sh

              if [ -f /run/my-script-is-dead ]
              then
              # to avoid very fast loop, sleep for a bit
              sleep 10
              exit 1
              fi

              # Run the script itself
              /path/and/usual-command

              # check result
              RESULT=$?

              if [ $RESULT -eq 10 ] || [ RESULT -eq 11 ]
              then
              exit 0
              fi

              if [ $RESULT -eq 111 ]
              then
              touch /run/my-script-is-dead
              exit 1
              fi

              exit $RESULT


              But putting a file under /run, it will automatically disappear on each reboot. If you want something more permanent, then you'll have to create a file somewhere else (i.e. /var/cache/...)






              share|improve this answer






















                up vote
                0
                down vote



                accepted







                up vote
                0
                down vote



                accepted






                You have options for the main ExecStart command. I do not know, but suspect that the -Post and -Pre do not use those.



                Accepting 10 and 11 as valid: SuccessExitStatus=



                Viewing 111 as a total deal breaker: RestartPreventExitStatus=



                Otherwise, you can always write a quick wrapper shell script to palliate to the lack of support in systemd.



                I would do something like this:



                #!/bin/sh

                if [ -f /run/my-script-is-dead ]
                then
                # to avoid very fast loop, sleep for a bit
                sleep 10
                exit 1
                fi

                # Run the script itself
                /path/and/usual-command

                # check result
                RESULT=$?

                if [ $RESULT -eq 10 ] || [ RESULT -eq 11 ]
                then
                exit 0
                fi

                if [ $RESULT -eq 111 ]
                then
                touch /run/my-script-is-dead
                exit 1
                fi

                exit $RESULT


                But putting a file under /run, it will automatically disappear on each reboot. If you want something more permanent, then you'll have to create a file somewhere else (i.e. /var/cache/...)






                share|improve this answer












                You have options for the main ExecStart command. I do not know, but suspect that the -Post and -Pre do not use those.



                Accepting 10 and 11 as valid: SuccessExitStatus=



                Viewing 111 as a total deal breaker: RestartPreventExitStatus=



                Otherwise, you can always write a quick wrapper shell script to palliate to the lack of support in systemd.



                I would do something like this:



                #!/bin/sh

                if [ -f /run/my-script-is-dead ]
                then
                # to avoid very fast loop, sleep for a bit
                sleep 10
                exit 1
                fi

                # Run the script itself
                /path/and/usual-command

                # check result
                RESULT=$?

                if [ $RESULT -eq 10 ] || [ RESULT -eq 11 ]
                then
                exit 0
                fi

                if [ $RESULT -eq 111 ]
                then
                touch /run/my-script-is-dead
                exit 1
                fi

                exit $RESULT


                But putting a file under /run, it will automatically disappear on each reboot. If you want something more permanent, then you'll have to create a file somewhere else (i.e. /var/cache/...)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 13 '16 at 6:30









                Alexis Wilke

                939615




                939615



























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f329242%2fhow-does-systemd-interpret-the-return-codes-of-scripts-it-launches-in-execstartp%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

                    Peggy Mitchell

                    The Forum (Inglewood, California)

                    Palaiologos