#!/sbin/openrc-run

name="FreeRADIUS"
description_checkconfig="Check configuration"
description_reload="Reload configuration"

extra_commands="checkconfig"
extra_started_commands="reload"

: ${cfgfile:="/etc/raddb/radiusd.conf"}
cfgname="${cfgfile##*/}"

command="/usr/sbin/radiusd"
# RADIUSD_OPTS is for backward compatibility only
command_args="-f -d ${cfgfile%/*} -n ${cfgname%.conf} ${command_args:-$RADIUSD_OPTS}"
command_background="yes"
pidfile="/run/$RC_SVCNAME.pid"

required_files="$cfgfile"

depend() {
	need net
	after firewall
	use dns
}

start_pre() {
	# XXX: Is this still needed?
	checkpath -d -m 0755 -o radius:radius /run/radiusd
	checkconfig
}

checkconfig() {
	ebegin "Checking $name configuration"
	$command $command_args -C || $command $command_args -Cx -lstdout
	eend $?
}

reload () {
	ebegin "Reloading $name"

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