Blob Blame History Raw
#!/bin/bash
#
# nsd           Starts the NSD Name Server Daemon
#
# chkconfig:    - 23 87
# description:  NSD is a complete implementation of an authoritative \
#               DNS name server.
#
### BEGIN INIT INFO
# Provides: nsd
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $network $syslog
# Default-Start:
# Default-Stop: 0 1 2 3 4 5 6
# Short-Description: The NSD Name Server Daemon
# Description: NSD is a complete implementation of an authoritative
#              DNS name server.
### END INIT INFO

# Init script default settings
NSD_CONF="/etc/nsd/nsd.conf"
NSD_PROG="/usr/sbin/nsd"
NSD_PIDFILE="/var/run/nsd/nsd.pid"
NSD_XFRDFILE="/var/lib/nsd/xfrd.state"
NSDC_PROG="/usr/sbin/nsdc"
NSD_USER="nsd"
NSD_PIDDIR="$(dirname ${NSD_PIDFILE})"
NSD_EXTRA_OPTS=""

# Source function library.
. /etc/rc.d/init.d/functions

[ -r /etc/sysconfig/nsd ] && . /etc/sysconfig/nsd

# Check that networking is configured.
[ "${NETWORKING}" = "no" ] && exit 0

start() {
    # Source networking configuration.
    [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network

    # Check that networking is up
    [ "${NETWORKING}" = "no" ] && exit 1

    # Sanity checks.
    [ -f ${NSD_CONF} ] || exit 5
    [ -x ${NSD_PROG} ] || exit 5
    # /var/run could (and should) be tmpfs
    [ -d ${NSD_PIDDIR} ] || {
	mkdir -p ${NSD_PIDDIR}
	chown ${NSD_USER}: ${NSD_PIDDIR}
    }

    echo -n $"Starting nsd:"
    ${NSDC_PROG} -c ${NSD_CONF} rebuild >/dev/null 2>&1
    daemon \
	--pidfile=${NSD_PIDFILE} \
	${NSD_PROG} -c ${NSD_CONF} \
	${NSD_EXTRA_OPTS}
    RETVAL=$?
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/nsd
    echo
}

stop() {
    echo -n $"Stopping nsd: "
    # save state to zonefiles
    ${NSDC_PROG} -c ${NSD_CONF} patch > /dev/null 2>&1
    ${NSDC_PROG} -c ${NSD_CONF} stop
    RETVAL=$?
    # was nsdc successful?
    if [ "$RETVAL" -gt 0 ]; then
	killproc -p ${NSD_PIDFILE} ${NSD_PROG}
    fi
    if [ $RETVAL -eq 0 ] ; then
	rm -f ${NSD_PIDFILE}
	rm -f /var/lock/subsys/nsd
        # ensure notifies are sent at startup
	rm -f ${NSD_XFRDFILE}
	success
    else
	failure
    fi
    echo
    return $RETVAL
}

restart() {
    stop
    start
}

RETVAL=0

# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
    condrestart|try-restart)
        [ -f /var/lock/subsys/nsd ] && restart || :
	;;
    status)
	status -p ${NSD_PIDFILE} ${NSD_PROG}
	;;
    reload)
	echo -n $"Rebuilding zonefiles:"
	${NSDC_PROG} -c ${NSD_CONF} rebuild >/dev/null 2>&1
        RETVAL=$?
        if [ $RETVAL -eq 0 ] ; then
            success
        else
            failure
        fi
	echo 
	echo -n $"Reloading nsd:"
	${NSDC_PROG} -c ${NSD_CONF} reload
        RETVAL=$?
        if [ $RETVAL -eq 0 ] ; then
            success
        else
            failure
        fi
	echo
	;;
    stats|rebuild|running|update|notify)
	${NSDC_PROG} -c ${NSD_CONF} $1 
	;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|stats|notify|reload|rebuild|running|update}"
	exit 2
esac

exit $RETVAL
#