[packages] vnstat: rework package, get rid of download stuff (this is better done...
[openwrt/svn-archive/archive.git] / net / vnstat / files / vnstat.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2011 OpenWrt.org
3
4 START=99
5
6 vnstat_option() {
7 sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
8 /etc/vnstat.conf
9 }
10
11 start() {
12 local lib="$(vnstat_option DatabaseDir)"
13 local pid="$(vnstat_option PidFile)"
14
15 [ -n "$lib" ] || {
16 echo "Error: No DatabaseDir set in vnstat.conf" >&2
17 exit 1
18 }
19
20 [ -n "$pid" ] || {
21 echo "Error: No PidFile set in vnstat.conf" >&2
22 exit 1
23 }
24
25 mkdir -p "$lib"
26
27 init_ifaces() {
28 local cfg="$1"
29 init_iface() { /usr/bin/vnstat -u -i "$1" >/dev/null; }
30 config_list_foreach "$cfg" interface init_iface
31 return 1
32 }
33
34 config_load vnstat
35 config_foreach init_ifaces vnstat
36
37 /usr/sbin/vnstatd -d
38 }
39
40 stop() {
41 local pid="$(vnstat_option PidFile)"
42 [ -n "$pid" ] && {
43 service_kill vnstatd "$pid"
44 rm -f "$pid"
45 }
46 }