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

    Restarting OpenVPN with cron job

    pfSense Packages
    4
    6
    4.3k
    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.
    • B
      BeepStein
      last edited by

      Hello,

      I am using the openvpn client with a vpn service provider. The client at some point in time is failing to resolve the DNS name of the server.  It works when i restart the client and/or reboot the pfsense.  I do not know what is causing it.

      I want to set a cron job using the cron package to restart the OpenVPN client at midnight. So far I configured what is in screen shot 1. It uses the following command:

      echo "" | php -q

      But when I save it, it show up as screenshot too. When I go to edit it again it seems like the entire command is there. I am not an expert with the CLI so did I put the command in correctly? (note i have this cron job to go every 3 minutes because I just wanted to see if it worked.)

      Any help will be appreciated.

      ![Edit Page.png](/public/imported_attachments/1/Edit Page.png)
      ![Edit Page.png_thumb](/public/imported_attachments/1/Edit Page.png_thumb)
      ![Main Cron Page.png](/public/imported_attachments/1/Main Cron Page.png)
      ![Main Cron Page.png_thumb](/public/imported_attachments/1/Main Cron Page.png_thumb)

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

        Don't use PHP there. You can use the shell command to restart the instance.

        /usr/local/sbin/pfSsh.php playback svc restart openvpn client x

        Where "x" is the id of the OpenVPN instance (e.g. ovpnc2 would be id 2)

        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 0
        • B
          BeepStein
          last edited by

          Thank you!

          1 Reply Last reply Reply Quote 0
          • Z
            zayrn9efir
            last edited by

            @jimp:

            Don't use PHP there. You can use the shell command to restart the instance.

            /usr/local/sbin/pfSsh.php playback svc restart openvpn client x

            Where "x" is the id of the OpenVPN instance (e.g. ovpnc2 would be id 2)

            Is there an easy way to do this for all running clients?

            My end goal is to have active OpenVPN clients restart on a schedule without pointlessly attempting to restart disabled clients using a for loop.

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

              No, there is no built-in way to do that for all instances.

              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 0
              • B
                babobobom
                last edited by

                I tried this command
                "/usr/local/sbin/pfSsh.php playback svc restart openvpn client 1"

                and now I can't login to the web interface, not even after restart.

                any tips for me? :P

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