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

START=99
STOP=02
USE_PROCD=1

PROG=/usr/sbin/obuspa
CONFIGURATION=obuspa
ENV_PROFILE="/root/.profile"
KEEP_FILE="/lib/upgrade/keep.d/obuspa"

RESET_FILE="/tmp/obuspa/fw_defaults"

OBUSPA_BOOT_MARKER="/etc/obuspa/.boot"

BASEPATH=""
INSTANCE_COUNT=0
CLIENT_ID_PREFIX=""

. /lib/functions/network.sh
. /etc/obuspa/usp_utils.sh

global_init()
{
	BASEPATH=""
	INSTANCE_COUNT=0
}

log()
{
	echo "$*"|logger -t obuspa.init -p debug
	echo "$*" >/dev/console
}

db_set_reset_file()
{
	local param value

	param="${1}"
	shift
	value="$*"

	if [ -n "${param}" ]; then
		echo "${param} \"${value}\"">>${RESET_FILE}
	else
		echo >>${RESET_FILE}
	fi
}

db_set()
{
	db_set_reset_file "$@"
}

# if db present then check if it matches with existing instances
# fallback to max instance present + 1
# In case of no db get the count
get_base_path()
{
	local refpath value path count

	refpath="${1}"
	value="${2}"
	path=""
	count=0

	if [ -z "${path}" ]; then
		INSTANCE_COUNT=$(( INSTANCE_COUNT + 1 ))
		path="${refpath}${INSTANCE_COUNT}"
	fi
	BASEPATH="${path}"
}

get_refrence_path()
{
	local dmref value path

	dmref="${1}"
	value="${2}"
	path=""

	if [ -f "${RESET_FILE}" ]; then
		path=$(grep -E "${dmref}\d+.Alias " ${RESET_FILE}|grep -w "${value}")
	fi
	path=${path%.*}
	echo "${path}"
}

update_keep()
{
	file=${1}

	if [ -z "${file}" ]; then
		return 0
	fi

	if [ ! -f "${KEEP_FILE}" ]; then
		touch "${KEEP_FILE}"
	fi

	if ! grep -q "${file}" ${KEEP_FILE}; then
		echo "${file}" >> ${KEEP_FILE}
	fi
}

validate_obuspa_section()
{
	uci_validate_section ${CONFIGURATION} obuspa "${1}" \
		'enabled:bool:1' \
		'trust_cert:file' \
		'client_cert:file' \
		'interface:string' \
		'ifname:string' \
		'prototrace:bool:0' \
		'log_level:uinteger' \
		'min_num_to_group:uinteger' \
		'max_group_sep:uinteger' \
		'max_cache_time:uinteger' \
		'ipc_timeout:uinteger' \
		'log_dest:string' \
		'db_file:string'
}

validate_localagent_section()
{
	uci_validate_section ${CONFIGURATION} localagent "${1}" \
		'EndpointID:string'
}

validate_controller_section()
{
	uci_validate_section ${CONFIGURATION} controller "${1}" \
		'Enable:bool:1' \
		'EndpointID:string' \
		'assigned_role_name:string' \
		'Protocol:or("STOMP","CoAP","MQTT", "WebSocket")' \
		'Destination:string' \
		'Topic:string' \
		'ParameterName:list(string)' \
		'mqtt:string' \
		'stomp:string' \
		'Host:string' \
		'Port:port' \
		'Path:string' \
		'EnableEncryption:bool' \
		'PeriodicNotifInterval:uinteger' \
		'SessionMode:string' \
		'ProvisioningCode:string'
}

validate_subscription_section()
{
	uci_validate_section ${CONFIGURATION} subscription "${1}" \
		'Enable:bool:1' \
		'NotifType:or("ValueChange","ObjectCreation","ObjectDeletion","OperationComplete","Event")' \
		'ReferenceList:list(string)' \
		'Recipient:string' \
		'controller:string'
}

validate_mtp_section()
{
	uci_validate_section ${CONFIGURATION} mtp "${1}" \
		'Enable:bool:1' \
		'Protocol:or("STOMP","CoAP","MQTT", "WebSocket")' \
		'ResponseTopicConfigured:string' \
		'Destination:string' \
		'Port:port' \
		'Path:string' \
		'mqtt:string' \
		'stomp:string' \
		'PublishQoS:uinteger' \
		'EnableEncryption:bool'
}

validate_stomp_connection_section()
{
	uci_validate_section ${CONFIGURATION} stomp "${1}" \
		'Enable:bool:1' \
		'Host:string' \
		'Port:port:61613' \
		'Username:string' \
		'Password:string' \
		'EnableEncryption:bool:1' \
		'EnableHeartbeats:bool:1' \
		'VirtualHost:string:/'
}

validate_mqtt_client_section()
{
	uci_validate_section ${CONFIGURATION} mqtt "${1}" \
		'Enable:bool:1' \
		'BrokerAddress:string' \
		'BrokerPort:port:1883' \
		'Username:string' \
		'Password:string' \
		'ProtocolVersion:or("3.1", "3.1.1","5.0"):5.0' \
		'TransportProtocol:or("TCP/IP","TLS"):TCP/IP' \
		'ClientID:string' \
		'RequestResponseInfo:bool:1'
}

validate_challenge_section()
{
	uci_validate_section ${CONFIGURATION} challenge "${1}" \
		'Enable:bool:1' \
		'Description:string' \
		'role_name:string' \
		'Role:string' \
		'Value:string' \
		'Retries:uinteger:3' \
		'LockoutPeriod:uinteger:0'
}

configure_localagent()
{
	local EndpointID

	validate_localagent_section "${1}" || {
		log "Validation of localagent section failed"
		return 0
	}

	db_set Device.LocalAgent.EndpointID "${EndpointID}"
}

update_reset_reason()
{
	[ -f "/tmp/reset_reason" ] || return 0

	if grep -qwi "defaultreset" /tmp/reset_reason; then
		db_set Internal.Reboot.Cause "FactoryReset"
	fi
}

update_dual_stack_pref()
{
	db_set Internal.DualStackPreference "${1}"
}

get_role_index()
{
	local name drole

	name="${1}"
	drole="Device.LocalAgent.ControllerTrust.Role.2"
	if [ -z "${name}" ]; then
		log "No role name provided, use Untrusted role index 2"
		echo "${drole}"
		return 0
	fi

	if [ "${name}" = "full_access" ] || [ "${name}" = "Full Access" ]; then
		echo "Device.LocalAgent.ControllerTrust.Role.1"
		return 0
	fi

	if [ "${name}" = "Untrusted" ]; then
		echo "Device.LocalAgent.ControllerTrust.Role.1"
		return 0
	fi

	# Get if from CTRUST file first if present, then from dbdump and then use default Untrusted role
	if [ -f "${CTRUST_RESET_FILE}" ]; then
		val="$(grep "Device.LocalAgent.ControllerTrust.Role.\d.Name" ${CTRUST_RESET_FILE} |grep $name)"
		val="$(echo ${val/.Name /,}|cut -d, -f 1)"
		echo "$val"
	else
		log "Not able to get role ${name}, use Untrusted role"
		echo "${drole}"
	fi
}

configure_controller()
{
	local EndpointID Enable 
	local Protocol Destination
	local Topic mqtt stomp assigned_role_name AssignedRole ParameterName ProvisioningCode
	local Host Port Path EnableEncryption PeriodicNotifInterval
	local dm_ref sec

	sec="${1}"
	validate_controller_section "${1}" || {
		log "Validation of controller section failed"
		return 1
	}

	sec="${sec/controller_/cpe-}"
	get_base_path "Device.LocalAgent.Controller." "${sec}"
	if [ -z "${BASEPATH}" ]; then
		log "Failed to get path [$BASEPATH]"
		return 1
	fi

	if [ -z "${Protocol}" ]; then
		log "controller:: Protocol cannot be empty"
		return 1
	fi

	dm_ref=""
	if [ "${Protocol}" = "STOMP" ]; then
		stomp="${stomp/stomp_/cpe-}"
		dm_ref=$(get_refrence_path "Device.STOMP.Connection." "${stomp}")
	elif [ "${Protocol}" = "MQTT" ]; then
		mqtt="${mqtt/mqtt_/cpe-}"
		dm_ref=$(get_refrence_path "Device.MQTT.Client." "${mqtt}")
	fi

	db_set "${BASEPATH}.Alias" "${sec}"
	db_set "${BASEPATH}.Enable" "${Enable}"
	db_set "${BASEPATH}.EndpointID" "${EndpointID}"

	if [ -n "${ProvisioningCode}" ]; then
		db_set "${BASEPATH}.ProvisioningCode" "${ProvisioningCode}"
	fi

	if [ -n "${PeriodicNotifInterval}" ]; then
		db_set "${BASEPATH}.PeriodicNotifInterval" "${PeriodicNotifInterval}"
	fi

	if [ -n "${SessionMode}" ]; then
		db_set "${BASEPATH}.E2ESession.SessionMode" "${SessionMode}"
	fi

	if [ -n "${assigned_role_name}" ]; then
		AssignedRole=$(get_role_index "${assigned_role_name}")
		if [ -n "${AssignedRole}" ]; then
			db_set "${BASEPATH}.AssignedRole" "${AssignedRole}"
		fi
	fi

	db_set "${BASEPATH}.MTP.1.Alias" "${sec}"
	db_set "${BASEPATH}.MTP.1.Enable" "${Enable}"
	db_set "${BASEPATH}.MTP.1.Protocol" "${Protocol}"
	# only support configuration of one mtp path per controller using uci
	if [ "${Protocol}" = "MQTT" ]; then
		# Cleanup
		db_set "${BASEPATH}.MTP.1.WebSocket.Host" ""
		db_set "${BASEPATH}.MTP.1.WebSocket.Path" ""
		db_set "${BASEPATH}.MTP.1.STOMP.Reference" ""
		db_set "${BASEPATH}.MTP.1.STOMP.Destination" ""

		db_set "${BASEPATH}.MTP.1.MQTT.Reference" "${dm_ref}"
		db_set "${BASEPATH}.MTP.1.MQTT.Topic" "${Topic}"
	elif [ "${Protocol}" = "STOMP" ]; then
		# Cleanup
		db_set "${BASEPATH}.MTP.1.WebSocket.Host" ""
		db_set "${BASEPATH}.MTP.1.WebSocket.Path" ""
		db_set "${BASEPATH}.MTP.1.MQTT.Reference" ""
		db_set "${BASEPATH}.MTP.1.MQTT.Topic" ""

		db_set "${BASEPATH}.MTP.1.STOMP.Reference" "${dm_ref}"
		db_set "${BASEPATH}.MTP.1.STOMP.Destination" "${Destination}"
	elif [ "${Protocol}" = "CoAP" ]; then
		db_set "${BASEPATH}.MTP.1.CoAP.Host" "${Host}"
		db_set "${BASEPATH}.MTP.1.CoAP.Path" "${Path}"
		db_set "${BASEPATH}.MTP.1.CoAP.Port" "${Port}"
		db_set "${BASEPATH}.MTP.1.CoAP.EnableEncryption" "${EnableEncryption}"
	elif [ "${Protocol}" = "WebSocket" ]; then
		# Cleanup
		db_set "${BASEPATH}.MTP.1.STOMP.Reference" ""
		db_set "${BASEPATH}.MTP.1.STOMP.Destination" ""
		db_set "${BASEPATH}.MTP.1.MQTT.Reference" ""
		db_set "${BASEPATH}.MTP.1.MQTT.Topic" ""

		db_set "${BASEPATH}.MTP.1.WebSocket.Host" "${Host}"
		db_set "${BASEPATH}.MTP.1.WebSocket.Port" "${Port}"
		db_set "${BASEPATH}.MTP.1.WebSocket.Path" "${Path}"
		db_set "${BASEPATH}.MTP.1.WebSocket.EnableEncryption" "${EnableEncryption}"
	fi

	local param
	local _pnum=1

	for param in ${ParameterName}
	do
		db_set "${BASEPATH}.BootParameter.${_pnum}.Alias" "${sec}_boot_${_pnum}"
		db_set "${BASEPATH}.BootParameter.${_pnum}.Enable" "${Enable}"
		db_set "${BASEPATH}.BootParameter.${_pnum}.ParameterName" "${param}"
		_pnum=$(( _pnum + 1 ))
	done
}

configure_subscription()
{
	local Enable NotifType ReferenceList controller
	local dm_ref
	local sec

	sec="${1}"
	validate_subscription_section "${1}" || {
		log "Validation of subscription section failed"
		return 1
	}

	sec="${sec/sub_/cpe-}"
	get_base_path "Device.LocalAgent.Subscription." "sub_${1}"
	if [ -z "${BASEPATH}" ]; then
		log "Failed to get path [$BASEPATH]"
		return 1
	fi

	if [ -n "${controller}" ]; then
		controller="${controller/controller_/cpe-}"
		dm_ref=$(get_refrence_path "Device.LocalAgent.Controller." "${controller}")
	fi

	db_set "${BASEPATH}.Alias" "${sec}"
	db_set "${BASEPATH}.ID" "uci-${1}"
	db_set "${BASEPATH}.CreationDate" "$(date -I'seconds')"
	db_set "${BASEPATH}.Enable" "${Enable}"
	db_set "${BASEPATH}.NotifType" "${NotifType}"
	if [ -n "${ReferenceList}" ]; then
		ReferenceList=${ReferenceList// /,}
		db_set "${BASEPATH}.ReferenceList" "${ReferenceList}"
	fi
	db_set "${BASEPATH}.Persistent" "1"
	db_set "${BASEPATH}.Recipient" "${dm_ref}"
	# Entry updated in db, remove uci entry
	uci_remove obuspa "${1}"
}

configure_challenges()
{
	local Enable Description role_name Role Value Retries LockoutPeriod
	local sec

	sec="${1}"
	validate_challenge_section "${1}" || {
		log "Validation of challenge section failed"
	}

	sec="${sec/challenge_/cpe-}"
	get_base_path "Device.LocalAgent.ControllerTrust.Challenge." "${sec}"
	if [ -z "${BASEPATH}" ]; then
		log "Failed to get path [$BASEPATH]"
		return 1
	fi

	if [ -z "${role_name}" ] && [ -z "${Role}" ]; then
		log "Either role_name or Role must defined for a challenge"
		return 1
	fi

	db_set "${BASEPATH}.Alias" "${sec}"
	db_set "${BASEPATH}.Enable" "${Enable}"
	db_set "${BASEPATH}.Description" "${Description}"

	if [ -z "${Role}" ]; then
		Role=$(get_role_index "${role_name}")
	fi

	db_set "${BASEPATH}.Role" "${Role}"
	db_set "${BASEPATH}.Value" "${Value}"
	db_set "${BASEPATH}.Retries" "${Retries}"
	db_set "${BASEPATH}.LockoutPeriod" "${LockoutPeriod}"
	# Entry updated in db, remove uci entry
	uci_remove obuspa "${1}"
}

configure_mtp() {
	local Enable Protocol ResponseTopicConfigured
	local Path Port EnableEncryption PublishQoS
	local stomp mqtt dm_ref sec

	sec="${1}"
	validate_mtp_section "${1}" || {
		log "Validation of mtp section failed"
		return 1
	}
	sec="${sec/mtp_/cpe-}"
	get_base_path "Device.LocalAgent.MTP." "${sec}"
	if [ -z "${BASEPATH}" ]; then
		log "Failed to get path [$BASEPATH]"
		return 1
	fi

	if [ -z "${Protocol}" ]; then
		log "Protocol not defined for the mtp[${1}] section"
		return 1
	fi

	dm_ref=""
	if [ "${Protocol}" = "STOMP" ]; then
		stomp="${stomp/stomp_/cpe-}"
		dm_ref=$(get_refrence_path "Device.STOMP.Connection." "${stomp}")
	elif [ "${Protocol}" = "MQTT" ]; then
		mqtt="${mqtt/mqtt_/cpe-}"
		dm_ref=$(get_refrence_path "Device.MQTT.Client." "${mqtt}")
	fi

	db_set "${BASEPATH}.Alias" "${sec}"
	db_set "${BASEPATH}.Enable" "${Enable}"
	db_set "${BASEPATH}.Protocol" "${Protocol}"
	if [ "${Protocol}" = "MQTT" ]; then
		# cleanup
		db_set "${BASEPATH}.WebSocket.Path" ""
		db_set "${BASEPATH}.STOMP.Reference" ""
		db_set "${BASEPATH}.STOMP.Destination" ""

		db_set "${BASEPATH}.MQTT.Reference" "${dm_ref}"
		db_set "${BASEPATH}.MQTT.ResponseTopicConfigured" "${ResponseTopicConfigured}"
		if [ -n "${PublishQoS}" ]; then
			db_set "${BASEPATH}.MQTT.PublishQoS" "${PublishQoS}"
		fi
	elif [ "${Protocol}" = "STOMP" ]; then
		# cleanup
		db_set "${BASEPATH}.WebSocket.Path" ""
		db_set "${BASEPATH}.MQTT.Reference" ""
		db_set "${BASEPATH}.MQTT.ResponseTopicConfigured" ""

		db_set "${BASEPATH}.STOMP.Reference" "${dm_ref}"
		db_set "${BASEPATH}.STOMP.Destination" "${Destination}"
	elif [ "${Protocol}" = "CoAP" ]; then
		db_set "${BASEPATH}.CoAP.Path" "${Path}"
		db_set "${BASEPATH}.CoAP.Port" "${Port}"
	elif [ "${Protocol}" = "WebSocket" ]; then
		# cleanup
		db_set "${BASEPATH}.MQTT.Reference" ""
		db_set "${BASEPATH}.MQTT.ResponseTopicConfigured" ""
		db_set "${BASEPATH}.STOMP.Reference" ""
		db_set "${BASEPATH}.STOMP.Destination" ""

		db_set "${BASEPATH}.WebSocket.Path" "${Path}"
		db_set "${BASEPATH}.WebSocket.Port" "${Port}"
		db_set "${BASEPATH}.WebSocket.EnableEncryption" "${EnableEncryption}"
	fi
}

configure_stomp_connection() {
	local Host Username Password Enable Port VirtualHost
	local EnableEncryption EnableHeartbeats
	local sec

	sec="${1}"
	validate_stomp_connection_section "${1}" || {
		log "Validation of stomp section failed"
		return 1
	}

	sec="${sec/stomp_/cpe-}"
	get_base_path "Device.STOMP.Connection." "${sec}"
	if [ -z "${BASEPATH}" ]; then
		log "Failed to get path [$BASEPATH]"
		return 1
	fi

	db_set "${BASEPATH}.Alias" "${sec}"
	db_set "${BASEPATH}.Host" "${Host}"
	db_set "${BASEPATH}.Username" "${Username}"
	db_set "${BASEPATH}.Password" "${Password}"

	db_set "${BASEPATH}.Enable" "${Enable}"
	db_set "${BASEPATH}.Port" "${Port}"
	db_set "${BASEPATH}.EnableEncryption" "${EnableEncryption}"
	db_set "${BASEPATH}.EnableHeartbeats" "${EnableHeartbeats}"
	db_set "${BASEPATH}.VirtualHost" "${VirtualHost}"
}

configure_mqtt_client() {
	local BrokerAddress BrokerPort Enable Username Password ProtocolVersion
	local TransportProtocol ClientID RequestResponseInfo
	local sec

	sec="${1}"
	validate_mqtt_client_section "${1}" || {
		log "Validation of mqtt section failed"
		return 1
	}

	sec="${sec/mqtt_/cpe-}"
	get_base_path "Device.MQTT.Client." "${sec}"
	if [ -z "${BASEPATH}" ]; then
		log "Failed to get path [$BASEPATH]"
		return 1
	fi

	if [ -z "${ClientID}" ]; then
		ClientID="${CLIENT_ID_PREFIX}-${sec}"
	fi

	db_set "${BASEPATH}.Alias" "${sec}"
	db_set "${BASEPATH}.Enable" "${Enable}"
	db_set "${BASEPATH}.BrokerAddress" "${BrokerAddress}"
	db_set "${BASEPATH}.BrokerPort" "${BrokerPort}"
	db_set "${BASEPATH}.Username" "${Username}"
	db_set "${BASEPATH}.Password" "${Password}"
	db_set "${BASEPATH}.ProtocolVersion" "${ProtocolVersion}"
	db_set "${BASEPATH}.TransportProtocol" "${TransportProtocol}"
	db_set "${BASEPATH}.ClientID" "${ClientID}"
	db_set "${BASEPATH}.RequestResponseInfo" "${RequestResponseInfo}"
}


configure_obuspa() {
	local enabled trust_cert ifname interface prototrace log_level db_file log_dest
	local client_cert

	validate_obuspa_section "global"

	if [ "${prototrace}" -eq 1 ]; then
		procd_append_param command -p
	fi

	if [ -n "${log_level}" ]; then
		if [ "${log_level}" -gt "4" ]; then
			log_level="4"
		fi
		procd_append_param command -v "${log_level}"
	fi

	if [ -n "${log_dest}" ]; then
		procd_append_param command -l "${log_dest}"
	fi

	if [ -n "${interface}" ]; then
		network_get_physdev ifname "${interface}"
	fi

	if [ -n "${ifname}" ]; then
		procd_set_param env USP_BOARD_IFNAME="${ifname}"
	fi

	if [ -z "${ifname}" ] || ! grep -F -q "export USP_BOARD_IFNAME=${ifname}" "${ENV_PROFILE}"; then
		if [ -f "${ENV_PROFILE}" ]; then
			sed -i "/export USP_BOARD_IFNAME/d" "${ENV_PROFILE}"
		fi

		if [ -n "${ifname}" ]; then
			# Set this variable for root user and obuspa -c tool
			echo "export USP_BOARD_IFNAME=${ifname}" >> "${ENV_PROFILE}"
		fi
	fi

	if [ -n "${db_file}" ]; then
		update_keep "${db_file}"
		procd_append_param command -f "${db_file}"
		if [ -f "${db_file}-journal" ]; then
			log "SQL Journal detected ..."
		fi
	fi

	if [ -f "${RESET_FILE}" ]; then
		procd_append_param command -r ${RESET_FILE}
	fi

	if [ -n "${trust_cert}" ]; then
		update_keep "${trust_cert}"
		if [ -f "${trust_cert}" ]; then
			procd_append_param command -t "${trust_cert}"
		fi
	else
		# Use default CA, if trust store not defined
		if [ -f "/etc/ssl/cert.pem" ]; then
			procd_append_param command -t "/etc/ssl/cert.pem"
		fi
	fi

	if [ -n "${client_cert}" ]; then
		update_keep "${client_cert}"
		if [ -f "${client_cert}" ]; then
			procd_append_param command -a "${client_cert}"
		fi
	fi
}

# Create factory reset file
db_init()
{
	local reason

	reason="${1}"
	# remove usp.db, in case of reload
	if [ -f "${OBUSPA_BOOT_MARKER}" ] && [ "${reason}" = "update" ]; then
		log "Deleting ${OBUSPA_BOOT_MARKER} in order to enforce values from UCI..."
		rm -f "${OBUSPA_BOOT_MARKER}"
	fi

	if [ -f "${OBUSPA_BOOT_MARKER}" ]; then
		return 0
	fi

	# Remove reset file if present
	[ -f "${RESET_FILE}" ] && rm ${RESET_FILE}

	CLIENT_ID_PREFIX="$(db -q get device.deviceinfo.ManufacturerOUI)"
	CLIENT_ID_PREFIX="${CLIENT_ID_PREFIX}-$(db -q get device.deviceinfo.SerialNumber)"
	CLIENT_ID_PREFIX="${CLIENT_ID_PREFIX//+/%2b}"

	#log "Create reset file ...."
	config_load $CONFIGURATION
	config_get dualstack_pref global dualstack_pref "IPv6"

	log "Enforcing UCI values, no boot marker found."
	global_init
	config_foreach configure_localagent localagent
	global_init
	config_foreach configure_stomp_connection stomp
	global_init
	config_foreach configure_mqtt_client mqtt
	global_init
	config_foreach configure_mtp mtp
	global_init
	config_foreach configure_controller controller
	global_init
	config_foreach configure_subscription subscription
	global_init
	config_foreach configure_challenges challenge

	# enforce ctrust only on upgrades, not on reloads
	if [ -f "${CTRUST_RESET_FILE}" ] && [ -z "${reason}" ]; then
		cat ${CTRUST_RESET_FILE} >> ${RESET_FILE}
	fi
	update_reset_reason
	update_dual_stack_pref "${dualstack_pref}"
}

start_service() {
	local enabled

	mkdir -p /tmp/obuspa/
	config_load obuspa
	config_get_bool enabled global enabled 1

	procd_open_instance ${CONFIGURATION}
	if [ "${enabled}" -eq 1 ]; then
		procd_set_param command ${PROG}
		db_init "${1}"
		configure_obuspa
		procd_set_param respawn \
			"${respawn_threshold:-10}" \
			"${respawn_timeout:-10}" "${respawn_retry:-5}"
	fi
	procd_close_instance ${CONFIGURATION}
}

stop_service() {
	${PROG} -c stop
}

reload_service() {
	stop
	start update
}

service_triggers() {
	export PROCD_RELOAD_DELAY=3000
	procd_add_reload_trigger "obuspa"
}
