#!/sbin/sh
#
# named $Revision: 1.2.212.1 $ $Date: 95/10/12 19:33:50 $
#
#           Copyright (C) 1993, 1994 Hewlett-Packard Company
#
# NOTE:    This script is not configurable!  Any changes made to this
#          script will be overwritten when you upgrade to the next
#          release of HP-UX.
#
#
# NOTE: The /etc/named.boot file is a host specific file that resides in a
#       private root directory.  In a diskless cluster, this file should be 
#       created on the server node so that named is started only on the 
#       server.  There are no restrictions against starting named on a client,
#       but this is not an optimal situation and is discouraged. A different
#       boot file path can be specified using the NAMED_ARGS variable in 
#       /etc/rc.config (see named(1m) for argument syntax).
#

PATH=/sbin:/usr/sbin:/usr/bin
export PATH

rval=0
set_return() {
        x=$?
        if [ $x -ne 0 ]; then
                echo "EXIT CODE: $x"
                rval=1  # always 1 so that 2 can be used for other reasons
        fi
}


case $1 in
start_msg)
	echo "Start name server daemon"
	;;

stop_msg)
	echo "Stopping name server daemon"
	;;

'start')
	if [ -f /etc/rc.config ] ; then
		. /etc/rc.config
		else
		echo "ERROR: /etc/rc.config defaults file MISSING"
	fi

	if [ "$NAMED" -eq 1 -a -x /usr/sbin/named ]; then
		/usr/sbin/named $NAMED_ARGS && echo "named  \c"
		set_return
		if [ $rval -ne 0 ]; then
			echo "Error in starting named. Recommend checking the"
			echo "syslog file (usually /var/adm/syslog/syslog.log)"
			echo "for possible reasons."
		fi
	else
		if [ ! -x /usr/sbin/named ]; then
		    echo "/usr/sbin/named is not executable"
		    rval=1
		else
		    rval=2
		fi
	fi
	;;

'stop')
	if [ -f /etc/rc.config ] ; then
		. /etc/rc.config
		else
		echo "ERROR: /etc/rc.config defaults file MISSING"
	fi

	#
	# Determine PID of process(es) to stop
	#
	if [ "$NAMED" -ne 1 ]; then
	    rval=2
	else
	    if [ -r /var/run/named.pid ]; then
		if  kill `cat /var/run/named.pid` ; then
			rm /var/run/named.pid
			echo "named stopped"
		else
			rval=1
			echo "Unable to stop named"
		fi
	    else
		rval=1
		echo "Unable to stop named (no pid file)"
	    fi
	fi
	;;

*)
	echo "usage: $0 {start|stop}"
	rval=1
	;;
esac

exit $rval
