[packages] vnstat: rework package, get rid of download stuff (this is better done externally), initialize db in init script, store monitored interfaces in /etc/config/vnstat
git-svn-id: svn://svn.openwrt.org/openwrt/packages@25000 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
89a970759d
commit
1ba7498ad0
@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=vnstat
|
||||
PKG_VERSION:=1.10
|
||||
PKG_RELEASE:=1
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=http://humdi.net/vnstat
|
||||
@ -98,16 +98,14 @@ endef
|
||||
|
||||
define Package/vnstat/postinst
|
||||
#!/bin/sh
|
||||
BIN_REL=/usr/bin/vnstat
|
||||
BIN=$${IPKG_INSTROOT}$${BIN_REL}
|
||||
LIB_D_REL=/var/lib/vnstat
|
||||
LIB_D=$${IPKG_INSTROOT}$${LIB_D_REL}
|
||||
[ -d $$LIB_D ] || mkdir -p $$LIB_D
|
||||
IFACE_WAN=$$(uci get network.wan.ifname)
|
||||
if [ -n $$IFACE_WAN ]; then
|
||||
[ -e $$LIB_D/$$IFACE_WAN ] || ( [ -x $$BIN ] && $$BIN -u -i $$IFACE_WAN )
|
||||
local wan="$$(uci -P/var/state get network.wan.ifname)"
|
||||
if [ -n "$$wan" ]; then
|
||||
uci -q batch <<-EOF >/dev/null
|
||||
add_list vnstat.@vnstat[-1].interface=$$wan
|
||||
commit vnstat
|
||||
EOF
|
||||
fi
|
||||
true
|
||||
exit 0
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,vnstat))
|
||||
|
@ -1,4 +1,3 @@
|
||||
config interface wan
|
||||
option enabled 0
|
||||
option remote_host <webserver>
|
||||
option remote_path <directory>
|
||||
config vnstat
|
||||
list interface br-lan
|
||||
# list interface eth0.1
|
||||
|
@ -1,67 +1,46 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2008 OpenWrt.org
|
||||
# Copyright (C) 2008-2011 OpenWrt.org
|
||||
|
||||
START=99
|
||||
LIB_D=/var/lib/vnstat
|
||||
WWW_D=/www/vnstat
|
||||
RUN_D=/var/run
|
||||
PID_F=$RUN_D/vnstat.pid
|
||||
VNSTATD_BIN=/usr/sbin/vnstatd
|
||||
|
||||
system_config() {
|
||||
local cfg="$1"
|
||||
|
||||
config_get hostname "$cfg" hostname
|
||||
hostname="${hostname:-OpenWrt}"
|
||||
}
|
||||
|
||||
do_download() {
|
||||
include /lib/network
|
||||
scan_interfaces
|
||||
|
||||
local cfg="$1"
|
||||
|
||||
config_get ifname "$cfg" ifname
|
||||
[ -n "$ifname" ] || return 0
|
||||
[ -e $LIB_D/$ifname ] && return 0
|
||||
|
||||
config_get_bool enabled "$cfg" enabled '1'
|
||||
[ "$enabled" -gt 0 ] && {
|
||||
config_get remote_host "$cfg" remote_host
|
||||
[ -n "$remote_host" ] || return 0
|
||||
config_get remote_path "$cfg" remote_path
|
||||
[ -n "$remote_path" ] || return 0
|
||||
|
||||
while [ ! -e $LIB_D/$ifname ]; do
|
||||
wget http://$remote_host/$remote_path/${hostname}_$ifname -O $LIB_D/$ifname 2>/dev/null
|
||||
[ -e $LIB_D/$ifname ] && {
|
||||
logger -t "vnstat" "Successfully downloaded ${ifname}'s vnStat database backup"
|
||||
[ -L $WWW_D/$ifname ] || ln -s $LIB_D/$ifname $WWW_D/$ifname
|
||||
return 0
|
||||
}
|
||||
sleep 30
|
||||
done
|
||||
}
|
||||
vnstat_option() {
|
||||
sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
|
||||
/etc/vnstat.conf
|
||||
}
|
||||
|
||||
start() {
|
||||
[ -d $LIB_D ] || mkdir -p $LIB_D
|
||||
[ -d $WWW_D ] || mkdir -p $WWW_D
|
||||
local lib="$(vnstat_option DatabaseDir)"
|
||||
local pid="$(vnstat_option PidFile)"
|
||||
|
||||
config_load system
|
||||
config_foreach system_config system
|
||||
[ -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"
|
||||
init_iface() { /usr/bin/vnstat -u -i "$1" >/dev/null; }
|
||||
config_list_foreach "$cfg" interface init_iface
|
||||
return 1
|
||||
}
|
||||
|
||||
config_load vnstat
|
||||
config_foreach do_download interface
|
||||
config_foreach init_ifaces vnstat
|
||||
|
||||
[ ! -f $PID_F ] && $VNSTATD_BIN -d
|
||||
/usr/sbin/vnstatd -d
|
||||
}
|
||||
|
||||
stop() {
|
||||
[ -f $PID_F ] && kill $(cat $PID_F)
|
||||
local pid="$(vnstat_option PidFile)"
|
||||
[ -n "$pid" ] && {
|
||||
service_kill vnstatd "$pid"
|
||||
rm -f "$pid"
|
||||
}
|
||||
}
|
||||
|
||||
reload() {
|
||||
[ -f $PID_F ] && kill -HUP $(cat $PID_F)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user