Last active
May 24, 2019 15:32
-
-
Save karlwilbur/e6c7719a3a35d75892aa87921c96f1aa to your computer and use it in GitHub Desktop.
Start/stop OpenVPN while tracking PID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PID_FILE=~/run/openvpn.pid | |
if [ -e $PID_FILE ] && [ -s $PID_FILE ]; then | |
pid=`cat $PID_FILE`; | |
if [ ! "$(ps -eF | grep $pid | grep openvpn)" ]; then | |
echo "It seems that OpenVPN is not running and was not shutdown cleanly, remove the file '$PID_FILE' before attepting to start." | |
exit 1; | |
fi | |
echo "Stopping OpenVPN with PID: $pid"; | |
sudo kill $pid && rm $PID_FILE; | |
else | |
echo "OpenVPN is not running." | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
PID_FILE=~/run/openvpn.pid | |
if [ -e $PID_FILE ] && [ -s $PID_FILE ]; then | |
if [ "$(ps -eF | grep `cat $PID_FILE` | grep openvpn)" ]; then | |
echo "It seems that OpenVPN is already running with PID $(cat $PID_FILE)"; | |
exit 1; | |
else | |
echo "It seems that OpenVPN was not shutdown cleanly, remove the file '$PID_FILE' and try to start again." | |
exit 1; | |
fi | |
fi | |
sudo openvpn --daemon --config ~/.config/openvpn/karlwilbur.ovpn | |
pid=`pidof openvpn` | |
echo $pid > $PID_FILE | |
echo "OpenVPN started with PID $pid" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment