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

START=98
STOP=20

USE_PROCD=1

start_service() {
	if [ -e "/etc/config/mapagent" -o -e "/etc/config/mapcontroller" ]; then
		config_load mapagent
		config_get_bool agent_enabled agent enabled 1
		config_load mapcontroller
		config_get_bool controller_enabled controller enabled 1

		if [ $agent_enabled -eq 1 -o $controller_enabled -eq 1 ]; then
			procd_open_instance
			procd_set_param command "/usr/sbin/capiagent" "-p 9000"
			procd_set_param limits core="unlimited"
			#procd_set_param respawn
			#procd_set_param stdout 1
			#procd_set_param stderr 1
			procd_close_instance
		fi
	fi
}

service_triggers()
{
	procd_add_reload_trigger "capiagent"
}

reload_service() {
	stop
	start
}
