#!/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"
NSDC_PROG="/usr/sbin/nsd-control"
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
# avoid AVC, see rhbz#989218
cd /etc/nsd
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}
}
if [ ! -f /etc/nsd/nsd_control.key ]; then
echo -n $"Generating nsd control key and certificate: "
/usr/sbin/nsd-control-setup -d /etc/nsd/ > /dev/null 2> /dev/null
chgrp nsd /etc/nsd/nsd_*key /etc/nsd/nsd_*pem
[ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled && \
[ -x /sbin/restorecon ] && /sbin/restorecon /etc/nsd/*
echo
fi
echo -n $"Starting nsd:"
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: "
killproc -p ${NSD_PIDFILE} ${NSD_PROG}
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/nsd
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}
RETVAL=$?
;;
reload)
echo -n $"Reloading nsd:"
killproc -p ${NSD_PIDFILE} ${NSD_PROG} -HUP
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
success
else
failure
fi
echo
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload}"
exit 2
esac
exit $RETVAL