2008-07-28 19:34:31 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
2011-01-14 19:53:27 +00:00
|
|
|
# Copyright (C) 2008-2011 OpenWrt.org
|
2008-07-28 19:34:31 +00:00
|
|
|
|
|
|
|
START=99
|
|
|
|
|
2011-01-14 19:53:27 +00:00
|
|
|
vnstat_option() {
|
|
|
|
sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
|
|
|
|
/etc/vnstat.conf
|
2008-07-28 19:34:31 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 19:53:27 +00:00
|
|
|
start() {
|
|
|
|
local lib="$(vnstat_option DatabaseDir)"
|
|
|
|
local pid="$(vnstat_option PidFile)"
|
2008-07-28 19:34:31 +00:00
|
|
|
|
2011-01-14 19:53:27 +00:00
|
|
|
[ -n "$lib" ] || {
|
|
|
|
echo "Error: No DatabaseDir set in vnstat.conf" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2008-07-28 19:34:31 +00:00
|
|
|
|
2011-01-14 19:53:27 +00:00
|
|
|
[ -n "$pid" ] || {
|
|
|
|
echo "Error: No PidFile set in vnstat.conf" >&2
|
|
|
|
exit 1
|
2009-06-04 09:57:46 +00:00
|
|
|
}
|
2008-07-28 19:34:31 +00:00
|
|
|
|
2011-01-14 19:53:27 +00:00
|
|
|
mkdir -p "$lib"
|
2008-07-28 19:34:31 +00:00
|
|
|
|
2011-01-14 19:53:27 +00:00
|
|
|
init_ifaces() {
|
|
|
|
local cfg="$1"
|
|
|
|
init_iface() { /usr/bin/vnstat -u -i "$1" >/dev/null; }
|
|
|
|
config_list_foreach "$cfg" interface init_iface
|
|
|
|
return 1
|
|
|
|
}
|
2008-07-28 19:34:31 +00:00
|
|
|
|
|
|
|
config_load vnstat
|
2011-01-14 19:53:27 +00:00
|
|
|
config_foreach init_ifaces vnstat
|
2009-06-04 09:57:46 +00:00
|
|
|
|
2011-01-14 19:53:27 +00:00
|
|
|
/usr/sbin/vnstatd -d
|
2008-07-28 19:34:31 +00:00
|
|
|
}
|
2009-06-04 09:57:46 +00:00
|
|
|
|
|
|
|
stop() {
|
2011-01-14 19:53:27 +00:00
|
|
|
local pid="$(vnstat_option PidFile)"
|
|
|
|
[ -n "$pid" ] && {
|
|
|
|
service_kill vnstatd "$pid"
|
|
|
|
rm -f "$pid"
|
|
|
|
}
|
2009-06-04 09:57:46 +00:00
|
|
|
}
|