#!/bin/sh
#
# $FreeBSD: dns/unbound/files/unbound.in 303943 2012-09-09 01:08:36Z sem $
#
# unbound freebsd startup rc.d script, modified from the named script.
# uses the default unbound installation path and pidfile location.
# copy this to /etc/rc.d/unbound
# and put unbound_enable="YES" into rc.conf
#

# PROVIDE: unbound
# REQUIRE: SERVERS cleanvar
# KEYWORD: shutdown

. /etc/rc.subr

name="unbound"
rcvar=unbound_enable

command="/usr/local/sbin/unbound"
extra_commands="reload"
start_precmd="start_precmd"
reload_precmd="/usr/local/sbin/unbound-checkconf >/dev/null" 

load_rc_config $name

pidfile=${unbound_pidfile:-"/usr/local/etc/unbound/unbound.pid"}
unbound_enable=${unbound_enable:-"NO"}

start_precmd()
{
	/usr/local/sbin/unbound-checkconf && \
	echo -n "Obtaining a trust anchor:" && \
	su -m unbound -c /usr/local/sbin/unbound-anchor && \
	echo .
}

run_rc_command "$1"
