#!/bin/sh
#
# $MidnightBSD: mports/dns/unbound/files/unbound.in,v 1.3 2013/06/12 03:04:47 laffer1 Exp $
#
# 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"
