Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    How do I restart a service a minute or 2 after reboot?

    Scheduled Pinned Locked Moved General pfSense Questions
    10 Posts 4 Posters 497 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      py
      last edited by

      Long ago I used it to restart unbound 1 minute after each reboot:

      -n pfSsh.php playback svc restart unbound | at now + 1minute

      That problem was fixed but now I need to restart an openvpn client 1 minute after reboot and it's not working. Testing from the CLI it appears "at" doesn't have any effect.

      I understand it's best to address the root of the issue rather than restarting a service after boot, but this will fix it until i can spend more time on it.

      Thanks,

      stephenw10S 1 Reply Last reply Reply Quote 0
      • JonathanLeeJ
        JonathanLee
        last edited by JonathanLee

        You can do a @reboot in cron however I do not know what time they run during reboot

        Make sure to upvote

        1 Reply Last reply Reply Quote 0
        • stephenw10S
          stephenw10 Netgate Administrator @py
          last edited by

          @py said in How do I restart a service a minute or 2 after reboot?:

          Testing from the CLI it appears "at" doesn't have any effect.

          Like it runs immediately or not at all?

          That command is probably just piping to result of the restart to at. You probably want something more like:
          echo 'pfSsh.php playback svc restart unbound' | at now + 5 minutes

          P 1 Reply Last reply Reply Quote 0
          • P
            py @stephenw10
            last edited by py

            @stephenw10
            I'm trying to get this working in the CLI before I bother with Cron.
            From the CLI, the following result in immediate restart of the correct openvpn client:

            pfSsh.php playback svc restart openvpn client 3
            pfSsh.php playback svc restart openvpn client 3 | at now + 1minute
            pfSsh.php playback svc restart openvpn client 3 | at now + 1 minute

            This is why I wondered if "at" is even part of the OS.

            The following had no result, except for the Shell Output "Job ?? will be executed using /bin/sh:"

            echo 'pfSsh.php playback svc restart openvpn client 3' | at now + 1minute
            echo 'pfSsh.php playback svc restart openvpn client 3'

            Specifying the full paths also results in no restart:

            /usr/local/sbin/pfSsh.php playback svc restart /usr/local/sbin/openvpn client 3 | at now + 1minute

            Another thing i noticed is that when the openvpn service is restarted from the CLI, the restart appears in the OpenVPN log but not always in the Status page, (Status > OpenVPN). I haven't tracked that enough yet to see which specific command keeps it from appearing on the Status page.

            S 1 Reply Last reply Reply Quote 0
            • stephenw10S
              stephenw10 Netgate Administrator
              last edited by

              What pfSense version are you doing this in?

              Since atrun only runs at 5min intervals now+1m might not get run. Hence I tested at +5m.

              However it still fail here logging:

              Jan 6 14:40:00 	atrun 	17651 	cannot chdir to /var/at/spool: No such file or directory
              

              Do you also see that?

              1 Reply Last reply Reply Quote 0
              • S
                SteveITS Galactic Empire @py
                last edited by

                @py said in How do I restart a service a minute or 2 after reboot?:

                result in immediate restart

                Well I'd read what you wrote as you're piping the result of pfSsh.php to at. Did you try the "echo" as above? Is the "-n" from "echo -n" maybe?

                Maybe, "sleep 60 && pfSsh.php playback svc restart openvpn client 3" ?

                Pre-2.7.2/23.09: Only install packages for your version, or risk breaking it. Select your branch in System/Update/Update Settings.
                When upgrading, allow 10-15 minutes to restart, or more depending on packages and device speed.
                Upvote ๐Ÿ‘ helpful posts!

                1 Reply Last reply Reply Quote 0
                • stephenw10S
                  stephenw10 Netgate Administrator
                  last edited by

                  Yup using sleep is probably easier. Though if you run that as a shellcmd it may just sleep the boot process entirely!

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    SteveITS Galactic Empire @stephenw10
                    last edited by

                    "sleep 60 && pfSsh.php playback svc restart openvpn client 3 &" to spawn it?

                    run a .sh script with sleep, via @reboot in cron (which has a pfSense package, for lurkers)?

                    Pre-2.7.2/23.09: Only install packages for your version, or risk breaking it. Select your branch in System/Update/Update Settings.
                    When upgrading, allow 10-15 minutes to restart, or more depending on packages and device speed.
                    Upvote ๐Ÿ‘ helpful posts!

                    P 2 Replies Last reply Reply Quote 1
                    • P
                      py @SteveITS
                      last edited by

                      @SteveITS @stephenw10
                      This is pfSense + 24.11.

                      I haven't tried "atrun" but I was aware of the 5 minute granularity. However, years ago "at now + 1minute" worked after 1 minute, or close enough I didn't notice. This is acting so different that I still wonder if "at" is even part of the OS anymore, and based on your result, maybe "atrun" is also gone?

                      I know where the FreeBSD manual is and I've been using that, but I could use a command reference that shows the specifics on how to use "at" or "sleep" in this context. I'm using the pipe symbol, but I found that on another forum somewhere long ago and could use a reference on how to use all these together instead of hunting and pecking to see if it works. And I realize there may still be some hunt and peck but at least it might be reduced.

                      Thanks,

                      1 Reply Last reply Reply Quote 0
                      • P
                        py @SteveITS
                        last edited by py

                        @SteveITS
                        "sleep 60...." did it, thanks!
                        Tested with a reboot and it did not sleep the reboot process either.

                        Status > OpenVPN also shows the time (re)started correctly.

                        Much appreciated and thanks to everyone for their help!

                        1 Reply Last reply Reply Quote 2
                        • First post
                          Last post
                        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.