#!/bin/sh
#
# $FreeBSD: dns/credns/files/credns.in 302454 2012-08-12 21:00:32Z scheidell $
#
# PROVIDE: credns
# REQUIRE: DAEMON
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following line to /etc/rc.conf to enable credns
#
# credns_enable="YES"
#

. /etc/rc.subr

name=credns
rcvar=credns_enable

required_files=/usr/local/etc/credns/credns.conf

command=/usr/local/sbin/crednsc
command_args="start"
pidfile=`/usr/local/sbin/credns-checkconf -o pidfile /usr/local/etc/credns/credns.conf`
procname=/usr/local/sbin/${name}

load_rc_config ${name}

credns_enable=${credns_enable-"NO"}

extra_commands="reload"
start_precmd="credns_precmd"
reload_cmd="credns_reload"
stop_cmd="credns_stop"

credns_precmd()
{
	db=`/usr/local/sbin/credns-checkconf -o database /usr/local/etc/credns/credns.conf`
	if [ ! -f "$db" ]; then
		${command} rebuild
	fi
}

credns_reload()
{
	${command} rebuild && ${command} reload
}

credns_stop()
{
	echo "Merging credns zone transfer changes to zone files."
	${command} patch

	echo "Stopping ${name}."
	${command} stop
}

run_rc_command "$1"

