be3d56b
#!/bin/bash
be3d56b
#
be3d56b
# nsd           Starts the NSD Name Server Daemon
be3d56b
#
be3d56b
# chkconfig:    - 23 87
be3d56b
# description:  NSD is a complete implementation of an authoritative \
be3d56b
#               DNS name server.
be3d56b
#
be3d56b
### BEGIN INIT INFO
be3d56b
# Provides: nsd
be3d56b
# Required-Start: $local_fs $network $syslog
be3d56b
# Required-Stop: $local_fs $network $syslog
be3d56b
# Default-Start:
be3d56b
# Default-Stop: 0 1 2 3 4 5 6
be3d56b
# Short-Description: The NSD Name Server Daemon
be3d56b
# Description: NSD is a complete implementation of an authoritative
be3d56b
#              DNS name server.
be3d56b
### END INIT INFO
be3d56b
be3d56b
# Init script default settings
be3d56b
NSD_CONF="/etc/nsd/nsd.conf"
be3d56b
NSD_PROG="/usr/sbin/nsd"
be3d56b
NSD_PIDFILE="/var/run/nsd/nsd.pid"
be3d56b
NSD_XFRDFILE="/var/lib/nsd/xfrd.state"
be3d56b
NSDC_PROG="/usr/sbin/nsd-control"
be3d56b
NSD_USER="nsd"
be3d56b
NSD_PIDDIR="$(dirname ${NSD_PIDFILE})"
be3d56b
NSD_EXTRA_OPTS=""
be3d56b
be3d56b
# Source function library.
be3d56b
. /etc/rc.d/init.d/functions
be3d56b
be3d56b
[ -r /etc/sysconfig/nsd ] && . /etc/sysconfig/nsd
be3d56b
be3d56b
# Check that networking is configured.
be3d56b
[ "${NETWORKING}" = "no" ] && exit 0
be3d56b
be3d56b
# avoid AVC, see rhbz#989218
be3d56b
cd /etc/nsd
be3d56b
be3d56b
start() {
be3d56b
    # Source networking configuration.
be3d56b
    [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
be3d56b
be3d56b
    # Check that networking is up
be3d56b
    [ "${NETWORKING}" = "no" ] && exit 1
be3d56b
be3d56b
    # Sanity checks.
be3d56b
    [ -f ${NSD_CONF} ] || exit 5
be3d56b
    [ -x ${NSD_PROG} ] || exit 5
be3d56b
    # /var/run could (and should) be tmpfs
be3d56b
    [ -d ${NSD_PIDDIR} ] || {
be3d56b
	mkdir -p ${NSD_PIDDIR}
be3d56b
	chown ${NSD_USER}: ${NSD_PIDDIR}
be3d56b
    }
be3d56b
be3d56b
    if [ ! -f /etc/nsd/nsd_control.key ]; then
be3d56b
	echo -n $"Generating nsd control key and certificate: "
be3d56b
	/usr/sbin/nsd-control-setup -d /etc/nsd/ > /dev/null 2> /dev/null
be3d56b
	chgrp nsd /etc/nsd/nsd_*key /etc/nsd/nsd_*pem
be3d56b
	[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled && \
be3d56b
	    [ -x /sbin/restorecon ] && /sbin/restorecon /etc/nsd/*
be3d56b
	echo
be3d56b
    fi
be3d56b
be3d56b
    echo -n $"Starting nsd:"
be3d56b
    daemon \
be3d56b
	--pidfile=${NSD_PIDFILE} \
be3d56b
	${NSD_PROG} -c ${NSD_CONF} \
be3d56b
	${NSD_EXTRA_OPTS}
be3d56b
    RETVAL=$?
be3d56b
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/nsd
be3d56b
    echo
be3d56b
}
be3d56b
be3d56b
stop() {
be3d56b
    echo -n $"Stopping nsd: "
be3d56b
    # save state to zonefiles
be3d56b
    ${NSDC_PROG} -c ${NSD_CONF} write > /dev/null 2>&1
be3d56b
    killproc -p ${NSD_PIDFILE} ${NSD_PROG}
be3d56b
    RETVAL=$?
be3d56b
    if [ $RETVAL -eq 0 ] ; then
be3d56b
	rm -f /var/lock/subsys/nsd
be3d56b
	# ensure notifies are sent at startup
be3d56b
	rm -f ${NSD_XFRDFILE}
be3d56b
	success
be3d56b
    else
be3d56b
	failure
be3d56b
    fi
be3d56b
    echo
be3d56b
    return $RETVAL
be3d56b
}
be3d56b
be3d56b
restart() {
be3d56b
    stop
be3d56b
    start
be3d56b
}
be3d56b
be3d56b
RETVAL=0
be3d56b
be3d56b
# See how we were called.
be3d56b
case "$1" in
be3d56b
    start)
be3d56b
	start
be3d56b
	;;
be3d56b
    stop)
be3d56b
	stop
be3d56b
	;;
be3d56b
    restart)
be3d56b
	restart
be3d56b
	;;
be3d56b
    condrestart|try-restart)
be3d56b
	[ -f /var/lock/subsys/nsd ] && restart || :
be3d56b
	;;
be3d56b
    status)
be3d56b
	status -p ${NSD_PIDFILE} ${NSD_PROG}
be3d56b
	RETVAL=$?
be3d56b
	;;
be3d56b
    reload)
be3d56b
	echo -n $"Reloading nsd:"
be3d56b
	killproc -p ${NSD_PIDFILE} ${NSD_PROG} -HUP
be3d56b
	RETVAL=$?
be3d56b
	${NSDC_PROG} -c ${NSD_CONF} notify >/dev/null 2>&1 
be3d56b
	if [ $RETVAL -eq 0 ] ; then
be3d56b
	    success
be3d56b
	else
be3d56b
	    failure
be3d56b
	fi
be3d56b
	echo
be3d56b
	;;
be3d56b
    *)
be3d56b
	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload}"
be3d56b
	exit 2
be3d56b
esac
be3d56b
be3d56b
exit $RETVAL