From: jow Date: Fri, 14 Jan 2011 19:53:27 +0000 (+0000) Subject: [packages] vnstat: rework package, get rid of download stuff (this is better done... X-Git-Url: http://207.154.207.93/?a=commitdiff_plain;h=1ba7498ad0bfde50413f02b4f71955275054403e;p=packages.git [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 --- diff --git a/net/vnstat/Makefile b/net/vnstat/Makefile index e0f364ca4..29995fc6a 100644 --- a/net/vnstat/Makefile +++ b/net/vnstat/Makefile @@ -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)) diff --git a/net/vnstat/files/vnstat-uci.conf b/net/vnstat/files/vnstat-uci.conf index 44c02c2d0..339fda48a 100644 --- a/net/vnstat/files/vnstat-uci.conf +++ b/net/vnstat/files/vnstat-uci.conf @@ -1,4 +1,3 @@ -config interface wan - option enabled 0 - option remote_host - option remote_path +config vnstat + list interface br-lan +# list interface eth0.1 diff --git a/net/vnstat/files/vnstat.init b/net/vnstat/files/vnstat.init index 5632c6a77..2febdfae3 100644 --- a/net/vnstat/files/vnstat.init +++ b/net/vnstat/files/vnstat.init @@ -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}" +vnstat_option() { + sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \ + /etc/vnstat.conf } -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 +start() { + local lib="$(vnstat_option DatabaseDir)" + local pid="$(vnstat_option PidFile)" - 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 + [ -n "$lib" ] || { + echo "Error: No DatabaseDir set in vnstat.conf" >&2 + exit 1 + } - 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 + [ -n "$pid" ] || { + echo "Error: No PidFile set in vnstat.conf" >&2 + exit 1 } -} -start() { - [ -d $LIB_D ] || mkdir -p $LIB_D - [ -d $WWW_D ] || mkdir -p $WWW_D + mkdir -p "$lib" - config_load system - config_foreach system_config system + 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) -} - -reload() { - [ -f $PID_F ] && kill -HUP $(cat $PID_F) + local pid="$(vnstat_option PidFile)" + [ -n "$pid" ] && { + service_kill vnstatd "$pid" + rm -f "$pid" + } } -