|
cvsdist |
2f7f4b |
#!/bin/bash
|
|
cvsdist |
2f7f4b |
#
|
|
cvsdist |
2f7f4b |
# named This shell script takes care of starting and stopping
|
|
cvsdist |
2f7f4b |
# named (BIND DNS server).
|
|
cvsdist |
2f7f4b |
#
|
|
jvdias |
3c357d |
# chkconfig: - 13 87
|
|
cvsdist |
2f7f4b |
# description: named (BIND) is a Domain Name Server (DNS) \
|
|
cvsdist |
2f7f4b |
# that is used to resolve host names to IP addresses.
|
|
cvsdist |
2f7f4b |
# probe: true
|
|
cvsdist |
2f7f4b |
|
|
Adam Tkac |
e51da3 |
# Return codes
|
|
Adam Tkac |
e51da3 |
# - script (all except status command)
|
|
Adam Tkac |
e51da3 |
# - 2 invalid or excess argument(s)
|
|
Adam Tkac |
e51da3 |
# - 3 unimplemented feature (for example, "reload")
|
|
Adam Tkac |
e51da3 |
# - 4 user had insufficient privilege
|
|
Adam Tkac |
e51da3 |
# - 5 program is not installed
|
|
Adam Tkac |
e51da3 |
# - 6 program is not configured
|
|
Adam Tkac |
e51da3 |
# - 7 program is not running
|
|
Adam Tkac |
e51da3 |
|
|
cvsdist |
2f7f4b |
# Source function library.
|
|
cvsdist |
2f7f4b |
. /etc/rc.d/init.d/functions
|
|
cvsdist |
2f7f4b |
|
|
cvsdist |
78e1f2 |
[ -r /etc/sysconfig/named ] && . /etc/sysconfig/named
|
|
cvsdist |
2f7f4b |
|
|
Adam Tkac |
e51da3 |
RETVAL=0
|
|
Adam Tkac |
e51da3 |
|
|
Martin Stransky |
28242b |
# Don't kill named during clean-up
|
|
Martin Stransky |
2e702b |
NAMED_SHUTDOWN_TIMEOUT=${NAMED_SHUTDOWN_TIMEOUT:-100}
|
|
Martin Stransky |
2e702b |
|
|
jvdias |
0cd02a |
if [ -n "$ROOTDIR" ]; then
|
|
jvdias |
0cd02a |
ROOTDIR=`echo $ROOTDIR | sed 's#//*#/#g;s#/$##'`;
|
|
jvdias |
0cd02a |
rdl=`/usr/bin/readlink $ROOTDIR`;
|
|
jvdias |
0cd02a |
if [ -n "$rdl" ]; then
|
|
jvdias |
0cd02a |
ROOTDIR="$rdl";
|
|
jvdias |
0cd02a |
fi;
|
|
jvdias |
0cd02a |
fi
|
|
jvdias |
38a73e |
|
|
Adam Tkac |
e51da3 |
# Run SDB backend?
|
|
jvdias |
e9f83d |
named='named'
|
|
Adam Tkac |
e51da3 |
if `echo "$ENABLE_SDB" | grep -q ^[yY1].*`; then
|
|
Adam Tkac |
e51da3 |
named='named_sdb';
|
|
jvdias |
e9f83d |
fi;
|
|
jvdias |
e9f83d |
|
|
Adam Tkac |
e51da3 |
# Manage forwarders through D-BUS?
|
|
Adam Tkac |
e51da3 |
for a in $OPTIONS; do
|
|
Adam Tkac |
e51da3 |
if [ $a = "-D" ]; then
|
|
Adam Tkac |
e51da3 |
dbusEnabled=1;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
done
|
|
Adam Tkac |
e51da3 |
if [ -z $dbusEnabled ] && [ -z "$DISABLE_NAMED_DBUS" ] ; then
|
|
Adam Tkac |
e51da3 |
for l in 0 1 2 3 4 5 6; do
|
|
Adam Tkac |
e51da3 |
if /sbin/chkconfig --level=$l NetworkManager >/dev/null 2>&1; then
|
|
Adam Tkac |
e51da3 |
dbusEnabled=1;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
done
|
|
Adam Tkac |
55b04d |
[ -z $dbusEnabled ] || OPTIONS="$OPTIONS -D";
|
|
Adam Tkac |
e51da3 |
fi;
|
|
cvsdist |
2f7f4b |
|
|
Adam Tkac |
e51da3 |
# Check if all what named needs running
|
|
Adam Tkac |
e51da3 |
start()
|
|
Adam Tkac |
e51da3 |
{
|
|
Adam Tkac |
e51da3 |
# Source networking configuration.
|
|
Adam Tkac |
e51da3 |
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
|
|
jvdias |
0cd02a |
|
|
Adam Tkac |
e51da3 |
# Check that networking is up
|
|
Adam Tkac |
e51da3 |
[ "${NETWORKING}" = "no" ] && exit 1
|
|
jvdias |
0cd02a |
|
|
jvdias |
420671 |
|
|
Adam Tkac |
e51da3 |
[ -x /usr/sbin/$named ] || exit 5
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
# Handle -c option
|
|
Adam Tkac |
e51da3 |
previous_option='unspecified';
|
|
Adam Tkac |
e51da3 |
for a in $OPTIONS; do
|
|
Adam Tkac |
e51da3 |
if [ $previous_option = '-c' ]; then
|
|
Adam Tkac |
e51da3 |
named_conf=$a;
|
|
jvdias |
bc0ace |
fi;
|
|
Adam Tkac |
e51da3 |
previous_option=$a;
|
|
Adam Tkac |
e51da3 |
done;
|
|
jvdias |
bc0ace |
|
|
Adam Tkac |
e51da3 |
named_conf=${named_conf:-/etc/named.conf};
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
if [ ! -r $named_conf ]; then
|
|
Adam Tkac |
e51da3 |
echo 'Cannot find configuration file. You could create it by system-config-bind'
|
|
Adam Tkac |
e51da3 |
exit 6;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
# all pre-start is done, lets start named
|
|
Adam Tkac |
e51da3 |
echo -n $"Starting $named: "
|
|
Adam Tkac |
e51da3 |
if [ -n "`/sbin/pidof -o %PPID $named`" ]; then
|
|
Adam Tkac |
e51da3 |
echo -n $"$named: already running"
|
|
Adam Tkac |
e51da3 |
failure
|
|
Adam Tkac |
e51da3 |
echo
|
|
Adam Tkac |
e51da3 |
exit 1;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
ckcf_options='-z'; # enable named-checkzone for each zone (9.3.1+) !
|
|
Adam Tkac |
e51da3 |
if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
|
|
Adam Tkac |
e51da3 |
OPTIONS="${OPTIONS} -t ${ROOTDIR}"
|
|
Adam Tkac |
e51da3 |
ckcf_options="$ckcf_options -t ${ROOTDIR}";
|
|
Adam Tkac |
e51da3 |
[ -s /etc/localtime ] && cp -fp /etc/localtime ${ROOTDIR}/etc/localtime;
|
|
Adam Tkac |
e51da3 |
[ -d ${ROOTDIR}/proc ] || mkdir -p ${ROOTDIR}/proc;
|
|
Adam Tkac |
e51da3 |
if ! egrep -q '^/proc[[:space:]]+'${ROOTDIR}'/proc' /proc/mounts; then
|
|
Adam Tkac |
e51da3 |
mount --bind -n /proc ${ROOTDIR}/proc >/dev/null 2>&1;
|
|
Adam Tkac |
e51da3 |
fi
|
|
Adam Tkac |
e51da3 |
if [ ! -z $dbusEnabled ]; then
|
|
Adam Tkac |
e51da3 |
if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${ROOTDIR}'/var/run/dbus' /proc/mounts; then
|
|
Adam Tkac |
e51da3 |
mkdir -p ${ROOTDIR}/var/run/dbus
|
|
Adam Tkac |
e51da3 |
[ -d /var/run/dbus ] || mkdir -p /var/run/dbus;
|
|
Adam Tkac |
e51da3 |
mount --bind -n /var/run/dbus ${ROOTDIR}/var/run/dbus > /dev/null 2>&1;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
jvdias |
6fcc99 |
fi;
|
|
Adam Tkac |
e51da3 |
fi
|
|
jvdias |
bc0ace |
|
|
Adam Tkac |
e51da3 |
RETVAL=0
|
|
Adam Tkac |
e51da3 |
# check if configuration is correct
|
|
Adam Tkac |
e51da3 |
if [ -x /usr/sbin/named-checkconf ] && [ -x /usr/sbin/named-checkzone ] && /usr/sbin/named-checkconf $ckcf_options ${named_conf} >/dev/null 2>&1; then
|
|
Adam Tkac |
7fdb7f |
|
|
Adam Tkac |
e51da3 |
daemon /usr/sbin/$named -u named ${OPTIONS};
|
|
Adam Tkac |
e51da3 |
RETVAL=$?
|
|
Adam Tkac |
e51da3 |
if [ $RETVAL -eq 0 ]; then
|
|
Adam Tkac |
e51da3 |
rm -f /var/run/named.pid;
|
|
Adam Tkac |
e51da3 |
rm -f /var/run/named_sdb.pid;
|
|
Adam Tkac |
e51da3 |
ln -s $ROOTDIR/var/run/named/named.pid /var/run/named.pid;
|
|
Adam Tkac |
e51da3 |
[ "$named" = "named_sdb" ] && ln -s $ROOTDIR/var/run/named/named.pid /var/run/named_sdb.pid;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
if [ -n "`/sbin/pidof -o %PPID $named`" ]; then
|
|
Adam Tkac |
e51da3 |
# Verify that named actually started (JM 2006-10-04)
|
|
Adam Tkac |
e51da3 |
if [ ! -e $ROOTDIR/var/run/named/named.pid ]; then
|
|
Adam Tkac |
e51da3 |
# If there is not a file containing the PID of the now running named daemon then create it (JM 2006-10-04)
|
|
Adam Tkac |
e51da3 |
echo `/sbin/pidof -o %PPID $named` > $ROOTDIR/var/run/named/named.pid;
|
|
Adam Tkac |
e51da3 |
[ "$named" = "named_sdb" ] && echo `/sbin/pidof -o %PPID $named` > $ROOTDIR/var/run/named/named_sdb.pid;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
else
|
|
Adam Tkac |
e51da3 |
named_err="`/usr/sbin/named-checkconf $ckcf_options $named_conf 2>&1`";
|
|
Adam Tkac |
e51da3 |
echo
|
|
Adam Tkac |
e51da3 |
echo "Error in named configuration:";
|
|
Adam Tkac |
e51da3 |
echo "$named_err";
|
|
Adam Tkac |
e51da3 |
failure
|
|
Adam Tkac |
e51da3 |
echo
|
|
Adam Tkac |
e51da3 |
[ -x /usr/bin/logger ] && echo "$named_err" | /usr/bin/logger -pdaemon.error -tnamed;
|
|
Adam Tkac |
e51da3 |
exit 2;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
if [ $RETVAL -eq 0 ]; then
|
|
Adam Tkac |
e51da3 |
touch /var/lock/subsys/named;
|
|
Adam Tkac |
e51da3 |
else
|
|
Adam Tkac |
e51da3 |
exit 7;
|
|
Adam Tkac |
e51da3 |
fi
|
|
Adam Tkac |
e51da3 |
echo
|
|
Adam Tkac |
e51da3 |
return 0;
|
|
cvsdist |
2f7f4b |
}
|
|
Adam Tkac |
e51da3 |
|
|
cvsdist |
2f7f4b |
stop() {
|
|
Adam Tkac |
e51da3 |
# Stop daemons.
|
|
Adam Tkac |
e51da3 |
echo -n $"Stopping $named: "
|
|
Adam Tkac |
e51da3 |
[ -x /usr/sbin/rndc ] && /usr/sbin/rndc stop >/dev/null 2>&1;
|
|
Adam Tkac |
e51da3 |
RETVAL=$?
|
|
Adam Tkac |
e51da3 |
# is it still here?
|
|
Adam Tkac |
e51da3 |
if /sbin/pidof -o %PPID $named >/dev/null; then
|
|
Adam Tkac |
e51da3 |
timeout=0
|
|
Adam Tkac |
e51da3 |
while : ; do
|
|
Adam Tkac |
e51da3 |
if /sbin/pidof -o %PPID $named >/dev/null; then
|
|
Adam Tkac |
e51da3 |
if [ $timeout -ge $NAMED_SHUTDOWN_TIMEOUT ]; then
|
|
Adam Tkac |
e51da3 |
killproc $named -TERM >/dev/null 2>&1
|
|
Adam Tkac |
e51da3 |
RETVAL=$?
|
|
Adam Tkac |
e51da3 |
echo $"no response, killing with -TERM "
|
|
Adam Tkac |
e51da3 |
break
|
|
Adam Tkac |
e51da3 |
else
|
|
Adam Tkac |
e51da3 |
sleep 2 && echo -n "."
|
|
Adam Tkac |
e51da3 |
timeout=$((timeout+2))
|
|
jvdias |
b7b41a |
fi;
|
|
Adam Tkac |
e51da3 |
else
|
|
Adam Tkac |
e51da3 |
break
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
done
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
# remove pid files
|
|
Adam Tkac |
e51da3 |
if [ $RETVAL -eq 0 ]; then
|
|
Adam Tkac |
e51da3 |
rm -f /var/lock/subsys/named
|
|
Adam Tkac |
e51da3 |
rm -f /var/run/named.pid
|
|
Adam Tkac |
e51da3 |
rm -f /var/run/named_sdb.pid
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
# unmount mounted filesystems/directories
|
|
Adam Tkac |
e51da3 |
if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
|
|
Adam Tkac |
e51da3 |
if egrep -q '^/proc[[:space:]]+'${ROOTDIR}'/proc' /proc/mounts; then
|
|
Adam Tkac |
e51da3 |
umount ${ROOTDIR}/proc >/dev/null 2>&1
|
|
Adam Tkac |
e51da3 |
fi
|
|
Adam Tkac |
e51da3 |
if [ ! -z $dbusEnabled ]; then
|
|
Adam Tkac |
e51da3 |
if egrep -q '^/[^[:space:]]+[[:space:]]+'${ROOTDIR}'/var/run/dbus' /proc/mounts; then
|
|
Adam Tkac |
e51da3 |
umount ${ROOTDIR}/var/run/dbus > /dev/null 2>&1
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
if [ $RETVAL -eq 0 ]; then
|
|
Adam Tkac |
e51da3 |
success
|
|
Adam Tkac |
e51da3 |
else
|
|
Adam Tkac |
e51da3 |
failure
|
|
Adam Tkac |
e51da3 |
RETVAL=1
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
echo
|
|
Adam Tkac |
e51da3 |
return $RETVAL
|
|
cvsdist |
2f7f4b |
}
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
e51da3 |
|
|
cvsdist |
2f7f4b |
rhstatus() {
|
|
Adam Tkac |
e51da3 |
[ -x /usr/sbin/rndc ] && /usr/sbin/rndc status;
|
|
Adam Tkac |
e51da3 |
status /usr/bin/$named;
|
|
Adam Tkac |
e51da3 |
return $?
|
|
cvsdist |
2f7f4b |
}
|
|
cvsdist |
2f7f4b |
restart() {
|
|
cvsdist |
2f7f4b |
stop
|
|
cvsdist |
2f7f4b |
start
|
|
cvsdist |
2f7f4b |
}
|
|
cvsdist |
2f7f4b |
reload() {
|
|
jvdias |
e9f83d |
echo -n $"Reloading $named: "
|
|
jvdias |
e9f83d |
p=`/sbin/pidof -o %PPID $named`
|
|
cvsdist |
d69ee3 |
RETVAL=$?
|
|
cvsdist |
d69ee3 |
if [ "$RETVAL" -eq 0 ]; then
|
|
jvdias |
aad908 |
/usr/sbin/rndc reload >/dev/null 2>&1 || /bin/kill -HUP $p;
|
|
cvsdist |
d69ee3 |
RETVAL=$?
|
|
cvsdist |
d69ee3 |
fi
|
|
jvdias |
e9f83d |
[ "$RETVAL" -eq 0 ] && success $"$named reload" || failure $"$named reload"
|
|
cvsdist |
78e1f2 |
echo
|
|
Adam Tkac |
e51da3 |
return $RETVAL
|
|
jvdias |
b7b41a |
}
|
|
cvsdist |
2f7f4b |
|
|
cvsdist |
2f7f4b |
# See how we were called.
|
|
cvsdist |
2f7f4b |
case "$1" in
|
|
cvsdist |
2f7f4b |
start)
|
|
cvsdist |
2f7f4b |
start
|
|
cvsdist |
2f7f4b |
;;
|
|
cvsdist |
2f7f4b |
stop)
|
|
cvsdist |
2f7f4b |
stop
|
|
cvsdist |
2f7f4b |
;;
|
|
cvsdist |
2f7f4b |
status)
|
|
Adam Tkac |
e51da3 |
rhstatus;
|
|
Adam Tkac |
e51da3 |
RETVAL=$?
|
|
cvsdist |
2f7f4b |
;;
|
|
cvsdist |
2f7f4b |
restart)
|
|
cvsdist |
2f7f4b |
restart
|
|
cvsdist |
2f7f4b |
;;
|
|
cvsdist |
2f7f4b |
condrestart)
|
|
cvsdist |
31bdca |
if [ -e /var/lock/subsys/named ]; then restart; fi
|
|
cvsdist |
2f7f4b |
;;
|
|
cvsdist |
2f7f4b |
reload)
|
|
cvsdist |
2f7f4b |
reload
|
|
cvsdist |
2f7f4b |
;;
|
|
cvsdist |
2f7f4b |
*)
|
|
Adam Tkac |
e51da3 |
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
|
|
Adam Tkac |
e51da3 |
exit 3
|
|
cvsdist |
2f7f4b |
esac
|
|
cvsdist |
2f7f4b |
|
|
Adam Tkac |
e51da3 |
exit $RETVAL
|
|
cvsdist |
2f7f4b |
|