#!/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" init_iface() { /usr/bin/vnstat -u -i "$1" >/dev/null; } config_list_foreach "$cfg" interface init_iface return 1 } config_load vnstat config_foreach init_ifaces vnstat /usr/sbin/vnstatd -d } stop() { local pid="$(vnstat_option PidFile)" [ -n "$pid" ] && { service_kill vnstatd "$pid" rm -f "$pid" } }