cvsdist 2f7f4b
#!/bin/bash
cvsdist 2f7f4b
#
cvsdist 2f7f4b
# named           This shell script takes care of starting and stopping
cvsdist 2f7f4b
#                 named (BIND DNS server).
cvsdist 2f7f4b
#
jvdias 3c357d
# chkconfig: - 13 87
cvsdist 2f7f4b
# description: named (BIND) is a Domain Name Server (DNS) \
cvsdist 2f7f4b
# that is used to resolve host names to IP addresses.
cvsdist 2f7f4b
# probe: true
cvsdist 2f7f4b
cvsdist 2f7f4b
# Source function library.
cvsdist 2f7f4b
. /etc/rc.d/init.d/functions
cvsdist 2f7f4b
cvsdist 2f7f4b
# Source networking configuration.
cvsdist 4f506d
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
cvsdist 2f7f4b
cvsdist 2f7f4b
# Check that networking is up.
jvdias e51c8f
[ "${NETWORKING}" = "no" ] && exit 1
cvsdist aed712
cvsdist 78e1f2
[ -r /etc/sysconfig/named ] && . /etc/sysconfig/named
cvsdist 2f7f4b
jvdias e9f83d
RETVAL=0
jvdias e9f83d
named='named'
jvdias e9f83d
if [[ "$ENABLE_SDB" = [yY1]* ]] && [ -x /usr/sbin/named_sdb ]; then
jvdias e9f83d
    named='named_sdb';
jvdias e9f83d
fi;
jvdias e9f83d
prog=$named
jvdias e9f83d
jvdias e9f83d
[ -x /usr/sbin/$named ] || exit 1
cvsdist 2f7f4b
jvdias 31ab24
named_conf=${ROOTDIR}/etc/named.conf
jvdias 31ab24
c_opt=0
jvdias 31ab24
if [[ "${OPTIONS}" = *-c* ]]; then
jvdias 31ab24
   named_conf=`echo ${OPTIONS} | sed 's/^.*-c[\ \	]//;s/[\ \	].*$//'`;
jvdias 31ab24
   c_opt=1;
jvdias 31ab24
fi;
jvdias 31ab24
jvdias 31ab24
[ -r ${named_conf} ] || exit 1
jvdias 31ab24
jvdias 31ab24
if [ ${c_opt} -eq 0 ]; then
jvdias 31ab24
   named_conf='';
jvdias 31ab24
fi;
cvsdist 2f7f4b
jvdias 420671
[ -n "$ROOTDIR" ] && ROOTDIR=`echo $ROOTDIR | sed 's#//*#/#g;s#/$##'`
jvdias 420671
cvsdist 2f7f4b
start() {
cvsdist 2f7f4b
        # Start daemons.
jvdias e9f83d
        echo -n $"Starting $named: "
jvdias e9f83d
	if [ -n "`/sbin/pidof -o %PPID $named`" ]; then
jvdias e9f83d
		echo -n $"$named: already running"
jvdias 6e144c
		failure
jvdias 6e144c
		echo
cvsdist 0a52a5
		return 1
cvsdist 0a52a5
	fi
jvdias b7b41a
	ckcf_options='-z'; # enable named-checkzone for each zone (9.3.1+) !
cvsdist aed712
	if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
cvsdist aed712
		OPTIONS="${OPTIONS} -t ${ROOTDIR}"
jvdias b7b41a
		ckcf_options="$ckcf_options -t ${ROOTDIR}";
jvdias d3f558
		if [ -s /etc/localtime ]; then
jvdias d3f558
		    cp -fp /etc/localtime ${ROOTDIR}/etc/localtime
jvdias d3f558
		fi;
jvdias 1abbaa
		if [ ! -d ${ROOTDIR}/proc ]; then
jvdias 1abbaa
		    mkdir -p ${ROOTDIR}/proc
jvdias 1abbaa
		fi
jvdias 1abbaa
		if ! egrep -q "${ROOTDIR}/proc proc" /etc/mtab; then
jvdias 1ccce3
		    mount -tproc none ${ROOTDIR}/proc >/dev/null 2>&1 
jvdias 1abbaa
		fi
cvsdist aed712
	fi
jvdias 18d1e1
	no_write_master_zones=0
jvdias 23b1ff
	if [ -e /etc/selinux/config ]; then
jvdias 23b1ff
           .  /etc/selinux/config
jvdias b7b41a
           if [[ ( "$SELINUX" != 'disabled') && ("$SELINUXTYPE" != "") && (-d /etc/selinux/${SELINUXTYPE}) && (-e /etc/selinux/${SELINUXTYPE}/booleans || (-e /etc/selinux/${SELINUXTYPE}/booleans.local)) ]]; then
jvdias b7b41a
	       if [ -e /etc/selinux/${SELINUXTYPE}/booleans.local ]; then
jvdias b7b41a
		   . /etc/selinux/${SELINUXTYPE}/booleans.local;
jvdias b7b41a
	       else
jvdias b7b41a
		   . /etc/selinux/${SELINUXTYPE}/booleans;
jvdias b7b41a
               fi;
jvdias 2dbdf5
	       if echo "$named_write_master_zones" | /bin/egrep -q '^[0-9]+$'; then
jvdias 2dbdf5
		   if [ "$named_write_master_zones" -eq 1 ] ; then
jvdias 2dbdf5
		       /bin/chown -f --from=root:named named:named $ROOTDIR/var/named
jvdias 2dbdf5
		   elif [ "$named_write_master_zones" -eq 0 ] ; then
jvdias 2dbdf5
		       /bin/chown -f --from=named:named root:named $ROOTDIR/var/named
jvdias 2dbdf5
		   fi;
jvdias 2dbdf5
               fi;
jvdias 18d1e1
	   else
jvdias 18d1e1
	       no_write_master_zones=1
jvdias 23b1ff
	   fi;
jvdias 18d1e1
	else
jvdias 18d1e1
	    no_write_master_zones=1
jvdias 23b1ff
        fi;
jvdias 18d1e1
	if [ "$no_write_master_zones" -eq 1 ]; then
jvdias 18d1e1
	    if [[ "$ENABLE_ZONE_WRITE" =  [yY1]* ]]; then
jvdias 18d1e1
		/bin/chown -f --from=root:named named:named $ROOTDIR/var/named
jvdias 18d1e1
	    elif [[ "$ENABLE_ZONE_WRITE" =  [nN0]* ]]; then	        
jvdias 18d1e1
		/bin/chown -f --from=named:named root:named $ROOTDIR/var/named
jvdias 18d1e1
	    fi;
jvdias 18d1e1
	fi
cvsdist 49d83b
        conf_ok=0;
jvdias 31ab24
	if [ -x /usr/sbin/named-checkconf ] && [ -x /usr/sbin/named-checkzone ] && /usr/sbin/named-checkconf $ckcf_options ${named_conf} >/dev/null 2>&1; then
cvsdist 49d83b
           conf_ok=1;
cvsdist 49d83b
        else
cvsdist 49d83b
	   RETVAL=$?;
cvsdist 49d83b
	fi
cvsdist 49d83b
	if [ $conf_ok -eq 1 ]; then	   
jvdias e9f83d
	   daemon /usr/sbin/$named -u named ${OPTIONS};
cvsdist 49d83b
	   RETVAL=$?;
jvdias b7b41a
	   if [ $RETVAL -eq 0 ]; then
jvdias aad908
	       rm -f /var/run/named.pid
jvdias e9f83d
	       rm -f /var/run/named_sdb.pid 2>/dev/null
jvdias b7b41a
	       ln -s $ROOTDIR/var/run/named/named.pid /var/run/named.pid;
jvdias e9f83d
	       if [ "$named" = "named_sdb" ]; then
jvdias e9f83d
		   ln -s $ROOTDIR/var/run/named/named.pid /var/run/named_sdb.pid;
jvdias e9f83d
	       fi;
cvsdist 668aac
	   fi;
jvdias b7b41a
	else
jvdias 31ab24
	   named_err="`/usr/sbin/named-checkconf $ckcf_options $named_conf 2>&1`";	   
jvdias b7b41a
	   echo
jvdias b7b41a
	   echo $"Error in named configuration"':';
jvdias b7b41a
	   echo "$named_err";
jvdias b7b41a
	   failure
jvdias b7b41a
	   echo
jvdias b7b41a
	   if [ -x /usr/bin/logger ]; then
jvdias b7b41a
	       echo "$named_err" | /usr/bin/logger -pdaemon.error -tnamed 
jvdias b7b41a
           fi;
cvsdist 49d83b
           return $RETVAL;
cvsdist 49d83b
        fi;
cvsdist 78e1f2
 	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named 
cvsdist 4f506d
        echo
cvsdist 2f7f4b
	return $RETVAL
cvsdist 2f7f4b
}
cvsdist 2f7f4b
stop() {
cvsdist 2f7f4b
        # Stop daemons.
jvdias e9f83d
        echo -n $"Stopping $named: "
jvdias aad908
	/usr/sbin/rndc stop >/dev/null 2>&1 
cvsdist 2f7f4b
	RETVAL=$?
jvdias b7b41a
	if [ $RETVAL -eq 0 ]; then
jvdias b7b41a
	    rm -f /var/lock/subsys/named
jvdias b7b41a
	    rm -f /var/run/named.pid	    
jvdias e9f83d
	    rm -f /var/run/named_sdb.pid 2>/dev/null	    
jvdias e9f83d
	elif /sbin/pidof -o %PPID $named >/dev/null; then
jvdias e9f83d
	    killproc $named -TERM >/dev/null 2>&1
jvdias b7b41a
	    RETVAL=$?
jvdias b7b41a
	    if [ $RETVAL -eq 0 ]; then
jvdias b7b41a
		rm -f /var/lock/subsys/named
jvdias b7b41a
		rm -f /var/run/named.pid
jvdias e9f83d
		rm -f /var/run/named_sdb.pid 2>/dev/null	    
jvdias b7b41a
	    fi;
jvdias b7b41a
	fi;
jvdias b7b41a
	if [ $RETVAL -eq 0 ]; then
jvdias b7b41a
	    success
jvdias b7b41a
	else
jvdias b7b41a
	    failure
jvdias b7b41a
        fi;
jvdias b7b41a
	echo
cvsdist 2f7f4b
	return $RETVAL
cvsdist 2f7f4b
}
cvsdist 2f7f4b
rhstatus() {
cvsdist 366442
	/usr/sbin/rndc status
cvsdist 366442
	return $?
cvsdist 2f7f4b
}	
cvsdist 2f7f4b
restart() {
cvsdist 2f7f4b
	stop
cvsdist 78e1f2
# wait a couple of seconds for the named to finish closing down
cvsdist 78e1f2
	sleep 2
cvsdist 2f7f4b
	start
cvsdist 2f7f4b
}	
cvsdist 2f7f4b
reload() {
jvdias e9f83d
        echo -n $"Reloading $named: "
jvdias e9f83d
	p=`/sbin/pidof -o %PPID $named`	
cvsdist d69ee3
	RETVAL=$?
cvsdist d69ee3
	if [ "$RETVAL" -eq 0 ]; then 
jvdias aad908
	    /usr/sbin/rndc reload >/dev/null 2>&1 || /bin/kill -HUP $p;
cvsdist d69ee3
	    RETVAL=$?
cvsdist d69ee3
        fi
jvdias e9f83d
	[ "$RETVAL" -eq 0 ] && success $"$named reload" || failure $"$named reload"
cvsdist 78e1f2
        echo
cvsdist 2f7f4b
	return $?
cvsdist 2f7f4b
}
cvsdist 2f7f4b
probe() {
cvsdist 2f7f4b
	# named knows how to reload intelligently; we don't want linuxconf
cvsdist 2f7f4b
	# to offer to restart every time
cvsdist aed712
	/usr/sbin/rndc reload >/dev/null 2>&1 || echo start
cvsdist 2f7f4b
	return $?
jvdias b7b41a
}
jvdias b7b41a
checkconfig() {
jvdias b7b41a
        ckcf_options='-z'; # enable named-checkzone for each zone (9.3.1+) !
jvdias b7b41a
	if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
jvdias b7b41a
		OPTIONS="${OPTIONS} -t ${ROOTDIR}"
jvdias b7b41a
		ckcf_options="$ckcf_options -t ${ROOTDIR}";  
jvdias b7b41a
	fi;
jvdias 31ab24
	if [ -x /usr/sbin/named-checkconf ] && [ -x /usr/sbin/named-checkzone ] && /usr/sbin/named-checkconf $ckcf_options ${named_conf} | cat ; then
jvdias b7b41a
	    return 0;
jvdias b7b41a
	else
jvdias b7b41a
	    return 1;
jvdias b7b41a
	fi
jvdias b7b41a
}
cvsdist 2f7f4b
cvsdist 2f7f4b
# See how we were called.
cvsdist 2f7f4b
case "$1" in
cvsdist 2f7f4b
	start)
cvsdist 2f7f4b
		start
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	stop)
cvsdist 2f7f4b
		stop
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	status)
cvsdist 2f7f4b
		rhstatus
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	restart)
cvsdist 2f7f4b
		restart
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	condrestart)
cvsdist 31bdca
		if [ -e /var/lock/subsys/named ]; then restart; fi
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	reload)
cvsdist 2f7f4b
		reload
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	probe)
cvsdist 2f7f4b
		probe
cvsdist 2f7f4b
		;;
jvdias e9f83d
        checkconfig|configtest|check|test)
jvdias b7b41a
	        checkconfig
jvdias b7b41a
		;;
cvsdist 2f7f4b
	*)
cvsdist aed712
        	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|probe}"
cvsdist 2f7f4b
		exit 1
cvsdist 2f7f4b
esac
cvsdist 2f7f4b
cvsdist 2f7f4b
exit $?
cvsdist 2f7f4b