Reply
Established Member
Posts: 789
Registered: ‎08-22-2013
Kudos: 237
Solutions: 17

Re: Better way to restart OpenVPN?

That's outstanding. I'll happily alpha-test 2.0. Thanks for the update @UBNT-sandisn

UBRSS, UEWA.


Milwaukee, WI
Highlighted
Established Member
Posts: 789
Registered: ‎08-22-2013
Kudos: 237
Solutions: 17

Re: Better way to restart OpenVPN?


@karogwrote:

In the mean time, one could use this script that seems to work.

 

vtunrestart

#!/bin/vbash

# SET FOR YOUR VTUN !! VTUN="vtun2" if [ -f "/var/run/openvpn-$VTUN.pid" ]; then sudo kill $(cat "/var/run/openvpn-$VTUN.pid") fi

# CHANGE THIS COMMAND keeping sudo !! sudo /usr/sbin/openvpn --daemon --verb 3 --writepid /var/run/openvpn-$VTUN.pid --status /var/run/openvpn/status/$VTUN.status 30 --config /config/openvpn/pia/128/US\ East.ovpn --dev-type tun --dev $VTUN

 

To find your command, do (after adjusting for vtun). The command will vary depending on how you configured the interface.

 

$ ps aux | grep -v grep | grep vtun2
root 2025 0.2 0.5 6456 2720 ? Ss 12:45 0:01 /usr/sbin/openvpn --daemon --verb 3 --writepid /var/run/openvpn-vtun2.pid --status /var/run/openvpn/status/vtun2.status 30 --config /config/openvpn/pia/128/US East.ovpn --dev-type tun --dev vtun2

 

This shows you the command line ( it starts with /usr/sbin/openvpn to the end of line ) that was used to start your openvpn instance. It is what you will need in the above script. Beware any spaces in your .ovpn filename if such is used as they will not be quoted here. Just add a \ before each space. PIA uses spaces in its .ovpn filenames which motivated me to mention it.

 


@karog - I can't seem to get this to work. It works for you?

UBRSS, UEWA.


Milwaukee, WI
Established Member
Posts: 1,534
Registered: ‎05-03-2016
Kudos: 528
Solutions: 148

Re: Better way to restart OpenVPN?

[ Edited ]

@jeremyk wrote:

 

@karog - I can't seem to get this to work. It works for you?


 Yes, I would not have posted it otherwise.

 

Did you adapt it as instructed?

 

 

Established Member
Posts: 789
Registered: ‎08-22-2013
Kudos: 237
Solutions: 17

Re: Better way to restart OpenVPN?


@karog wrote:

@jeremyk wrote:

 

@karog - I can't seem to get this to work. It works for you?


 Yes

 

Did you adapt it as instructed?

 

 


@karog - My fault, I didn't realize I was still in a failover situation at the moment I tried to run it. I did make the necessary customizations for my config. I'll test again and report back. Thanks.  

UBRSS, UEWA.


Milwaukee, WI
Established Member
Posts: 789
Registered: ‎08-22-2013
Kudos: 237
Solutions: 17

Re: Better way to restart OpenVPN?

@karog - It works. thanks, and my apologies. Everything you suggest functions wonderfully at killing the openvpn tunnel and restarting it with a fresh PID.

 

It wasn't working for me after a WAN-failover and fail-back event earlier today. I think it may be related to my use of openvpn-option --persist-tun. Going to play with that a bit. Anyway thanks. 

UBRSS, UEWA.


Milwaukee, WI
New Member
Posts: 9
Registered: ‎10-23-2017
Kudos: 1

Re: Better way to restart OpenVPN?

@karog Thanks for the script. it seems to work as it keeps my AirVPN connection flowing.

 

Just some error message seen:

openvpn[15587]: Options error: option 'dhcp-option' cannot be used in this context ([PUSH-OPTIONS])

openvpn[15587]: Options error: option 'redirect-gateway' cannot be used in this context ([PUSH-OPTIONS])

 

I further edited my AirVPN.ovpn file to comment out ovpn option "persist-tun" and add in ovpn option "keepalive 10 60". Hope this helps.

Security defense is tough, but the tough gets going
Reply