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

# Uncomment this if functions need to called inside /lib/qos
# include /lib/qos

START=21
STOP=10

USE_PROCD=1
PROG=/usr/sbin/qosmngr
INIT_QOS=/lib/qos/init_qos.sh

. /lib/functions.sh

. /lib/qos/qos.sh

start_service() {
	if [ -f "/etc/config/qos" ]; then
		log_level=$(jsonfilter -qe '@.daemon.config.loglevel' < /etc/bbfdm/services/qosmngr.json)
		[ -z "$log_level" ] && log_level="3"

		procd_open_instance init_qos
		procd_set_param command "${INIT_QOS}"
		procd_close_instance

		procd_open_instance qosmngr
		procd_set_param command "${PROG}" -l "${log_level}"
		procd_set_param respawn
		procd_close_instance
	fi
}

boot() {
	setup_qos
	start
}

service_triggers() {
	procd_add_reload_trigger qos
}

restart() {
	stop
	setup_qos
	start
}

reload_service() {
	while procd_running qos init_qos; do
		sleep 1
	done

	reload_qos_service
}
