#!/bin/sh

# PROVIDE: nginx_agent
# REQUIRE: NETWORKING nginx
# KEYWORD: shutdown

. /etc/rc.subr

name="nginx_agent"
rcvar="nginx_agent_enable"

load_rc_config ${name}

: ${nginx_agent_enable:="NO"}
: ${nginx_agent_user:="root"}
: ${nginx_agent_flags:=""}
: ${nginx_agent_args:="--lib-dir /var/db/nginx-agent --allowed-directories /usr/local/etc/nginx,/usr/share/nginx/modules,/var/run/nginx,/var/log/nginx"}

command="/usr/sbin/daemon"
procname="%%PREFIX%%/sbin/nginx-agent"
pidfile="/var/run/${name}.pid"

start_precmd="${name}_prestart"

nginx_agent_prestart()
{
	install -d -m 0755 /var/db/nginx-agent
	install -d -m 0755 /var/log/nginx-agent
	install -d -m 0755 /var/run/nginx
}

command_args="-c -f -p ${pidfile} -u ${nginx_agent_user} -- ${procname} ${nginx_agent_args} ${nginx_agent_flags}"

run_rc_command "$1"
