-
Notifications
You must be signed in to change notification settings - Fork 18
/
rc.vnstatd
60 lines (54 loc) · 1003 Bytes
/
rc.vnstatd
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
#!/bin/bash
VNSTATBIN="/usr/sbin/vnstatd"
CONFIGFILE="/etc/vnstat.conf"
BASEDIR="/var/lib/vnstat/"
PIDFILE="/run/vnstat/vnstat.pid"
INTERFACE=$(grep Interface $CONFIGFILE | cut -d" " -f2 | cut -d'"' -f2)
start_vnstat() {
if [ -e "$PIDFILE" ]; then
echo "Already running"
return 0
elif [ ! -e "$BASEDIR/$INTERFACE" ]; then
if ! $VNSTATBIN -u -i "$INTERFACE"; then
echo "Failed"
return 0
fi
fi
printf "Starting vnStat daemon: "
if ! $VNSTATBIN -d --config "$CONFIGFILE"; then
echo "Failed"
return 0
else
echo "Done"
fi
}
stop_vnstat() {
if [ ! -e "$PIDFILE" ]; then
echo "Not running"
return 0
else
printf "Stopping vnStat daemon: "
if ! kill "$(cat $PIDFILE)"; then
echo "Failed"
return 0
else
echo "Done"
fi
fi
}
case "$1" in
start)
start_vnstat
;;
stop)
stop_vnstat
;;
restart|reload)
stop_vnstat
sleep 2
start_vnstat
;;
*)
echo "usage: $0 {start|stop|restart|reload}"
esac
exit 0