MattSurabian / proxpn-bash-client

A minimal command-line based ProXPN OpenVPN client that is compatible with Linux and OS X.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature request: run as service with auto-reconnect.

kenthinson opened this issue · comments

Have ability to run as a service. If the connection drops it will automatically reconnect.

I don't have any problem providing an upstart/system d script for this. Would you expect the installer to prompt and ask if you want to install the service and then ask which "flavor" of service to install?

yeah some kind of prompt to configure the default settings like tcp/udp and what server you want would be nice. Maybe a conf file somewhere to edit it if you ever need to change the settings... This would be awesome for my use case.

Yeah changing the settings after the fact is the trickier part since the non-interactive mode is currently all flag based. The service script would need the output of a "dry-run" to be contained within it...

Maybe there's something like a --service -s flag that will output the file to stdout if run without elevated privilege and put the file in place if run with sudo. It could optionally take a name which would default to proxpn so multiple services could be created if needed?

Bleh, automating this could prove tricky for UX... maybe it would be better to provide service template files in the repo and document how to use them and folks could directly paste the dry run commands into them?

I have to admit i'm not sure I've never made a service before :/

What i've ended up doing so far is I made a crontab
if ps -ef | grep -v grep | grep openvpn ; then
exit 0
else
/usr/local/bin/proxpn -p udp -r SanJose
fi

The problem with my crontab that i've run into so far is that loosing connection does not always terminate openvpn. So every other day or so I have to go manually "killall openvpn" to get the connection working again.

yeah the crontab option will kind of work but really you probably want to use upstart or systemd with a respawn directive.

I was under the impression that the resolv-retry option https://github.com/MattSurabian/proxpn-bash-client/blob/master/proxpn.ovpn#L9-L10 would terminate the script on connection drop if it wasn't able to reconnect after 30 seconds. If that's not happening we might need a self termination thing setup on -down. Once the script has terminated the service controller (upstart/systemd) should trigger respawn immediately.

Development here is delayed because I wanted to come up with an automated test harness that would close the network connection and confirm functionality but haven't had the time.

Hey just realized I never got back to you on this. This is how I ended up solving it. Crontab run every 5 mins.

if ping google.com -c 1 ; then
exit 0
else
killall openvpn
/usr/local/bin/proxpn -p udp -r NYC
fi

I've setup firewall rules so that the machine can only get internet traffic if the connection it up. Otherwise the ping fails.

I thought I would leave this here incase it helps others.