#!/sbin/openrc-run

name="hostapd"
description="User space daemon for access point and authentication servers"

extra_started_commands="reload"

# $CONFIGS and $OPTIONS are deprecated since Alpine v3.17.
# NOTE: cfgfile can contain more than one file path in this case.
: ${cfgfile:=${CONFIGS:-"/etc/hostapd/hostapd.conf"}}

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

required_files="$cfgfile"

depend() {
	need net
	after firewall
	use logger
}

reload() {
	ebegin "Reloading $name configuration"

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