#!/bin/sh /etc/rc.common

START=60
STOP=50

USE_PROCD=1

init_database() {
	/usr/sbin/vnstatd --initdb >/dev/null
}

init_ifaces() {
	local cfg="$1"

	init_iface() {
		local ifn="$1"

		/usr/bin/vnstat --add --force -i "$ifn" >/dev/null
	}

	config_list_foreach "$cfg" interface init_iface
}

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 --noadd --startempty --noremove
	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
}
