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

    [SOLVED] Restart OpenVPN via Cron Every Night

    Scheduled Pinned Locked Moved OpenVPN
    7 Posts 4 Posters 8.8k 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.
    • A
      archedraft
      last edited by

      Hello, I have 2 OpenVPN servers setup and 2 OpenVPN clients setup. I would like cron to restart ovpnc2 cleint interface every night but I only would like that this interface to restart. Is there a command only target that one openvpn client?

      I found this command listed but I would guess that it restarts all the open servers and cleints?

      #!/usr/local/bin/php -q

      1 Reply Last reply Reply Quote 0
      • jimpJ
        jimp Rebel Alliance Developer Netgate
        last edited by

        Here's the easiest way:

        First find the server you need to restart:

        : ps uxawww | grep openvpn
        root    25984 0.0  0.9 13496  4340  ??  Ss  Thu06PM  0:09.08 /usr/local/sbin/openvpn –config /var/etc/openvpn/server1.conf
        root    32393  0.0  0.9 13496  4492  ??  Ss  Thu06PM  0:01.75 /usr/local/sbin/openvpn –config /var/etc/openvpn/server2.conf

        Then run this script to restart just that one

        : /usr/local/sbin/pfSsh.php playback svc restart openvpn server 1

        Starting the pfSense shell system…............

        Attempting to issue restart to openvpn service...

        openvpn has been restarted.

        Note that only server 1 restarted:

        : ps uxawww | grep openvpn
        root    32393  0.0  0.9 13496  4492  ??  Ss  Thu06PM  0:01.75 /usr/local/sbin/openvpn –config /var/etc/openvpn/server2.conf
        root    32933  0.0  0.9 13496  4624  ??  Ss    4:18PM  0:00.00 /usr/local/sbin/openvpn –config /var/etc/openvpn/server1.conf

        Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

        Need help fast? Netgate Global Support!

        Do not Chat/PM for help!

        1 Reply Last reply Reply Quote 2
        • A
          archedraft
          last edited by

          Perfect! Thanks jimp!

          1 Reply Last reply Reply Quote 0
          • J
            Jim Coogan
            last edited by

            While this was a great solution for my open VPN problem it made Avahi restart on pfsense even though it wasn't bound to openvpn interfaces and this caused homekit on ios / mac to often show accessories (in a different vlan and relying on avahi) as inaccessible for 20 + seconds after a restart upon first trying to use home app.

            B 1 Reply Last reply Reply Quote 0
            • B
              Bambos @Jim Coogan
              last edited by

              @jim-coogan today i had OpenVPN service stopped after ISP restart (disconnection on WAN), and stay stopped for 12 hours. I had to go on-site to press start service again.

              Is there any way to cron restart services from pfsense ?

              J 1 Reply Last reply Reply Quote 1
              • J
                Jim Coogan @Bambos
                last edited by

                @bambos yeah there is a cron package you can add in the package manager and then like this 2nd post here describes you can set it up to restart on whatever schedule you want.

                B 1 Reply Last reply Reply Quote 0
                • B
                  Bambos @Jim Coogan
                  last edited by

                  @jim-coogan thank you my friend. seems watchdog is easier package for that purpose, allows to monitor active services by selection and monitors, restarts, and notify without commands. Looks like a good start. Thank you for your comments.

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