How to delay a systemd unit until network is ready?

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











up vote
4
down vote

favorite












I've switched from cron to systemd-cron with my Debian unstable system, but now the daily "cron-job" often fails, because it runs mixmaster which fetches it's database from the internet and if the cron-daily.timer gets triggered before the network is up, after wake-up from suspend to RAM, mixmaster can't reach the server.



Apr 24 11:02:23 run-parts[13608]: /usr/bin/mixmaster-update: Get failed for http://www.noreply.org/echolot/pgp-all.asc (500 Can't connect to www.noreply.org:80)
Apr 24 11:02:23 run-parts[13608]: Downloading of mlist and/or mixring failed (do you need a proxy?). Aborting.
Apr 24 11:02:23 su[13809]: pam_unix(su:session): session closed for user mixmaster
Apr 24 11:02:23 run-parts[13608]: run-parts: /etc/cron.daily/mixmaster exited with return code 22


Is it possible to delay the timer until the network is up and running?










share|improve this question

























    up vote
    4
    down vote

    favorite












    I've switched from cron to systemd-cron with my Debian unstable system, but now the daily "cron-job" often fails, because it runs mixmaster which fetches it's database from the internet and if the cron-daily.timer gets triggered before the network is up, after wake-up from suspend to RAM, mixmaster can't reach the server.



    Apr 24 11:02:23 run-parts[13608]: /usr/bin/mixmaster-update: Get failed for http://www.noreply.org/echolot/pgp-all.asc (500 Can't connect to www.noreply.org:80)
    Apr 24 11:02:23 run-parts[13608]: Downloading of mlist and/or mixring failed (do you need a proxy?). Aborting.
    Apr 24 11:02:23 su[13809]: pam_unix(su:session): session closed for user mixmaster
    Apr 24 11:02:23 run-parts[13608]: run-parts: /etc/cron.daily/mixmaster exited with return code 22


    Is it possible to delay the timer until the network is up and running?










    share|improve this question























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I've switched from cron to systemd-cron with my Debian unstable system, but now the daily "cron-job" often fails, because it runs mixmaster which fetches it's database from the internet and if the cron-daily.timer gets triggered before the network is up, after wake-up from suspend to RAM, mixmaster can't reach the server.



      Apr 24 11:02:23 run-parts[13608]: /usr/bin/mixmaster-update: Get failed for http://www.noreply.org/echolot/pgp-all.asc (500 Can't connect to www.noreply.org:80)
      Apr 24 11:02:23 run-parts[13608]: Downloading of mlist and/or mixring failed (do you need a proxy?). Aborting.
      Apr 24 11:02:23 su[13809]: pam_unix(su:session): session closed for user mixmaster
      Apr 24 11:02:23 run-parts[13608]: run-parts: /etc/cron.daily/mixmaster exited with return code 22


      Is it possible to delay the timer until the network is up and running?










      share|improve this question













      I've switched from cron to systemd-cron with my Debian unstable system, but now the daily "cron-job" often fails, because it runs mixmaster which fetches it's database from the internet and if the cron-daily.timer gets triggered before the network is up, after wake-up from suspend to RAM, mixmaster can't reach the server.



      Apr 24 11:02:23 run-parts[13608]: /usr/bin/mixmaster-update: Get failed for http://www.noreply.org/echolot/pgp-all.asc (500 Can't connect to www.noreply.org:80)
      Apr 24 11:02:23 run-parts[13608]: Downloading of mlist and/or mixring failed (do you need a proxy?). Aborting.
      Apr 24 11:02:23 su[13809]: pam_unix(su:session): session closed for user mixmaster
      Apr 24 11:02:23 run-parts[13608]: run-parts: /etc/cron.daily/mixmaster exited with return code 22


      Is it possible to delay the timer until the network is up and running?







      networking systemd cron






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 24 '17 at 14:17









      jo-so

      3113




      3113




















          3 Answers
          3






          active

          oldest

          votes

















          up vote
          2
          down vote













          It might be worth using systemd's timers rather than cron. You should then be able to specify in the unit what it depends on.



          https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies






          share|improve this answer




















          • The systemd-cron package in Debian are the systemd timers to replace sysv-cron. packages.debian.org/sid/systemd-cron
            – jo-so
            Apr 25 '17 at 17:32

















          up vote
          2
          down vote













          Use systemd timers instead of cron.



          Then in your systemd-unit, you can specify After=network-online.target and Wants=network-online.target.






          share|improve this answer
















          • 1




            This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
            – jo-so
            Apr 25 '17 at 17:39










          • If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60
            – Mark Stosberg
            Apr 25 '17 at 18:25

















          up vote
          0
          down vote













          In my setup the cron job is run every ten minutes, but quits if there is no internet connection, by a connectivity test such as

          nc -zw3 github.com 22 || exit 0

          When there is finally an internet connection, then, once a day, an anacron job is run.






          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%2f360984%2fhow-to-delay-a-systemd-unit-until-network-is-ready%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








            up vote
            2
            down vote













            It might be worth using systemd's timers rather than cron. You should then be able to specify in the unit what it depends on.



            https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies






            share|improve this answer




















            • The systemd-cron package in Debian are the systemd timers to replace sysv-cron. packages.debian.org/sid/systemd-cron
              – jo-so
              Apr 25 '17 at 17:32














            up vote
            2
            down vote













            It might be worth using systemd's timers rather than cron. You should then be able to specify in the unit what it depends on.



            https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies






            share|improve this answer




















            • The systemd-cron package in Debian are the systemd timers to replace sysv-cron. packages.debian.org/sid/systemd-cron
              – jo-so
              Apr 25 '17 at 17:32












            up vote
            2
            down vote










            up vote
            2
            down vote









            It might be worth using systemd's timers rather than cron. You should then be able to specify in the unit what it depends on.



            https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies






            share|improve this answer












            It might be worth using systemd's timers rather than cron. You should then be able to specify in the unit what it depends on.



            https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 24 '17 at 14:37









            Jonathan Hodgson

            9213




            9213











            • The systemd-cron package in Debian are the systemd timers to replace sysv-cron. packages.debian.org/sid/systemd-cron
              – jo-so
              Apr 25 '17 at 17:32
















            • The systemd-cron package in Debian are the systemd timers to replace sysv-cron. packages.debian.org/sid/systemd-cron
              – jo-so
              Apr 25 '17 at 17:32















            The systemd-cron package in Debian are the systemd timers to replace sysv-cron. packages.debian.org/sid/systemd-cron
            – jo-so
            Apr 25 '17 at 17:32




            The systemd-cron package in Debian are the systemd timers to replace sysv-cron. packages.debian.org/sid/systemd-cron
            – jo-so
            Apr 25 '17 at 17:32












            up vote
            2
            down vote













            Use systemd timers instead of cron.



            Then in your systemd-unit, you can specify After=network-online.target and Wants=network-online.target.






            share|improve this answer
















            • 1




              This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
              – jo-so
              Apr 25 '17 at 17:39










            • If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60
              – Mark Stosberg
              Apr 25 '17 at 18:25














            up vote
            2
            down vote













            Use systemd timers instead of cron.



            Then in your systemd-unit, you can specify After=network-online.target and Wants=network-online.target.






            share|improve this answer
















            • 1




              This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
              – jo-so
              Apr 25 '17 at 17:39










            • If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60
              – Mark Stosberg
              Apr 25 '17 at 18:25












            up vote
            2
            down vote










            up vote
            2
            down vote









            Use systemd timers instead of cron.



            Then in your systemd-unit, you can specify After=network-online.target and Wants=network-online.target.






            share|improve this answer












            Use systemd timers instead of cron.



            Then in your systemd-unit, you can specify After=network-online.target and Wants=network-online.target.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Apr 24 '17 at 18:14









            Mark Stosberg

            3,7711125




            3,7711125







            • 1




              This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
              – jo-so
              Apr 25 '17 at 17:39










            • If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60
              – Mark Stosberg
              Apr 25 '17 at 18:25












            • 1




              This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
              – jo-so
              Apr 25 '17 at 17:39










            • If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60
              – Mark Stosberg
              Apr 25 '17 at 18:25







            1




            1




            This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
            – jo-so
            Apr 25 '17 at 17:39




            This doesn't help, because the target becomes active after boot, but remains untouched when the network goes down due to suspend to RAM e.g.
            – jo-so
            Apr 25 '17 at 17:39












            If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60
            – Mark Stosberg
            Apr 25 '17 at 18:25




            If all else fails, you can add a "sleep" statement to the script you run, to have it wait for a period before attempting to connect, like ExecStartPre=/bin/sleep 60
            – Mark Stosberg
            Apr 25 '17 at 18:25










            up vote
            0
            down vote













            In my setup the cron job is run every ten minutes, but quits if there is no internet connection, by a connectivity test such as

            nc -zw3 github.com 22 || exit 0

            When there is finally an internet connection, then, once a day, an anacron job is run.






            share|improve this answer
























              up vote
              0
              down vote













              In my setup the cron job is run every ten minutes, but quits if there is no internet connection, by a connectivity test such as

              nc -zw3 github.com 22 || exit 0

              When there is finally an internet connection, then, once a day, an anacron job is run.






              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                In my setup the cron job is run every ten minutes, but quits if there is no internet connection, by a connectivity test such as

                nc -zw3 github.com 22 || exit 0

                When there is finally an internet connection, then, once a day, an anacron job is run.






                share|improve this answer












                In my setup the cron job is run every ten minutes, but quits if there is no internet connection, by a connectivity test such as

                nc -zw3 github.com 22 || exit 0

                When there is finally an internet connection, then, once a day, an anacron job is run.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 at 15:28









                Enno

                11113




                11113



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f360984%2fhow-to-delay-a-systemd-unit-until-network-is-ready%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 check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay