#!/bin/sh
#
# $MidnightBSD: trunk/dns/unbound/files/unbound.in 16442 2014-08-06 01:24:27Z laffer1 $
#
# unbound 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
#
# unbound_anchorflags can be used to allow you to pass a custom flags to
# unbound-anchor.  Examples include a custom resolv.conf (-f) or a custom
# root.hints (-r).  Useful for when /etc/resolv.conf only contains 127.0.0.1

# 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"}
unbound_anchorflags=${unbound_anchorflags:-""}

start_precmd()
{
	/usr/local/sbin/unbound-checkconf > /dev/null && \
	echo -n "Obtaining a trust anchor:" && \
	if [ "${unbound_anchorflags}T" = "T" ]; then \
		su -m unbound -c /usr/local/sbin/unbound-anchor; \
	else
		su -m unbound -c "/usr/local/sbin/unbound-anchor ${unbound_anchorflags}"; \
	fi &&
	echo .
	return 0
}

run_rc_command "$1"
