diff options
Diffstat (limited to 'network/nordvpn/rc.nordvpn')
-rw-r--r-- | network/nordvpn/rc.nordvpn | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/network/nordvpn/rc.nordvpn b/network/nordvpn/rc.nordvpn index c59bb60073..bc1eb255a4 100644 --- a/network/nordvpn/rc.nordvpn +++ b/network/nordvpn/rc.nordvpn @@ -3,28 +3,58 @@ # Short-Description: Protect your privacy online and access media content with no regional restrictions. Strong encryption and no-log policy with 3000+ servers in 60+ countries. ### END INIT INFO +PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin -PRGNAM=nordvpn -PID=/var/run/$PRGNAM.pid -DAEMON=/usr/sbin/${PRGNAM}d -SOCK=/run/${PRGNAM}d.sock +BASE=nordvpn +DAEMON=/usr/sbin/${BASE}d +PID=/var/run/$BASE.pid +SOCK=/run/$BASE/${BASE}d.sock +SOCKDIR=/run/$BASE +create_socket_dir() { + if [[ -d $SOCKDIR ]]; then + return + fi + mkdir -m 0770 $SOCKDIR + chown root:$BASE $SOCKDIR +} + +checkuser() { + status=0 + for u in $(who | awk '{print $1}' | sort | uniq) + do + if [ "$u" == "$1" ]; then + return 0 + fi + done + return 1 +} # # Function that starts the daemon # nordvpnd_start() { + checkuser + create_socket_dir rm -rf $SOCK if [ -s $PID ]; then - echo "$PRGNAM is already running: $(cat $PID)" + echo "$BASE is already running: $(cat $PID)" exit 1 fi if [ -x $DAEMON ]; then - echo "Starting $PRGNAM" - $DAEMON & + echo "Starting $BASE" + sleep 1 + # $DAEMON start-stop-daemon --start --quiet -g "nordvpn" --pidfile $PID --exec $DAEMON + $DAEMON > /dev/null & pidof $DAEMON > $PID + sleep 10 + if [ -S "$SOCK" ]; then + echo "$BASE has been started." + else + echo "$BASE failed to start. Please restart the daemon." + fi fi } @@ -34,11 +64,14 @@ nordvpnd_start() nordvpnd_stop() { if [ -s $PID ]; then + echo "Stopping $BASE" + sleep 1 kill $(cat $PID) rm -rf $PID $SOCK - echo "$PRGNAM has been stopped." + sleep 1 + echo "$BASE has been stopped." else - echo "$PRGNAM is not running." + echo "$BASE is not running." fi } @@ -47,15 +80,9 @@ nordvpnd_stop() # nordvpnd_restart() { - echo "Stopping $PRGNAM" - sleep 1 nordvpnd_stop - echo "$PRGNAM has been stopped." - sleep 1 - echo "Restarting $PRGNAM" sleep 1 nordvpnd_start - echo "$PRGNAM has been restarted." } # @@ -64,9 +91,9 @@ nordvpnd_restart() nordvpnd_status() { if [ -s $PID ]; then - echo "$PRGNAM is running: $(cat $PID)" + echo "$BASE is running: $(cat $PID)" else - echo "$PRGNAM is not running." + echo "$BASE is not running." fi } |