#!/bin/bash # # named This shell script takes care of starting and stopping # named (BIND DNS server). # # chkconfig: 235 23 77 # description: named (BIND) is a Domain Name Server (DNS) \ # that is used to resolve host names to IP addresses. # probe: true # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network RETVAL=0 prog="named" # Check that networking is up. [ "${NETWORKING}" = "no" ] && exit 1 [ -r /etc/sysconfig/named ] && . /etc/sysconfig/named [ -x /usr/local/sbin/named ] || exit 1 [ -r ${ROOTDIR}/etc/named.conf ] || exit 1 PATH=$PATH:/usr/local/sbin start() { # Start daemons. echo -n $"Starting $prog: " if [ -n "`/sbin/pidof named`" ]; then echo -n $"$prog: already running" failure echo return 1 fi ckcf_options='-z'; if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then OPTIONS="${OPTIONS} -t ${ROOTDIR}" ckcf_options="$ckcf_options -t ${ROOTDIR}"; fi conf_ok=0; if [ -x /usr/local/sbin/named-checkconf ] && \ named-checkconf $ckcf_options >/dev/null 2>&1; then conf_ok=1; else RETVAL=$?; fi if [ $conf_ok -eq 1 ]; then daemon named -u named ${OPTIONS}; RETVAL=$?; if [ $RETVAL -eq 0 ]; then ln -s $ROOTDIR/var/named/named.pid /var/run/named.pid; fi; else named_err="`named-checkconf $ckcf_options 2>&1`"; echo echo $"Error in named configuration"':'; echo "$named_err"; failure echo if [ -x /usr/bin/logger ]; then echo "$named_err" | /usr/bin/logger -pdaemon.error -tnamed fi; return $RETVAL; fi; [ $RETVAL -eq 0 ] && touch /var/lock/subsys/named echo return $RETVAL } stop() { # Stop daemons. echo -n $"Stopping $prog: " rndc stop >/dev/null 2>&1 || killproc named >/dev/null 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/named rm -f /var/run/named.pid elif pidof named >/dev/null; then rndc stop >/dev/null 2>&1 || killproc named >/dev/null 2>&1 RETVAL=$? if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/named rm -f /var/run/named.pid fi; fi; if [ $RETVAL -eq 0 ]; then success else failure fi; echo return $RETVAL } rhstatus() { rndc status return $? } restart() { stop sleep 2 start } reload() { echo -n $"Reloading $prog: " p=`/sbin/pidof -o %PPID named` RETVAL=$? if [ "$RETVAL" -eq 0 ]; then rndc reload >/dev/null 2>&1 || /usr/bin/kill -HUP $p; RETVAL=$? fi [ "$RETVAL" -eq 0 ] && success $"$prog reload" || failure $"$prog reload" echo return $? } probe() { rndc reload >/dev/null 2>&1 || echo start return $? } checkconfig() { ckcf_options='-z'; if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then OPTIONS="${OPTIONS} -t ${ROOTDIR}" ckcf_options="$ckcf_options -t ${ROOTDIR}"; fi; if [ -x /usr/local/sbin/named-checkconf ] && \ named-checkconf $ckcf_options ; then return 0; else return 1; fi } case "$1" in start) start ;; stop) stop ;; status) rhstatus ;; restart) restart ;; condrestart) if [ -e /var/lock/subsys/named ]; then restart; fi ;; reload) reload ;; probe) probe ;; checkconfig) checkconfig ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|probe}" exit 1 esac exit $?