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

CRON restart OpenVPN using kill pid

Scheduled Pinned Locked Moved OpenVPN
7 Posts 4 Posters 2.7k 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
    pfBasic Banned
    last edited by Oct 1, 2016, 3:30 PM

    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 Oct 1, 2016, 10:32 PM

      Why Restart openvpn Every night?

      Have you tried svc restart?

      1 Reply Last reply Reply Quote 0
      • P
        pfBasic Banned
        last edited by Oct 1, 2016, 11:25 PM

        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 Oct 1, 2016, 11:51 PM Oct 1, 2016, 11:44 PM

          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 Jan 10, 2019, 5:43 PM Reply Quote 0
          • W
            wes93 @heper
            last edited by Jan 10, 2019, 5:43 PM

            @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
            • G
              Gertjan
              last edited by Jan 10, 2019, 7:04 PM

              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 Jan 10, 2019, 7:22 PM

                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.
                  This community forum collects and processes your personal information.
                  consent.not_received