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

    CRON restart OpenVPN using kill pid

    OpenVPN
    4
    7
    2.6k
    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
      pfBasic Banned
      last edited by

      I'm currently restarting my openvpn client via cron every night using: /usr/local/sbin/pfSsh.php playback svc start openvpn client 1

      However, I'm running into issues where this method doesn't update the PID with the GUI so all of the GUI interfaces say that openvpn is down even though it is working. If I leave it doing these updates for awhile then I'll see multiple PIDs in /var/run for openvpn client and server.

      All of this can be fixed by going into the shell and running: ps aux | grep openvpn then running kill "PID" for the processes and it's good to go.

      So instead of dealing with all of that, I'd like to just have CRON do that every night instead of restarting the way that I'm doing it now. But I'm not sure how to do it.

      I'd like something along the lines of this, but it doesn't work (I found it on a linux thread):

      kill $(ps aux | grep openvpn | awk '{print $2}')

      /usr/local/sbin/pfSsh.php playback svc start openvpn client 1

      I'm not sure if the "/usr/local/sbin/pfSsh.php playback svc start openvpn client 1" command is necessary, will openvpn just restart itself if I kill the PID? If not is this the best way to start openvpn after I've killed it by PID or is there a better way?

      Also, the: "kill $(ps aux | grep openvpn | awk '{print $2}')" command doesn't work (probably because it's written for linux). But basically I want to Kill the PIDs that are returned from "ps aux | grep openvpn"

      Any help is greatly appreciated!

      1 Reply Last reply Reply Quote 0
      • H
        heper
        last edited by

        Why Restart openvpn Every night?

        Have you tried svc restart?

        1 Reply Last reply Reply Quote 0
        • P
          pfBasic Banned
          last edited by

          Because occasionally the VPN client goes down and needs to be restarted. If it goes down then most of network goes down because most of my network will only route through the VPN.

          Yes that's what I'm using now but that method has some known issues with the GUI that I'm trying to avoid.

          1 Reply Last reply Reply Quote 0
          • H
            heper
            last edited by

            this seems to work for me:

            
            pfSense shell: include('service-utils.inc');
            pfSense shell: service_control_restart("openvpn", array('vpnmode' => 'client', 'id' => '1'));
            pfSense shell: exec
            
            

            you can create a new macro for it & call it the same way from cron.

            you can figure out the client 'ID' by capturing the post-data when clicking the restart-button in the GUI  or from config.xml or ….

            W 1 Reply Last reply Reply Quote 0
            • W
              wes93 @heper
              last edited by

              @heper said in CRON restart OpenVPN using kill pid:

              service_control_restart("openvpn", array('vpnmode' => 'client', 'id' => '1'));

              How can i use this? i'm a noob and i want to restart openvpn if ping fail...

              Thanks a lot
              Stefano

              1 Reply Last reply Reply Quote 0
              • GertjanG
                Gertjan
                last edited by

                Some of these restart openvp client if ping fails ?

                No "help me" PM's please. Use the forum, the community will thank you.
                Edit : and where are the logs ??

                1 Reply Last reply Reply Quote 0
                • W
                  wes93
                  last edited by

                  I don’t know how to use the results from Google... :(

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