restart systemd service within a timeframe











up vote
0
down vote

favorite












I have systemd unit file, I know it can be restarted on failure by providing parameters, like :



Restart=always
RestartSec=90


It will restart after 90 seconds whenever it fails,



But, I want to restart only if system time is in between given time-frame, say between 08:00 and 17:00, only then restart.



Is there way to do this via systemd ?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I have systemd unit file, I know it can be restarted on failure by providing parameters, like :



    Restart=always
    RestartSec=90


    It will restart after 90 seconds whenever it fails,



    But, I want to restart only if system time is in between given time-frame, say between 08:00 and 17:00, only then restart.



    Is there way to do this via systemd ?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have systemd unit file, I know it can be restarted on failure by providing parameters, like :



      Restart=always
      RestartSec=90


      It will restart after 90 seconds whenever it fails,



      But, I want to restart only if system time is in between given time-frame, say between 08:00 and 17:00, only then restart.



      Is there way to do this via systemd ?










      share|improve this question













      I have systemd unit file, I know it can be restarted on failure by providing parameters, like :



      Restart=always
      RestartSec=90


      It will restart after 90 seconds whenever it fails,



      But, I want to restart only if system time is in between given time-frame, say between 08:00 and 17:00, only then restart.



      Is there way to do this via systemd ?







      systemd systemd-timer






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 6 hours ago









      mkmayank

      41610




      41610






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Directly in a service unit file with settings: no.



          With a Heath Robinson mechanism: yes, as follows.




          • Create two snippet files somewhere, wibble-in-hours.conf with these settings turned on and wibble-out-of-hours.conf with these settings turned off. Don't forget the section heading.

          • At any given point, /etc/systemd/system/wibble.service.d/restart.conf is one or the other of these files. The systemd manual (q.v.) explains drop-in directories and snippet files.

          • Set up uschedule jobs, cron jobs, or whatever other mechanism you like, to swap the snippet files around at the appropriate times, invoke systemctl daemon-reload, and of course bring the service up if it has terminated during the out of hours period. (Be aware of masking, disabled services, and the fact that some operating systems stop services temporarily during package upgrades, all of which make the test of whether to start the service non-trivial.)






          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%2f481640%2frestart-systemd-service-within-a-timeframe%23new-answer', 'question_page');
            }
            );

            Post as a guest
































            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            Directly in a service unit file with settings: no.



            With a Heath Robinson mechanism: yes, as follows.




            • Create two snippet files somewhere, wibble-in-hours.conf with these settings turned on and wibble-out-of-hours.conf with these settings turned off. Don't forget the section heading.

            • At any given point, /etc/systemd/system/wibble.service.d/restart.conf is one or the other of these files. The systemd manual (q.v.) explains drop-in directories and snippet files.

            • Set up uschedule jobs, cron jobs, or whatever other mechanism you like, to swap the snippet files around at the appropriate times, invoke systemctl daemon-reload, and of course bring the service up if it has terminated during the out of hours period. (Be aware of masking, disabled services, and the fact that some operating systems stop services temporarily during package upgrades, all of which make the test of whether to start the service non-trivial.)






            share|improve this answer

























              up vote
              0
              down vote













              Directly in a service unit file with settings: no.



              With a Heath Robinson mechanism: yes, as follows.




              • Create two snippet files somewhere, wibble-in-hours.conf with these settings turned on and wibble-out-of-hours.conf with these settings turned off. Don't forget the section heading.

              • At any given point, /etc/systemd/system/wibble.service.d/restart.conf is one or the other of these files. The systemd manual (q.v.) explains drop-in directories and snippet files.

              • Set up uschedule jobs, cron jobs, or whatever other mechanism you like, to swap the snippet files around at the appropriate times, invoke systemctl daemon-reload, and of course bring the service up if it has terminated during the out of hours period. (Be aware of masking, disabled services, and the fact that some operating systems stop services temporarily during package upgrades, all of which make the test of whether to start the service non-trivial.)






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Directly in a service unit file with settings: no.



                With a Heath Robinson mechanism: yes, as follows.




                • Create two snippet files somewhere, wibble-in-hours.conf with these settings turned on and wibble-out-of-hours.conf with these settings turned off. Don't forget the section heading.

                • At any given point, /etc/systemd/system/wibble.service.d/restart.conf is one or the other of these files. The systemd manual (q.v.) explains drop-in directories and snippet files.

                • Set up uschedule jobs, cron jobs, or whatever other mechanism you like, to swap the snippet files around at the appropriate times, invoke systemctl daemon-reload, and of course bring the service up if it has terminated during the out of hours period. (Be aware of masking, disabled services, and the fact that some operating systems stop services temporarily during package upgrades, all of which make the test of whether to start the service non-trivial.)






                share|improve this answer












                Directly in a service unit file with settings: no.



                With a Heath Robinson mechanism: yes, as follows.




                • Create two snippet files somewhere, wibble-in-hours.conf with these settings turned on and wibble-out-of-hours.conf with these settings turned off. Don't forget the section heading.

                • At any given point, /etc/systemd/system/wibble.service.d/restart.conf is one or the other of these files. The systemd manual (q.v.) explains drop-in directories and snippet files.

                • Set up uschedule jobs, cron jobs, or whatever other mechanism you like, to swap the snippet files around at the appropriate times, invoke systemctl daemon-reload, and of course bring the service up if it has terminated during the out of hours period. (Be aware of masking, disabled services, and the fact that some operating systems stop services temporarily during package upgrades, all of which make the test of whether to start the service non-trivial.)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                JdeBP

                31.4k466145




                31.4k466145






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481640%2frestart-systemd-service-within-a-timeframe%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    Morgemoulin

                    Scott Moir

                    Souastre