summaryrefslogtreecommitdiff
path: root/network/nordvpn/rc.nordvpn
blob: c59bb600739aeacf9d824430fba204fc3b5a56b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env bash

# 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


PRGNAM=nordvpn
PID=/var/run/$PRGNAM.pid
DAEMON=/usr/sbin/${PRGNAM}d
SOCK=/run/${PRGNAM}d.sock


#
# Function that starts the daemon
#
nordvpnd_start()
{
  rm -rf $SOCK
  if [ -s $PID ]; then
    echo "$PRGNAM is already running: $(cat $PID)"
    exit 1
  fi

  if [ -x $DAEMON ]; then
    echo "Starting $PRGNAM"
    $DAEMON &
    pidof $DAEMON > $PID
  fi
}

#
# Function that stops the daemon
#
nordvpnd_stop()
{
  if [ -s $PID ]; then
    kill $(cat $PID)
    rm -rf $PID $SOCK
    echo "$PRGNAM has been stopped."
  else
    echo "$PRGNAM is not running."
  fi
}

#
# Function that restarts the daemon
#
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."
}

#
# Function that shows the current status of the daemon
#
nordvpnd_status()
{
  if [ -s $PID ]; then
    echo "$PRGNAM is running: $(cat $PID)"
  else
    echo "$PRGNAM is not running."
  fi
}


case "$1" in
  start)
    nordvpnd_start
    ;;
  stop)
    nordvpnd_stop
    ;;
  restart)
    nordvpnd_restart
    ;;
  status)
    nordvpnd_status
    ;;
  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 1
    ;;
esac