2008-07-28 19:34:31 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2008 OpenWrt.org
|
|
|
|
|
|
|
|
START=99
|
|
|
|
LIB_D=/var/lib/vnstat
|
|
|
|
WWW_D=/www/vnstat
|
2009-06-04 09:57:46 +00:00
|
|
|
RUN_D=/var/run
|
|
|
|
PID_F=$RUN_D/vnstat.pid
|
|
|
|
VNSTATD_BIN=/usr/sbin/vnstatd
|
2008-07-28 19:34:31 +00:00
|
|
|
|
|
|
|
system_config() {
|
|
|
|
local cfg="$1"
|
|
|
|
|
|
|
|
config_get hostname "$cfg" hostname
|
|
|
|
hostname="${hostname:-OpenWrt}"
|
|
|
|
}
|
|
|
|
|
|
|
|
do_download() {
|
|
|
|
include /lib/network
|
|
|
|
scan_interfaces
|
|
|
|
|
|
|
|
local cfg="$1"
|
|
|
|
|
2009-06-04 09:57:46 +00:00
|
|
|
config_get ifname "$cfg" ifname
|
2008-07-28 19:34:31 +00:00
|
|
|
[ -n "$ifname" ] || return 0
|
|
|
|
[ -e $LIB_D/$ifname ] && return 0
|
|
|
|
|
2009-06-04 09:57:46 +00:00
|
|
|
config_get_bool enabled "$cfg" enabled '1'
|
|
|
|
[ "$enabled" -gt 0 ] && {
|
|
|
|
config_get remote_host "$cfg" remote_host
|
2008-07-28 19:34:31 +00:00
|
|
|
[ -n "$remote_host" ] || return 0
|
2009-06-04 09:57:46 +00:00
|
|
|
config_get remote_path "$cfg" remote_path
|
|
|
|
[ -n "$remote_path" ] || return 0
|
2008-07-28 19:34:31 +00:00
|
|
|
|
|
|
|
while [ ! -e $LIB_D/$ifname ]; do
|
2009-06-04 09:57:46 +00:00
|
|
|
wget http://$remote_host/$remote_path/${hostname}_$ifname -O $LIB_D/$ifname 2>/dev/null
|
2008-07-28 19:34:31 +00:00
|
|
|
[ -e $LIB_D/$ifname ] && {
|
2009-06-04 09:57:46 +00:00
|
|
|
logger -t "vnstat" "Successfully downloaded ${ifname}'s vnStat database backup"
|
|
|
|
[ -L $WWW_D/$ifname ] || ln -s $LIB_D/$ifname $WWW_D/$ifname
|
2008-07-28 19:34:31 +00:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
sleep 30
|
|
|
|
done
|
2009-06-04 09:57:46 +00:00
|
|
|
}
|
2008-07-28 19:34:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
start() {
|
|
|
|
[ -d $LIB_D ] || mkdir -p $LIB_D
|
|
|
|
[ -d $WWW_D ] || mkdir -p $WWW_D
|
|
|
|
|
|
|
|
config_load system
|
|
|
|
config_foreach system_config system
|
|
|
|
|
|
|
|
config_load vnstat
|
|
|
|
config_foreach do_download interface
|
2009-06-04 09:57:46 +00:00
|
|
|
|
|
|
|
[ ! -f $PID_F ] && $VNSTATD_BIN -d
|
2008-07-28 19:34:31 +00:00
|
|
|
}
|
2009-06-04 09:57:46 +00:00
|
|
|
|
|
|
|
stop() {
|
|
|
|
[ -f $PID_F ] && kill $(cat $PID_F)
|
|
|
|
}
|
|
|
|
|
|
|
|
reload() {
|
|
|
|
[ -f $PID_F ] && kill -HUP $(cat $PID_F)
|
|
|
|
}
|
|
|
|
|