VPN Instability getting old

In 2.27 /etc/init.d/startvpn

This line was changed:

stop(){
kill -9 $(cat /var/run/ovpn_client.pid) >/dev/null 2>&1

The problem is startvpn is being called twice so there are two processes. This kill command doesn’t kill the conflicting one - only the one that wrote its pid file.

The old script prior to 2.27 ran

stop(){
killall openvpn

Which would clean up the conflicting openvpn process on vpn restart (and not fully exposing the race condition that was still present then). Dirty - but it sort of worked.

@alzhao Ideally it would be best to add some logic at the top of the startvpn start function like

start(){
if [ “$(pgrep /usr/sbin/openvpn)” ]; then
echo OpenVPN already started… Exiting.
exit 1
fi

This fixes it so I can use the switch to toggle VPN and if startvpn is called twice, the second time it will exit properly.