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

START=61
STOP=01

USE_PROCD=1
PROG="/usr/sbin/periodicstatsd"

start_service() {
	config_load periodicstats
	config_get log_level globals log_level "1"
	
	procd_open_instance "periodicstats"
	procd_set_param command ${PROG} -l ${log_level}
	procd_set_param respawn
	procd_close_instance "periodicstats"
}

reload_service() {
	ret=$(ubus call service list '{"name":"periodicstats"}' | jsonfilter -qe '@.periodicstats.instances.periodicstats.running')
	if [ "$ret" != "true" ]; then
		stop
		start
	else
		ubus send periodicstats.reload
	fi

	return
}

service_triggers() {
	procd_add_reload_trigger periodicstats
}
