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

START=15
STOP=8

USE_PROCD=1
PROG=/usr/sbin/sysmngr

start_service()
{
	local log_level

	config_load sysmngr
	config_get log_level "globals" log_level 3

	procd_open_instance "sysmngr"
	procd_set_param command ${PROG}
	procd_append_param command -l "${log_level}"
	procd_set_param respawn
	procd_close_instance "sysmngr"
}

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

	return 0
}

service_triggers() {
	procd_add_reload_trigger sysmngr
}
