#!/sbin/openrc-run

name=radsecproxy
description="Generic RADIUS proxy"
description_checkconfig="Check configuration"
description_reopen="Reopen log files and reload TLS certificate CRLs"

extra_commands="checkconfig"
extra_started_commands="reopen"

: ${command_user:="radsecproxy:radsecproxy"}
: ${cfgfile:="/etc/radsecproxy.conf"}

command="/usr/sbin/radsecproxy"
command_args="-c $cfgfile -f ${command_args:-}"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"

required_files="$cfgfile"

depend() {
	need net
	use dns logger netmount
}

start_pre() {
	$command $command_args -p
}

checkconfig() {
	ebegin "Checking $name configuration"

	start_pre
	eend $?
}

reopen() {
	ebegin "Reopening $name log files and CRLs"

	if [ "$supervisor" ]; then
		$supervisor "$RC_SVCNAME" --signal HUP
	else
		start-stop-daemon --signal HUP --pidfile "$pidfile"
	fi
	eend $?
}
