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

START=98
STOP=11

USE_PROCD=1
PROG=/usr/sbin/decollector

service_running() {
	ubus -t 2 wait_for ieee1905 ieee1905.map
}

start_service() {
	sleep 3
	[ -e "/etc/config/mapcontroller" ] && {
		local en

		config_load mapcontroller
		config_get en controller enabled "0"
		config_get collect_int controller de_collect_interval

		[ -n "$collect_int" -a $collect_int -lt 30 ] &&  collect_int=""

		[ $en -gt 0 ] && {
			procd_open_instance
			procd_set_param command "$PROG" "-d" "${collect_int:+-t $collect_int}"
			#procd_set_param stdout 1
			#procd_set_param stderr 1
			procd_set_param respawn
			procd_close_instance
		}
	}
}

reload_service() {
	stop
	start
}

service_triggers()
{
	procd_add_reload_trigger mapcontroller
}
