Restart OpenVPN client from shell / cron

So I’ve come across a few threads that are pretty old discussing ways of doing this.
I’d like to be able to have a simple command to restart a VPN client as though I’d be clicking on the the restart button in the OpenVPN Status page.

I’ve tried the following:

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

Which doesn’t seem to do anything.
I’ve tried the script taken from this site and managed to get it working with some modifications. But this pipes a php script via ssh which is way more complex than I’d like it to be.

Essentially I want to run a cron job to regularly restart my VPN client in order to be issued a new IP address from my provider. Or maybe there’s a Custom option in the VPN Advanced configuration that could do this?

Anyone have any ideas?

I agree with OP, this - well referenced - PHP function just doesn’t work on 2.5.2, and no amount of googling seems to produce any answer - nor even much of an acknowledgement from the user base.

The GUI restart icon works every time, but you can’t do that automatically when there’s a failure, can you?

I can vouch for it working on 2.4.x (not sure which sub-version)

But it no longer works, which I have to say is a massive dissapointment that it’s now broken. It’s almost enough impetus for me to downgrade back to a version which worked, as OpenVPN reliability with Privado is really quite poor. Not every day, but regularly enough that all users now know the symptoms - that’s not a good sign. (“Users” in this case are my family!)

I have changed to using the watchdog, but I’m not optimistic, as the OVPN service isn’t stopped, it still thinks it’s fine, it just gets a lot of packet loss, and then stops forwarding.

Maybe it’s time to change VPN provider?!

#!/bin/bash SERVERIP=192.168.1.10 ping -c 3 $SERVERIP > /dev/null 2>&1 if [ $? -ne 0 ] then # restart the service service openvpn restart fi

This what I use.

This one has a detailed process.
PHP script for openvpn

I would rather suggest to use watchdog package to monitor restart your services with different conditions.

Since this is the top result of my google search I thought I would leave a comment with my working solution on PFSense 2.5.

I found this post here which clearly tells you what command to use to restart the client or server: Netagate Forum Post

I installed the “Cron” package so I could modify the Cron file from the GUI.

I ran the psgrep command in the post to see which clients were running. All of them only have numbers not names, so to find the number I went to Status → OpenVPN in the GUI and I hovered my mouse over the reset button for the service. I right clicked (in chrome) and went to “inspect” and found out the number of the server that I wanted to restart by examining the HTML code. Then I put that number into the command line example and I tested it by going to Diagnostics → Command Prompt and pasting the command there.

After I confirmed that the command worked, I went to the Cron section in the GUI and pasted in the command and had it run as root. For me I’m rebooting every night. The reason is that I have a weird issue with my VPN and Netflix not working and I need to get a new IP address.

I hope this helps someone else in my situation. It wasn’t very helpful to see a lot of answers to this questions just telling the user that they should never need to restart the VPN outside of Watchdog which wasn’t very helpful.

So I see two processes running as openvpn when looking at top. But the service itself doesn’t seem to be running.

service openvpn onestatus
openvpn is not running.

service openvpn onerestart
openvpn not running? (check /var/run/openvpn.pid).
/usr/local/etc/rc.d/openvpn: WARNING: /usr/local/etc/openvpn/openvpn.conf is not readable.
/usr/local/etc/rc.d/openvpn: WARNING: failed precmd routine for openvpn

What version of pfsense are you running? I’m on 2.5.2 and openvpn was configured via the webgui and is running properly.

I’ll have a look at watchdog. Thanks