blob: acbdd104ee1ef89850c59aad0a2c15bfa9aa422d (
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
92
93
94
95
96
97
98
99
|
#!/bin/sh
INTERFACE=$1
STATUS=$2
# $INIT should be either "init" (System V) or "systemd".
INIT=`cat /proc/1/comm`
no_valid_init() {
echo 'No valid init system set. Please select either "init" or "systemd".'
exit 1
}
pdnsd_is_running() {
# Check whether pDNSd is running.
case "$INIT" in
'systemd')
systemctl is-active pdnsd.service -q
return [ ! $? = 0 ]
;;
'init')
return [ `rc.d list|grep pdnsd|cut -f1 -d']'|cut -d'[' -f2` == 'STARTED' ]
;;
*)
no_valid_init
;;
esac
}
pdnsd_going_up() {
if [ ! pdnsd_is_running ]; then
# pDNSd isn't running. Start it.
case "$INIT" in
'systemd')
systemctl start pdnsd.service
;;
'init')
rc.d start pdnsd
;;
esac
else
# pDNSd is running. Restart it.
case "$INIT" in
'systemd')
systemctl restart pdnsd.service
;;
'init')
rc.d restart pdnsd
;;
esac
fi
}
pdnsd_going_down() {
# Check for active interface, take offline if none is active
if [ ! `nm-tool|grep State|cut -f2 -d' '` = 'connected' ]; then
case "$INIT" in
'systemd')
systemctl stop pdnsd.service
;;
'init')
rc.d stop pdnsd
;;
*)
no_valid_init
;;
esac
else
# If another interface is active, restart so we're sure we're using
# the active connection.
case "$INIT" in
'systemd')
systemctl restart pdnsd.service
;;
'init')
rc.d restart pdnsd
;;
*)
no_valid_init
;;
esac
fi
}
case "$STATUS" in
up)
pdnsd_going_up
;;
vpn-up)
pdnsd_going_up
;;
down)
pdnsd_going_down
;;
vpn-down)
pdnsd_going_down
;;
esac
|