#!/bin/bash
#
# named8          This shell script takes care of starting and stopping
#                 named8 (BIND8 DNS server).
#
# chkconfig: 345 55 45
# description: named (BIND8) is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /etc/sysconfig/named8 ] && . /etc/sysconfig/named8

[ -f /usr/sbin/named8 ] || exit 0

[ -f ${ROOTDIR}/etc/named8.conf ] || exit 0

RETVAL=0

start() {
        # Start daemons.
	if [ -n "`/sbin/pidof named8`" ]; then
		echo -n "named8: already running"
		return 1
	fi
        echo -n "Starting named8: "
	if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
		OPTIONS="${OPTIONS} -t ${ROOTDIR}"
	fi
        # Start daemons.
        daemon named8 -u named8 ${OPTIONS}
	RETVAL=$?
 	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named8
	echo
	return $RETVAL
}
stop() {
        # Stop daemons.
        echo -n "Shutting down named8: "
        kill -9 `/sbin/pidof named8`
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named8
        echo
	return $RETVAL
}
rhstatus() {
	/usr/sbin/ndc8 status
	return $?
}	
restart() {
	stop
	start
}	
reload() {
	/usr/sbin/ndc8 reload
	return $?
}
probe() {
	# named knows how to reload intelligently; we don't want linuxconf
	# to offer to restart every time
	/usr/sbin/ndc8 reload >/dev/null 2>&1 || echo start
	return $?
}  

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		rhstatus
		;;
	restart)
		restart
		;;
	condrestart)
		[ -f /var/lock/subsys/named8 ] && restart || :
		;;
	reload)
		reload
		;;
	probe)
		probe
		;;
	*)
        	echo "Usage: named8 {start|stop|status|restart|condrestart|reload|probe}"
		exit 1
esac

exit $?
