#!/sbin/openrc-run

: ${cfgfile:="/etc/kea/kea-ctrl-agent.conf"}
: ${logger_dest:="syslog"}
: ${command_user:="kea"}
: ${retry:="SIGTERM/5/SIGINT/1/SIGKILL/1"}
: ${wait:=300}

name="kea-ctrl-agent"
extra_commands="checkconfig"
description_checkconfig="Checks configuration file for errors"

command="/usr/sbin/kea-ctrl-agent"
command_args="-c $cfgfile"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"

start_stop_daemon_args="--wait $wait $start_stop_daemon_args"
# The leading space is to avoid fallback to $start_stop_daemon_args when this
# is empty (supervise-daemon doesn't support --wait).
supervise_daemon_args=" $supervise_daemon_args"


depend() {
	need net
	after firewall
}

start_pre() {
	checkpath -d -m 0750 -o $command_user -q /run/kea /run/kea/lock || return 1
	case "$logger_dest" in
		/*) checkpath -f -m 0640 -o $command_user "$logger_dest" || return 1
	esac

	export KEA_LOGGER_DESTINATION="$logger_dest"

	checkconfig
}

checkconfig() {
	ebegin "Checking $name configuration"
	$command -t "$cfgfile" >/dev/null
	eend $?
}
