#!/sbin/openrc-run

description="Small HTTP server"
extra_started_commands="reload"
start_stop_daemon_args="--quiet"

cfgfile=/etc/mini_httpd/$RC_SVCNAME.conf
pidfile=/run/mini_httpd/$RC_SVCNAME.pid
command=/usr/sbin/mini_httpd
required_files="$cfgfile"

depend() {
	need net
	after firewall
}

start_pre() {
	ebegin
	checkpath -d ${pidfile%/*}
	local logfile=$(awk -F= '$1 == "logfile" { print $2 }' $cfgfile 2>/dev/null)
	[ -n "$logfile" ] && checkpath -d ${logfile%/*}
	command_args="-i $pidfile -C $cfgfile ${logfile:+-l $logfile} $command_args"
	$command -V -C $cfgfile >/dev/null
	eend $?
}

reload() {
	ebegin "Reloading $RC_SVCNAME configuration"
	start-stop-daemon --signal HUP --pidfile $pidfile
	eend $?
}
