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

START=60
STOP=10

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

validate_global_section() {
	uci_validate_section bulkdata bulkdata bulkdata \
	    'enable:bool:1' \
	    'loglevel:uinteger:3'
}

start_service() {
	local enable loglevel

	validate_global_section

	procd_open_instance "bulkdata"
	procd_set_param command "$PROG"
	procd_append_param command -l ${loglevel}
	procd_set_param respawn
	procd_close_instance "bulkdata"
}

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

	return 0
}

service_triggers() {
	procd_add_reload_trigger bulkdata
}
