blob: 802e60b066b92f1832d2f8d12576751eb0112f3d (
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
|
#!/bin/sh /etc/rc.common
# Copyright (C) 2008-2011 OpenWrt.org
START=99
vnstat_option() {
sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
/etc/vnstat.conf
}
start() {
local lib="$(vnstat_option DatabaseDir)"
local pid="$(vnstat_option PidFile)"
[ -n "$lib" ] || {
echo "Error: No DatabaseDir set in vnstat.conf" >&2
exit 1
}
[ -n "$pid" ] || {
echo "Error: No PidFile set in vnstat.conf" >&2
exit 1
}
mkdir -p "$lib"
init_ifaces() {
local cfg="$1"
local url lnk
init_iface() {
local ifn="$1"
[ -n "$url" ] && {
local try=0
local max=3
local hostname="$(cat /proc/sys/kernel/hostname)"
while [ $((++try)) -le $max ]; do
if wget -q -O "$lib/$ifn" "$url/${hostname}_$ifn" 2>/dev/null && [ -e "$lib/$ifn" ]; then
logger -t "vnstat" "Downloaded backup for database $ifn"
break
else
logger -t "vnstat" "Download try $try/$max for database $ifn failed"
sleep 30
fi
done
}
/usr/bin/vnstat -u -i "$ifn" >/dev/null
[ -n "$lnk" ] && {
mkdir -p "$lnk"
[ -L "$lnk/$ifn" ] || ln -s "$lib/$ifn" "$lnk/$ifn"
}
}
config_get url "$cfg" remote
config_get lnk "$cfg" symlink
config_list_foreach "$cfg" interface init_iface
return 1
}
config_load vnstat
config_foreach init_ifaces vnstat
SERVICE_PID_FILE="${pid}"
service_start /usr/sbin/vnstatd -d
}
stop() {
local pid="$(vnstat_option PidFile)"
[ -n "$pid" ] || {
echo "Error: No PidFile set in vnstat.conf" >&2
exit 1
}
SERVICE_PID_FILE="${pid}"
service_stop /usr/sbin/vnstatd
}
|