blob: bc1eb255a46c8980bc07b5484652bcf5eeacc3f2 (
about) (
plain) (
blame)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
#!/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
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
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 "$BASE is already running: $(cat $PID)"
exit 1
fi
if [ -x $DAEMON ]; then
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
}
#
# Function that stops the daemon
#
nordvpnd_stop()
{
if [ -s $PID ]; then
echo "Stopping $BASE"
sleep 1
kill $(cat $PID)
rm -rf $PID $SOCK
sleep 1
echo "$BASE has been stopped."
else
echo "$BASE is not running."
fi
}
#
# Function that restarts the daemon
#
nordvpnd_restart()
{
nordvpnd_stop
sleep 1
nordvpnd_start
}
#
# Function that shows the current status of the daemon
#
nordvpnd_status()
{
if [ -s $PID ]; then
echo "$BASE is running: $(cat $PID)"
else
echo "$BASE 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
|