|
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 |
969b1c |
### BEGIN INIT INFO
|
|
Adam Tkac |
969b1c |
# Provides: $named
|
|
Adam Tkac |
969b1c |
# Required-Start: $local_fs $network $syslog
|
|
Adam Tkac |
969b1c |
# Required-Stop: $local_fs $network $syslog
|
|
Adam Tkac |
fe4c11 |
# Default-Start:
|
|
Adam Tkac |
fe4c11 |
# Default-Stop: 0 1 2 3 4 5 6
|
|
Adam Tkac |
969b1c |
# Short-Description: start|stop|status|restart|try-restart|reload|force-reload DNS server
|
|
Adam Tkac |
969b1c |
# Description: control ISC BIND implementation of DNS server
|
|
Adam Tkac |
969b1c |
### END INIT INFO
|
|
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 |
fb5bf1 |
export KRB5_KTNAME=${KEYTAB_FILE:-/etc/named.keytab}
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
15c5cd |
named='named'
|
|
Adam Tkac |
15c5cd |
if [ -x /usr/sbin/named-sdb ]; then
|
|
Adam Tkac |
15c5cd |
named='named-sdb'
|
|
Adam Tkac |
15c5cd |
fi
|
|
Adam Tkac |
15c5cd |
|
|
Martin Stransky |
28242b |
# Don't kill named during clean-up
|
|
Adam Tkac |
72f5cc |
NAMED_SHUTDOWN_TIMEOUT=${NAMED_SHUTDOWN_TIMEOUT:-25}
|
|
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 |
559263 |
PIDFILE="/var/run/named/named.pid"
|
|
Adam Tkac |
559263 |
|
|
Adam Tkac |
91895c |
ROOTDIR_MOUNT='/etc/named /etc/pki/dnssec-keys /var/named /etc/named.conf
|
|
Adam Tkac |
583a06 |
/etc/named.dnssec.keys /etc/named.rfc1912.zones /etc/rndc.conf /etc/rndc.key
|
|
Adam Tkac |
f9d514 |
/usr/lib64/bind /usr/lib/bind /etc/named.iscdlv.key /etc/named.root.key'
|
|
Adam Tkac |
91895c |
|
|
Adam Tkac |
91895c |
mount_chroot_conf()
|
|
Adam Tkac |
91895c |
{
|
|
Adam Tkac |
91895c |
if [ -n "$ROOTDIR" ]; then
|
|
Adam Tkac |
91895c |
for all in $ROOTDIR_MOUNT; do
|
|
Adam Tkac |
91895c |
# Skip nonexistant files
|
|
Adam Tkac |
91895c |
[ -e "$all" ] || continue
|
|
Adam Tkac |
91895c |
|
|
Adam Tkac |
91895c |
# If mount source is a file
|
|
Adam Tkac |
91895c |
if ! [ -d "$all" ]; then
|
|
Adam Tkac |
91895c |
# mount it only if it is not present in chroot or it is empty
|
|
Adam Tkac |
b70aaa |
if ! [ -e "$ROOTDIR$all" ] || [ `stat -c'%s' "$ROOTDIR$all"` -eq 0 ]; then
|
|
Adam Tkac |
91895c |
touch "$ROOTDIR$all"
|
|
Adam Tkac |
91895c |
mount --bind "$all" "$ROOTDIR$all"
|
|
Adam Tkac |
91895c |
fi
|
|
Adam Tkac |
91895c |
else
|
|
Adam Tkac |
91895c |
# Mount source is a directory. Mount it only if directory in chroot is
|
|
Adam Tkac |
91895c |
# empty.
|
|
Adam Tkac |
583a06 |
if [ -e "$all" ] && [ `ls -1A $ROOTDIR$all | wc -l` -eq 0 ]; then
|
|
Adam Tkac |
91895c |
mount --bind "$all" "$ROOTDIR$all"
|
|
Adam Tkac |
583a06 |
fi
|
|
Adam Tkac |
91895c |
fi
|
|
Adam Tkac |
91895c |
done
|
|
Adam Tkac |
91895c |
fi
|
|
Adam Tkac |
91895c |
}
|
|
Adam Tkac |
91895c |
|
|
Adam Tkac |
91895c |
umount_chroot_conf()
|
|
Adam Tkac |
91895c |
{
|
|
Adam Tkac |
91895c |
for all in $ROOTDIR_MOUNT; do
|
|
Adam Tkac |
91895c |
# Check if file is mount target. Do not use /proc/mounts because detecting
|
|
Adam Tkac |
91895c |
# of modified mounted files can fail.
|
|
Adam Tkac |
91895c |
if mount | grep -q '.* on '"$ROOTDIR$all"' .*'; then
|
|
Adam Tkac |
91895c |
umount "$ROOTDIR$all"
|
|
Adam Tkac |
91895c |
# Remove temporary created files
|
|
Adam Tkac |
91895c |
[ -f "$all" ] && rm -f "$ROOTDIR$all"
|
|
Adam Tkac |
91895c |
fi
|
|
Adam Tkac |
91895c |
done
|
|
Adam Tkac |
91895c |
}
|
|
Adam Tkac |
91895c |
|
|
Adam Tkac |
f214e0 |
pidofnamed() {
|
|
Adam Tkac |
559263 |
pidofproc -p "$ROOTDIR/$PIDFILE" "$named";
|
|
Adam Tkac |
f214e0 |
}
|
|
Adam Tkac |
f214e0 |
|
|
Adam Tkac |
e51da3 |
# Check if all what named needs running
|
|
Adam Tkac |
e51da3 |
start()
|
|
Adam Tkac |
e51da3 |
{
|
|
Adam Tkac |
13e55c |
[ "$EUID" != "0" ] && exit 4
|
|
Adam Tkac |
13e55c |
|
|
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 |
15c5cd |
[ -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 |
91895c |
mount_chroot_conf
|
|
Adam Tkac |
91895c |
|
|
Adam Tkac |
038864 |
if [ ! -r $ROOTDIR$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 |
2be0bc |
echo -n $"Starting named: "
|
|
Adam Tkac |
f214e0 |
if [ -n "`pidofnamed`" ]; then
|
|
Adam Tkac |
2be0bc |
echo -n $"named: already running"
|
|
Adam Tkac |
13e55c |
success
|
|
Adam Tkac |
e51da3 |
echo
|
|
Adam Tkac |
13e55c |
exit 0;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
d4ce1d |
if ! [ "$DISABLE_ZONE_CHECKING" = yes ]; then
|
|
Adam Tkac |
d4ce1d |
ckcf_options='-z'; # enable named-checkzone for each zone (9.3.1+) !
|
|
Adam Tkac |
d4ce1d |
fi;
|
|
Adam Tkac |
d4ce1d |
|
|
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 |
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 |
559263 |
daemon --pidfile "$ROOTDIR/$PIDFILE" /usr/sbin/"$named" -u named ${OPTIONS};
|
|
Adam Tkac |
e51da3 |
RETVAL=$?
|
|
Adam Tkac |
e51da3 |
if [ $RETVAL -eq 0 ]; then
|
|
Adam Tkac |
15c5cd |
rm -f /var/run/{named,named-sdb}.pid;
|
|
Adam Tkac |
559263 |
ln -s $ROOTDIR/"$PIDFILE" /var/run/"$named".pid;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
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 |
91895c |
umount_chroot_conf
|
|
Adam Tkac |
e51da3 |
exit 2;
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
1c2862 |
echo
|
|
Adam Tkac |
e51da3 |
if [ $RETVAL -eq 0 ]; then
|
|
Adam Tkac |
e51da3 |
touch /var/lock/subsys/named;
|
|
Adam Tkac |
e51da3 |
else
|
|
Adam Tkac |
91895c |
umount_chroot_conf
|
|
Adam Tkac |
e51da3 |
exit 7;
|
|
Adam Tkac |
e51da3 |
fi
|
|
Adam Tkac |
e51da3 |
return 0;
|
|
cvsdist |
2f7f4b |
}
|
|
Adam Tkac |
e51da3 |
|
|
cvsdist |
2f7f4b |
stop() {
|
|
Adam Tkac |
13e55c |
[ "$EUID" != "0" ] && exit 4
|
|
Adam Tkac |
13e55c |
|
|
Adam Tkac |
e51da3 |
# Stop daemons.
|
|
Adam Tkac |
2be0bc |
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 |
72f5cc |
# was rndc successful?
|
|
Adam Tkac |
ebeac1 |
[ "$RETVAL" -eq 0 ] || \
|
|
Adam Tkac |
559263 |
killproc -p "$ROOTDIR/$PIDFILE" "$named" -TERM >/dev/null 2>&1
|
|
Adam Tkac |
72f5cc |
|
|
Adam Tkac |
72f5cc |
timeout=0
|
|
Adam Tkac |
72f5cc |
RETVAL=0
|
|
Adam Tkac |
f214e0 |
while pidofnamed >/dev/null; do
|
|
Adam Tkac |
72f5cc |
if [ $timeout -ge $NAMED_SHUTDOWN_TIMEOUT ]; then
|
|
Adam Tkac |
72f5cc |
RETVAL=1
|
|
Adam Tkac |
72f5cc |
break
|
|
Adam Tkac |
72f5cc |
else
|
|
Adam Tkac |
72f5cc |
sleep 2 && echo -n "."
|
|
Adam Tkac |
72f5cc |
timeout=$((timeout+2))
|
|
Adam Tkac |
72f5cc |
fi;
|
|
Adam Tkac |
72f5cc |
done
|
|
Adam Tkac |
e51da3 |
|
|
Adam Tkac |
91895c |
umount_chroot_conf
|
|
Adam Tkac |
91895c |
|
|
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 |
15c5cd |
rm -f /var/run/{named,named-sdb}.pid
|
|
Adam Tkac |
e51da3 |
fi;
|
|
Adam Tkac |
e51da3 |
|
|
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 |
559263 |
status -p "$ROOTDIR/$PIDFILE" /usr/sbin/"$named";
|
|
Adam Tkac |
e51da3 |
return $?
|
|
cvsdist |
2f7f4b |
}
|
|
cvsdist |
2f7f4b |
restart() {
|
|
cvsdist |
2f7f4b |
stop
|
|
cvsdist |
2f7f4b |
start
|
|
cvsdist |
2f7f4b |
}
|
|
cvsdist |
2f7f4b |
reload() {
|
|
Adam Tkac |
13e55c |
[ "$EUID" != "0" ] && exit
|
|
Adam Tkac |
13e55c |
|
|
Adam Tkac |
15c5cd |
echo -n $"Reloading "$named": "
|
|
Adam Tkac |
f214e0 |
p=`pidofnamed`
|
|
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
|
|
Adam Tkac |
15c5cd |
[ "$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 |
;;
|
|
Adam Tkac |
13e55c |
condrestart|try-restart)
|
|
Adam Tkac |
969b1c |
if [ -e /var/lock/subsys/named ]; then restart; fi
|
|
Adam Tkac |
969b1c |
;;
|
|
cvsdist |
2f7f4b |
reload)
|
|
cvsdist |
2f7f4b |
reload
|
|
cvsdist |
2f7f4b |
;;
|
|
Adam Tkac |
969b1c |
force-reload)
|
|
Adam Tkac |
969b1c |
if ! reload; then restart; fi
|
|
Adam Tkac |
969b1c |
;;
|
|
cvsdist |
2f7f4b |
*)
|
|
Adam Tkac |
969b1c |
echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
|
|
Adam Tkac |
13e55c |
[ "x$1" = "x" ] && exit 0
|
|
Adam Tkac |
311ac6 |
exit 2
|
|
cvsdist |
2f7f4b |
esac
|
|
cvsdist |
2f7f4b |
|
|
Adam Tkac |
e51da3 |
exit $RETVAL
|
|
cvsdist |
2f7f4b |
|