#!/bin/sh /etc/rc.common
|
|
|
|
START=60
|
|
STOP=50
|
|
|
|
USE_PROCD=1
|
|
|
|
vnstat_option() {
|
|
sed -ne "s/^[[:space:]]*$1[[:space:]]*['\"]\([^'\"]*\)['\"].*/\1/p" \
|
|
/etc/vnstat.conf
|
|
}
|
|
|
|
init_database() {
|
|
local lib="$(vnstat_option DatabaseDir)"
|
|
|
|
local database_count="$(ls "$lib" 2>/dev/null | wc -l)"
|
|
|
|
# only init database when folder is empty, as it would prevent import of legacy databases
|
|
if [ "$database_count" -eq "0" ]; then
|
|
/usr/sbin/vnstatd --initdb >/dev/null
|
|
fi
|
|
}
|
|
|
|
init_ifaces() {
|
|
local cfg="$1"
|
|
|
|
init_iface() {
|
|
local ifn="$1"
|
|
|
|
/usr/bin/vnstat --add -i "$ifn" >/dev/null
|
|
}
|
|
|
|
config_list_foreach "$cfg" interface init_iface
|
|
|
|
return 1
|
|
}
|
|
|
|
start_service() {
|
|
init_database
|
|
|
|
config_load vnstat
|
|
config_foreach init_ifaces vnstat
|
|
|
|
procd_open_instance
|
|
procd_set_param stdout 1
|
|
procd_set_param stderr 1
|
|
procd_set_param command /usr/sbin/vnstatd --nodaemon
|
|
procd_set_param file /etc/vnstat.conf
|
|
procd_set_param respawn
|
|
procd_close_instance
|
|
}
|
|
|
|
reload_service() {
|
|
config_load vnstat
|
|
config_foreach init_ifaces vnstat
|
|
|
|
procd_send_signal vnstat
|
|
}
|
|
|
|
service_triggers() {
|
|
procd_add_reload_trigger vnstat
|
|
}
|