-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathS33vnstat
53 lines (44 loc) · 1.43 KB
/
S33vnstat
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
#!/bin/sh
# shellcheck disable=SC1091
# shellcheck disable=SC2034
# shellcheck disable=SC2086
if [ -f /opt/etc/init.d/S32vnstat ]; then
/opt/etc/init.d/S32vnstat stop
rm -f /opt/etc/init.d/S32vnstat
fi
if [ -f /opt/etc/init.d/S32vnstat2 ]; then
/opt/etc/init.d/S32vnstat2 stop
rm -f /opt/etc/init.d/S32vnstat2
fi
if [ -f "/opt/share/dn-vnstat.d/config" ]; then
SCRIPT_STORAGE_DIR="/opt/share/dn-vnstat.d"
else
SCRIPT_STORAGE_DIR="/jffs/addons/dn-vnstat.d"
fi
TZ=$(cat /etc/TZ)
export TZ
ENABLED=yes
PROCS=vnstatd
ARGS="-d --noadd --config $SCRIPT_STORAGE_DIR/vnstat.conf"
PREARGS=""
DESC="$PROCS"
PATH=/opt/sbin:/opt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
if [ "$1" = "start" ] || [ "$1" = "restart" ]; then
if [ -f "$SCRIPT_STORAGE_DIR/vnstat.conf" ]; then
IFACE="$(grep "Interface " "$SCRIPT_STORAGE_DIR/vnstat.conf" | awk '{print $2}' | sed 's/"//g')"
logger -st vnstat "Starting monitoring for interface $IFACE"
else
logger -st vnstat "Configuration file missing - $SCRIPT_STORAGE_DIR/vnstat.conf - please check"
exit 1
fi
if [ "$(nvram get ntp_ready)" -eq 0 ]; then
logger -st vnstat "NTP not synced, exiting"
exit 1
fi
if ! vnstat --config "$SCRIPT_STORAGE_DIR/vnstat.conf" -i "$IFACE" >/dev/null 2>&1; then
vnstatd $ARGS >/dev/null 2>&1
vnstat --config "$SCRIPT_STORAGE_DIR/vnstat.conf" --add -i "$IFACE" >/dev/null 2>&1
killall vnstatd >/dev/null 2>&1
fi
fi
. /opt/etc/init.d/rc.func