fea33a3
#!/bin/bash
fea33a3
#
fea33a3
# nsd:         Starts the NSD Name Server Daemon
fea33a3
#
c84fed8
# chkconfig: - 13 87
fea33a3
# description:  NSD is a complete implementation of an authoritative \
fea33a3
#               DNS name server. 
fea33a3
# processname: /usr/sbin/nsd
16359b2
# config: /etc/nsd/nsd.conf
fea33a3
#
fea33a3
### BEGIN INIT INFO
fea33a3
# Provides: nsd
c84fed8
# Required-Start: $local_fs $network $syslog
c84fed8
# Required-Stop: $local_fs $network $syslog
a25e271
# Default-Stop: 0 11 89
c84fed8
# Short-Description: start|stop|status|restart|try-restart|reload|force-reload DNS server
c84fed8
# Description: control NSD implementation of DNS server
fea33a3
### END INIT INFO
fea33a3
a25e271
# Init script default settings
a25e271
NSD_CONF="/etc/nsd/nsd.conf"
a85cd70
NSD_DB="/var/lib/nsd/nsd.db"
a25e271
NSD_PROG="/usr/sbin/nsd"
a25e271
NSD_PIDFILE="/var/run/nsd/nsd.pid"
a25e271
NSD_XFRDFILE="/var/lib/nsd/xfrd.state"
a25e271
NSDC_PROG="/usr/sbin/nsdc"
fea33a3
fea33a3
# Source function library.
c84fed8
. /etc/rc.d/init.d/functions
fea33a3
c84fed8
[ -r /etc/sysconfig/nsd ] && . /etc/sysconfig/nsd
fea33a3
fea33a3
# Check that networking is configured.
43f3812
[ "${NETWORKING}" = "no" ] && exit 0
fea33a3
fea33a3
start() {
c84fed8
  # Source networking configuration.
c84fed8
  [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
c84fed8
c84fed8
  # Check that networking is up
c84fed8
  [ "${NETWORKING}" = "no" ] && exit 1
c84fed8
c84fed8
  # Sanity checks.
a25e271
  [ -f $NSD_CONF ] || exit 5
a25e271
  [ -x $NSD_PROG ] || exit 5
c84fed8
44eb252
  [ -G /var/run/nsdhm ] || chown nsd.nsd /var/run/nsdhm
44eb252
  [ -G /var/lib/nsdhm ] || chown nsd.nsd /var/lib/nsdhm
44eb252
a25e271
  echo -n $"Starting nsd:"
6d6ff76
  $NSDC_PROG -c $NSD_CONF rebuild >/dev/null 2>&1
a25e271
  $NSD_PROG -c $NSD_CONF $OTHER_NSD_OPTS
a25e271
  RETVAL=$?
a25e271
  echo
c84fed8
        if [ $RETVAL -eq 0 ]; then
a8a4595
           touch /var/lock/subsys/nsd;
c84fed8
        else
c84fed8
           exit 7;
c84fed8
        fi
c84fed8
  return 0;
fea33a3
}
fea33a3
fea33a3
stop() {
a25e271
  echo -n $"Stopping nsd: "
a25e271
  # save state to zonefiles
6d6ff76
  $NSDC_PROG -c $NSD_CONF patch > /dev/null 2>&1
a25e271
  $NSDC_PROG -c $NSD_CONF stop
a25e271
  RETVAL=$?
a25e271
  # was nsdc successful?
a25e271
  [ "$RETVAL" -eq 0 ] || killproc $NSD_PROG -TERM >/dev/null 2>&1
a25e271
  if [ $RETVAL -eq 0 ] ; then
a25e271
     rm -f $NSD_PIDFILE
a25e271
     rm -f /var/lock/subsys/nsd
a25e271
     # ensure notifies are sent at startup
a25e271
     rm -f $NSD_XFRDFILE
a25e271
  fi
a25e271
  echo
a25e271
  return $RETVAL
fea33a3
}
fea33a3
fea33a3
restart() {
fea33a3
	stop
fea33a3
	start
fea33a3
}
fea33a3
fea33a3
RETVAL=0
fea33a3
fea33a3
# See how we were called.
fea33a3
case "$1" in
fea33a3
  start)
fea33a3
	start
fea33a3
	;;
fea33a3
  stop)
fea33a3
	stop
fea33a3
	;;
fea33a3
  restart)
fea33a3
	restart
fea33a3
	;;
fea33a3
  condrestart)
fea33a3
        [ -f /var/lock/subsys/nsd ] && restart || :
fea33a3
	;;
fea33a3
  status)
a25e271
	$NSDC_PROG -c $NSD_CONF running
fea33a3
	;;
fea33a3
  stats|reload|rebuild|running|update|notify)
a25e271
	$NSDC_PROG -c $NSD_CONF $1 
fea33a3
	;;
fea33a3
  *)
fea33a3
	echo $"Usage: $0 {start|stop|status|restart|condrestart|stats|notify|reload|rebuild|running|update}"
fea33a3
	exit 1
fea33a3
esac
fea33a3
a25e271
exit $?