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
Adam Tkac 969b1c
### BEGIN INIT INFO
Adam Tkac 969b1c
# Provides: $named
Adam Tkac 969b1c
# Required-Start: $local_fs $network $syslog
Adam Tkac 969b1c
# Required-Stop: $local_fs $network $syslog
Adam Tkac fe4c11
# Default-Start:
Adam Tkac fe4c11
# Default-Stop: 0 1 2 3 4 5 6
Adam Tkac 969b1c
# Short-Description: start|stop|status|restart|try-restart|reload|force-reload DNS server
Adam Tkac 969b1c
# Description: control ISC BIND implementation of DNS server
Adam Tkac 969b1c
### END INIT INFO
Adam Tkac e51da3
cvsdist 2f7f4b
# Source function library.
cvsdist 2f7f4b
. /etc/rc.d/init.d/functions
cvsdist 2f7f4b
cvsdist 78e1f2
[ -r /etc/sysconfig/named ] && . /etc/sysconfig/named
cvsdist 2f7f4b
Adam Tkac e51da3
RETVAL=0
Adam Tkac fb5bf1
export KRB5_KTNAME=${KEYTAB_FILE:-/etc/named.keytab}
Adam Tkac e51da3
Adam Tkac 15c5cd
named='named'
Adam Tkac 15c5cd
if [ -x /usr/sbin/named-sdb ]; then
Adam Tkac 15c5cd
	named='named-sdb'
Adam Tkac 15c5cd
fi
Adam Tkac 15c5cd
Martin Stransky 28242b
# Don't kill named during clean-up
Adam Tkac 72f5cc
NAMED_SHUTDOWN_TIMEOUT=${NAMED_SHUTDOWN_TIMEOUT:-25}
Martin Stransky 2e702b
jvdias 0cd02a
if [ -n "$ROOTDIR" ]; then
jvdias 0cd02a
   ROOTDIR=`echo $ROOTDIR | sed 's#//*#/#g;s#/$##'`;
jvdias 0cd02a
   rdl=`/usr/bin/readlink $ROOTDIR`;
jvdias 0cd02a
   if [ -n "$rdl" ]; then
jvdias 0cd02a
      ROOTDIR="$rdl";
jvdias 0cd02a
   fi;
jvdias 0cd02a
fi
jvdias 38a73e
Adam Tkac e51da3
# Check if all what named needs running
Adam Tkac e51da3
start()
Adam Tkac e51da3
{
Adam Tkac e51da3
  # Source networking configuration.
Adam Tkac e51da3
  [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
jvdias 0cd02a
Adam Tkac e51da3
  # Check that networking is up
Adam Tkac e51da3
  [ "${NETWORKING}" = "no" ] && exit 1
jvdias 0cd02a
jvdias 420671
Adam Tkac 15c5cd
  [ -x /usr/sbin/"$named" ] || exit 5
Adam Tkac e51da3
Adam Tkac e51da3
  # Handle -c option
Adam Tkac e51da3
  previous_option='unspecified';
Adam Tkac e51da3
  for a in $OPTIONS; do
Adam Tkac e51da3
    if [ $previous_option = '-c' ]; then
Adam Tkac e51da3
      named_conf=$a;
jvdias bc0ace
    fi;
Adam Tkac e51da3
    previous_option=$a;
Adam Tkac e51da3
  done;
jvdias bc0ace
Adam Tkac e51da3
  named_conf=${named_conf:-/etc/named.conf};
Adam Tkac e51da3
Adam Tkac 038864
  if [ ! -r $ROOTDIR$named_conf ]; then
Adam Tkac e51da3
    echo 'Cannot find configuration file. You could create it by system-config-bind'
Adam Tkac e51da3
    exit 6;
Adam Tkac e51da3
  fi;
Adam Tkac e51da3
Adam Tkac e51da3
  # all pre-start is done, lets start named
Adam Tkac 2be0bc
  echo -n $"Starting named: "
Adam Tkac 15c5cd
  if [ -n "`/sbin/pidof -o %PPID "$named"`" ]; then
Adam Tkac 2be0bc
    echo -n $"named: already running"
Adam Tkac e51da3
    failure
Adam Tkac e51da3
    echo
Adam Tkac e51da3
    exit 1;
Adam Tkac e51da3
  fi;
Adam Tkac e51da3
Adam Tkac e51da3
  ckcf_options='-z'; # enable named-checkzone for each zone (9.3.1+) !
Adam Tkac e51da3
  if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
Adam Tkac e51da3
    OPTIONS="${OPTIONS} -t ${ROOTDIR}"
Adam Tkac e51da3
    ckcf_options="$ckcf_options -t ${ROOTDIR}";
Adam Tkac e51da3
    [ -s /etc/localtime ] && cp -fp /etc/localtime ${ROOTDIR}/etc/localtime;
Adam Tkac e51da3
    [ -d ${ROOTDIR}/proc ] || mkdir -p ${ROOTDIR}/proc;
Adam Tkac e51da3
    if ! egrep -q '^/proc[[:space:]]+'${ROOTDIR}'/proc' /proc/mounts; then
Adam Tkac e51da3
      mount --bind -n /proc ${ROOTDIR}/proc >/dev/null 2>&1;
Adam Tkac e51da3
    fi
Adam Tkac e51da3
    if [ ! -z $dbusEnabled ]; then
Adam Tkac e51da3
      if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${ROOTDIR}'/var/run/dbus' /proc/mounts; then
Adam Tkac e51da3
        mkdir -p ${ROOTDIR}/var/run/dbus
Adam Tkac e51da3
        [ -d /var/run/dbus ] || mkdir -p /var/run/dbus;
Adam Tkac e51da3
	mount --bind -n /var/run/dbus ${ROOTDIR}/var/run/dbus > /dev/null 2>&1;
Adam Tkac e51da3
      fi;
jvdias 6fcc99
    fi;
Adam Tkac e51da3
  fi
jvdias bc0ace
Adam Tkac e51da3
  RETVAL=0
Adam Tkac e51da3
  # check if configuration is correct
Adam Tkac e51da3
  if [ -x /usr/sbin/named-checkconf ] && [ -x /usr/sbin/named-checkzone ] && /usr/sbin/named-checkconf $ckcf_options ${named_conf} >/dev/null 2>&1; then
Adam Tkac 7fdb7f
Adam Tkac 15c5cd
    daemon /usr/sbin/"$named" -u named ${OPTIONS};
Adam Tkac e51da3
    RETVAL=$?
Adam Tkac e51da3
    if [ $RETVAL -eq 0 ]; then
Adam Tkac 15c5cd
      rm -f /var/run/{named,named-sdb}.pid;
Adam Tkac 15c5cd
      ln -s $ROOTDIR/var/run/named/"$named".pid /var/run/"$named".pid;
Adam Tkac e51da3
    fi;
Adam Tkac e51da3
Adam Tkac 15c5cd
    if [ -n "`/sbin/pidof -o %PPID "$named"`" ]; then
Adam Tkac e51da3
      # Verify that named actually started (JM 2006-10-04)
Adam Tkac 15c5cd
      if [ ! -e $ROOTDIR/var/run/named/"$named".pid ]; then
Adam Tkac e51da3
      # If there is not a file containing the PID of the now running named daemon then create it (JM 2006-10-04)
Adam Tkac 15c5cd
        echo `/sbin/pidof -o %PPID "$named"` > $ROOTDIR/var/run/named/"$named".pid;
Adam Tkac e51da3
      fi;
Adam Tkac e51da3
    fi;
Adam Tkac e51da3
  else
Adam Tkac e51da3
    named_err="`/usr/sbin/named-checkconf $ckcf_options $named_conf 2>&1`";	   
Adam Tkac e51da3
    echo
Adam Tkac e51da3
    echo "Error in named configuration:";
Adam Tkac e51da3
    echo "$named_err";
Adam Tkac e51da3
    failure
Adam Tkac e51da3
    echo
Adam Tkac e51da3
    [ -x /usr/bin/logger ] && echo "$named_err" | /usr/bin/logger -pdaemon.error -tnamed;
Adam Tkac e51da3
    exit 2;
Adam Tkac e51da3
  fi;
Adam Tkac 1c2862
  echo
Adam Tkac e51da3
  if [ $RETVAL -eq 0 ]; then
Adam Tkac e51da3
    touch /var/lock/subsys/named;
Adam Tkac e51da3
  else
Adam Tkac e51da3
    exit 7;
Adam Tkac e51da3
  fi
Adam Tkac e51da3
  return 0;
cvsdist 2f7f4b
}
Adam Tkac e51da3
cvsdist 2f7f4b
stop() {
Adam Tkac e51da3
  # Stop daemons.
Adam Tkac 2be0bc
  echo -n $"Stopping named: "
Adam Tkac e51da3
  [ -x /usr/sbin/rndc ] && /usr/sbin/rndc stop >/dev/null 2>&1;
Adam Tkac e51da3
  RETVAL=$?
Adam Tkac 72f5cc
  # was rndc successful?
Adam Tkac 72f5cc
  [ "$RETVAL" -eq 0 ] || killproc "$named" -TERM >/dev/null 2>&1
Adam Tkac 72f5cc
Adam Tkac 72f5cc
  timeout=0
Adam Tkac 72f5cc
  RETVAL=0
Adam Tkac dd1c37
  while /sbin/pidof -o %PPID "$named" >/dev/null; do
Adam Tkac 72f5cc
    if [ $timeout -ge $NAMED_SHUTDOWN_TIMEOUT ]; then
Adam Tkac 72f5cc
      RETVAL=1
Adam Tkac 72f5cc
      break
Adam Tkac 72f5cc
    else
Adam Tkac 72f5cc
      sleep 2 && echo -n "."
Adam Tkac 72f5cc
      timeout=$((timeout+2))
Adam Tkac 72f5cc
    fi;
Adam Tkac 72f5cc
  done
Adam Tkac e51da3
Adam Tkac e51da3
  # remove pid files
Adam Tkac e51da3
  if [ $RETVAL -eq 0 ]; then
Adam Tkac e51da3
    rm -f /var/lock/subsys/named
Adam Tkac 15c5cd
    rm -f /var/run/{named,named-sdb}.pid
Adam Tkac e51da3
  fi;
Adam Tkac e51da3
Adam Tkac e51da3
  # unmount mounted filesystems/directories
Adam Tkac e51da3
  if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
Adam Tkac e51da3
    if egrep -q '^/proc[[:space:]]+'${ROOTDIR}'/proc' /proc/mounts; then
Adam Tkac e51da3
      umount ${ROOTDIR}/proc >/dev/null 2>&1
Adam Tkac e51da3
    fi
Adam Tkac e51da3
    if [ ! -z $dbusEnabled ]; then
Adam Tkac e51da3
      if egrep -q '^/[^[:space:]]+[[:space:]]+'${ROOTDIR}'/var/run/dbus' /proc/mounts; then
Adam Tkac e51da3
        umount ${ROOTDIR}/var/run/dbus > /dev/null 2>&1
Adam Tkac e51da3
      fi;
Adam Tkac e51da3
    fi;
Adam Tkac e51da3
  fi;
Adam Tkac e51da3
  if [ $RETVAL -eq 0 ]; then
Adam Tkac e51da3
    success
Adam Tkac e51da3
  else
Adam Tkac e51da3
    failure
Adam Tkac e51da3
    RETVAL=1
Adam Tkac e51da3
  fi;
Adam Tkac e51da3
  echo
Adam Tkac e51da3
  return $RETVAL
cvsdist 2f7f4b
}
Adam Tkac e51da3
Adam Tkac e51da3
cvsdist 2f7f4b
rhstatus() {
Adam Tkac e51da3
  [ -x /usr/sbin/rndc ] && /usr/sbin/rndc status;
Adam Tkac 15c5cd
  status /usr/sbin/"$named";
Adam Tkac e51da3
  return $?
cvsdist 2f7f4b
}	
cvsdist 2f7f4b
restart() {
cvsdist 2f7f4b
	stop
cvsdist 2f7f4b
	start
cvsdist 2f7f4b
}	
cvsdist 2f7f4b
reload() {
Adam Tkac 15c5cd
        echo -n $"Reloading "$named": "
Adam Tkac 15c5cd
	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
Adam Tkac 15c5cd
	[ "$RETVAL" -eq 0 ] && success $"$named reload" || failure $"$named reload"
cvsdist 78e1f2
        echo
Adam Tkac e51da3
	return $RETVAL
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)
Adam Tkac e51da3
		rhstatus;
Adam Tkac e51da3
		RETVAL=$?
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	restart)
cvsdist 2f7f4b
		restart
cvsdist 2f7f4b
		;;
cvsdist 2f7f4b
	condrestart)
Adam Tkac 969b1c
		echo "condrestart option is obsolete. Use try-restart instead"
cvsdist 31bdca
		if [ -e /var/lock/subsys/named ]; then restart; fi
cvsdist 2f7f4b
		;;
Adam Tkac 969b1c
	try-restart)
Adam Tkac 969b1c
		if [ -e /var/lock/subsys/named ]; then restart; fi
Adam Tkac 969b1c
                ;;
cvsdist 2f7f4b
	reload)
cvsdist 2f7f4b
		reload
cvsdist 2f7f4b
		;;
Adam Tkac 969b1c
	force-reload)
Adam Tkac 969b1c
		if ! reload; then restart; fi
Adam Tkac 969b1c
		;;
cvsdist 2f7f4b
	*)
Adam Tkac 969b1c
        	echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
Adam Tkac e51da3
		exit 3
cvsdist 2f7f4b
esac
cvsdist 2f7f4b
Adam Tkac e51da3
exit $RETVAL
cvsdist 2f7f4b