|
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 |
|
|
cvsdist |
2f7f4b |
# Source function library.
|
|
cvsdist |
2f7f4b |
. /etc/rc.d/init.d/functions
|
|
cvsdist |
2f7f4b |
|
|
cvsdist |
2f7f4b |
# Source networking configuration.
|
|
cvsdist |
4f506d |
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
|
|
cvsdist |
2f7f4b |
|
|
cvsdist |
2f7f4b |
# Check that networking is up.
|
|
jvdias |
e51c8f |
[ "${NETWORKING}" = "no" ] && exit 1
|
|
cvsdist |
aed712 |
|
|
cvsdist |
78e1f2 |
[ -r /etc/sysconfig/named ] && . /etc/sysconfig/named
|
|
cvsdist |
2f7f4b |
|
|
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 |
|
|
jvdias |
e9f83d |
RETVAL=0
|
|
jvdias |
e9f83d |
named='named'
|
|
jvdias |
e9f83d |
if [[ "$ENABLE_SDB" = [yY1]* ]] && [ -x /usr/sbin/named_sdb ]; then
|
|
jvdias |
e9f83d |
named='named_sdb';
|
|
jvdias |
e9f83d |
fi;
|
|
jvdias |
e9f83d |
prog=$named
|
|
jvdias |
e9f83d |
|
|
jvdias |
e9f83d |
[ -x /usr/sbin/$named ] || exit 1
|
|
cvsdist |
2f7f4b |
|
|
jvdias |
38a73e |
nmdcOption()
|
|
jvdias |
38a73e |
{ let i=0;
|
|
jvdias |
38a73e |
for a in $*;
|
|
jvdias |
38a73e |
do ((++i));
|
|
jvdias |
38a73e |
if [ $a = -c ]; then
|
|
jvdias |
38a73e |
((++i));
|
|
jvdias |
38a73e |
eval 'echo $'$i;
|
|
jvdias |
38a73e |
elif [[ $a = -c* ]]; then
|
|
jvdias |
38a73e |
echo ${a#-c};
|
|
jvdias |
38a73e |
fi;
|
|
jvdias |
38a73e |
done;
|
|
jvdias |
38a73e |
}
|
|
jvdias |
0cd02a |
|
|
jvdias |
0cd02a |
named_c_option=`nmdcOption $OPTIONS`;
|
|
jvdias |
2e31a9 |
named_conf=${named_c_option:-/etc/named.conf};
|
|
jvdias |
0cd02a |
|
|
jvdias |
2e31a9 |
if [ ! -r ${ROOTDIR}${named_conf} ] ; then
|
|
jvdias |
0cd02a |
if [ -z "$named_c_option" ] && [ -r ${ROOTDIR}/etc/named.caching-nameserver.conf ]; then
|
|
jvdias |
0cd02a |
named_conf='/etc/named.caching-nameserver.conf';
|
|
jvdias |
0cd02a |
OPTIONS="$OPTIONS -c ${named_conf}";
|
|
jvdias |
0cd02a |
else
|
|
jvdias |
0cd02a |
echo Locating $ROOTDIR/${named_conf} failed:
|
|
jvdias |
0cd02a |
failure
|
|
jvdias |
0cd02a |
echo;
|
|
jvdias |
bc0ace |
exit 1;
|
|
jvdias |
0cd02a |
fi;
|
|
jvdias |
0cd02a |
fi;
|
|
jvdias |
420671 |
|
|
jvdias |
bc0ace |
dbusEnabled=0;
|
|
jvdias |
bc0ace |
for a in $OPTIONS; do
|
|
jvdias |
bc0ace |
if [ $a = "-D" ]; then
|
|
jvdias |
bc0ace |
dbusEnabled=1;
|
|
jvdias |
bc0ace |
fi;
|
|
jvdias |
bc0ace |
done
|
|
jvdias |
bc0ace |
|
|
jvdias |
6fcc99 |
if [ $dbusEnabled -eq 0 ] && [ -z "$DISABLE_NAMED_DBUS" ] ; then
|
|
jvdias |
6fcc99 |
NetworkManagerEnabled=0
|
|
jvdias |
6fcc99 |
for l in 0 1 2 3 4 5 6; do
|
|
jvdias |
6fcc99 |
if /sbin/chkconfig --level=$l NetworkManager >/dev/null 2>&1; then
|
|
jvdias |
6fcc99 |
NetworkManagerEnabled=1;
|
|
jvdias |
6fcc99 |
fi;
|
|
jvdias |
6fcc99 |
done
|
|
jvdias |
6fcc99 |
if [ $NetworkManagerEnabled -eq 1 ]; then
|
|
jvdias |
6fcc99 |
OPTIONS="$OPTIONS -D";
|
|
jvdias |
6fcc99 |
fi;
|
|
jvdias |
6fcc99 |
dbusEnabled=1;
|
|
jvdias |
bc0ace |
fi
|
|
jvdias |
bc0ace |
|
|
cvsdist |
2f7f4b |
start() {
|
|
cvsdist |
2f7f4b |
# Start daemons.
|
|
jvdias |
e9f83d |
echo -n $"Starting $named: "
|
|
jvdias |
e9f83d |
if [ -n "`/sbin/pidof -o %PPID $named`" ]; then
|
|
jvdias |
e9f83d |
echo -n $"$named: already running"
|
|
jvdias |
6e144c |
failure
|
|
jvdias |
6e144c |
echo
|
|
cvsdist |
0a52a5 |
return 1
|
|
cvsdist |
0a52a5 |
fi
|
|
jvdias |
b7b41a |
ckcf_options='-z'; # enable named-checkzone for each zone (9.3.1+) !
|
|
cvsdist |
aed712 |
if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
|
|
cvsdist |
aed712 |
OPTIONS="${OPTIONS} -t ${ROOTDIR}"
|
|
jvdias |
b7b41a |
ckcf_options="$ckcf_options -t ${ROOTDIR}";
|
|
jvdias |
d3f558 |
if [ -s /etc/localtime ]; then
|
|
jvdias |
d3f558 |
cp -fp /etc/localtime ${ROOTDIR}/etc/localtime
|
|
jvdias |
d3f558 |
fi;
|
|
jvdias |
1abbaa |
if [ ! -d ${ROOTDIR}/proc ]; then
|
|
jvdias |
1abbaa |
mkdir -p ${ROOTDIR}/proc
|
|
jvdias |
1abbaa |
fi
|
|
jvdias |
f84fe3 |
if ! egrep -q '^/proc[[:space:]]+'${ROOTDIR}'/proc' /proc/mounts; then
|
|
Martin Stransky |
28242b |
mount --bind -n /proc ${ROOTDIR}/proc >/dev/null 2>&1
|
|
jvdias |
1abbaa |
fi
|
|
jvdias |
bc0ace |
if [ $dbusEnabled -eq 1 ]; then
|
|
jvdias |
dc8dce |
if ! egrep -q '^/[^[:space:]]+[[:space:]]+'${ROOTDIR}'/var/run/dbus' /proc/mounts; then
|
|
jvdias |
f4e163 |
mkdir -p ${ROOTDIR}/var/run/dbus
|
|
jvdias |
f84fe3 |
if [ ! -d /var/run/dbus ] ; then
|
|
jvdias |
f84fe3 |
mkdir -p /var/run/dbus ;
|
|
jvdias |
f84fe3 |
fi;
|
|
Martin Stransky |
28242b |
mount --bind -n /var/run/dbus ${ROOTDIR}/var/run/dbus > /dev/null 2>&1;
|
|
jvdias |
f4e163 |
fi;
|
|
jvdias |
a06ea5 |
fi;
|
|
cvsdist |
aed712 |
fi
|
|
jvdias |
18d1e1 |
no_write_master_zones=0
|
|
jvdias |
23b1ff |
if [ -e /etc/selinux/config ]; then
|
|
jvdias |
23b1ff |
. /etc/selinux/config
|
|
jvdias |
b7b41a |
if [[ ( "$SELINUX" != 'disabled') && ("$SELINUXTYPE" != "") && (-d /etc/selinux/${SELINUXTYPE}) && (-e /etc/selinux/${SELINUXTYPE}/booleans || (-e /etc/selinux/${SELINUXTYPE}/booleans.local)) ]]; then
|
|
jvdias |
b7b41a |
if [ -e /etc/selinux/${SELINUXTYPE}/booleans.local ]; then
|
|
jvdias |
b7b41a |
. /etc/selinux/${SELINUXTYPE}/booleans.local;
|
|
jvdias |
b7b41a |
else
|
|
jvdias |
b7b41a |
. /etc/selinux/${SELINUXTYPE}/booleans;
|
|
jvdias |
b7b41a |
fi;
|
|
jvdias |
2dbdf5 |
if echo "$named_write_master_zones" | /bin/egrep -q '^[0-9]+$'; then
|
|
jvdias |
2dbdf5 |
if [ "$named_write_master_zones" -eq 1 ] ; then
|
|
jvdias |
2dbdf5 |
/bin/chown -f --from=root:named named:named $ROOTDIR/var/named
|
|
jvdias |
2dbdf5 |
elif [ "$named_write_master_zones" -eq 0 ] ; then
|
|
jvdias |
2dbdf5 |
/bin/chown -f --from=named:named root:named $ROOTDIR/var/named
|
|
jvdias |
2dbdf5 |
fi;
|
|
jvdias |
2dbdf5 |
fi;
|
|
jvdias |
18d1e1 |
else
|
|
jvdias |
18d1e1 |
no_write_master_zones=1
|
|
jvdias |
23b1ff |
fi;
|
|
jvdias |
18d1e1 |
else
|
|
jvdias |
18d1e1 |
no_write_master_zones=1
|
|
jvdias |
23b1ff |
fi;
|
|
jvdias |
18d1e1 |
if [ "$no_write_master_zones" -eq 1 ]; then
|
|
jvdias |
18d1e1 |
if [[ "$ENABLE_ZONE_WRITE" = [yY1]* ]]; then
|
|
jvdias |
18d1e1 |
/bin/chown -f --from=root:named named:named $ROOTDIR/var/named
|
|
jvdias |
18d1e1 |
elif [[ "$ENABLE_ZONE_WRITE" = [nN0]* ]]; then
|
|
jvdias |
18d1e1 |
/bin/chown -f --from=named:named root:named $ROOTDIR/var/named
|
|
jvdias |
18d1e1 |
fi;
|
|
jvdias |
18d1e1 |
fi
|
|
cvsdist |
49d83b |
conf_ok=0;
|
|
jvdias |
31ab24 |
if [ -x /usr/sbin/named-checkconf ] && [ -x /usr/sbin/named-checkzone ] && /usr/sbin/named-checkconf $ckcf_options ${named_conf} >/dev/null 2>&1; then
|
|
cvsdist |
49d83b |
conf_ok=1;
|
|
cvsdist |
49d83b |
else
|
|
cvsdist |
49d83b |
RETVAL=$?;
|
|
cvsdist |
49d83b |
fi
|
|
cvsdist |
49d83b |
if [ $conf_ok -eq 1 ]; then
|
|
jvdias |
e9f83d |
daemon /usr/sbin/$named -u named ${OPTIONS};
|
|
cvsdist |
49d83b |
RETVAL=$?;
|
|
jvdias |
b7b41a |
if [ $RETVAL -eq 0 ]; then
|
|
jvdias |
aad908 |
rm -f /var/run/named.pid
|
|
jvdias |
e9f83d |
rm -f /var/run/named_sdb.pid 2>/dev/null
|
|
jvdias |
b7b41a |
ln -s $ROOTDIR/var/run/named/named.pid /var/run/named.pid;
|
|
jvdias |
e9f83d |
if [ "$named" = "named_sdb" ]; then
|
|
jvdias |
e9f83d |
ln -s $ROOTDIR/var/run/named/named.pid /var/run/named_sdb.pid;
|
|
jvdias |
e9f83d |
fi;
|
|
cvsdist |
668aac |
fi;
|
|
Martin Stransky |
66f119 |
if [ -n "`/sbin/pidof -o %PPID $named`" ]; then
|
|
Martin Stransky |
66f119 |
# Verify that named actually started (JM 2006-10-04)
|
|
Martin Stransky |
66f119 |
if [ ! -e $ROOTDIR/var/run/named/named.pid ]; then
|
|
Martin Stransky |
66f119 |
# If there is not a file containing the PID of the now running named daemon then create it (JM 2006-10-04)
|
|
Martin Stransky |
66f119 |
echo `/sbin/pidof -o %PPID $named` > $ROOTDIR/var/run/named/named.pid;
|
|
Martin Stransky |
66f119 |
if [ "$named" = "named_sdb" ]; then
|
|
Martin Stransky |
66f119 |
echo `/sbin/pidof -o %PPID $named` > $ROOTDIR/var/run/named/named_sdb.pid;
|
|
Martin Stransky |
66f119 |
fi;
|
|
Martin Stransky |
66f119 |
fi;
|
|
Martin Stransky |
66f119 |
fi;
|
|
jvdias |
b7b41a |
else
|
|
jvdias |
31ab24 |
named_err="`/usr/sbin/named-checkconf $ckcf_options $named_conf 2>&1`";
|
|
jvdias |
b7b41a |
echo
|
|
jvdias |
b7b41a |
echo $"Error in named configuration"':';
|
|
jvdias |
b7b41a |
echo "$named_err";
|
|
jvdias |
b7b41a |
failure
|
|
jvdias |
b7b41a |
echo
|
|
jvdias |
b7b41a |
if [ -x /usr/bin/logger ]; then
|
|
jvdias |
b7b41a |
echo "$named_err" | /usr/bin/logger -pdaemon.error -tnamed
|
|
jvdias |
b7b41a |
fi;
|
|
cvsdist |
49d83b |
return $RETVAL;
|
|
cvsdist |
49d83b |
fi;
|
|
cvsdist |
78e1f2 |
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named
|
|
cvsdist |
4f506d |
echo
|
|
cvsdist |
2f7f4b |
return $RETVAL
|
|
cvsdist |
2f7f4b |
}
|
|
cvsdist |
2f7f4b |
stop() {
|
|
cvsdist |
2f7f4b |
# Stop daemons.
|
|
jvdias |
e9f83d |
echo -n $"Stopping $named: "
|
|
jvdias |
aad908 |
/usr/sbin/rndc stop >/dev/null 2>&1
|
|
cvsdist |
2f7f4b |
RETVAL=$?
|
|
Martin Stransky |
28242b |
# is it still here?
|
|
Martin Stransky |
28242b |
if /sbin/pidof -o %PPID $named >/dev/null; then
|
|
Martin Stransky |
2e702b |
timeout=0
|
|
Martin Stransky |
2e702b |
while : ; do
|
|
Martin Stransky |
2e702b |
if /sbin/pidof -o %PPID $named >/dev/null; then
|
|
Martin Stransky |
2e702b |
if [ $timeout -ge $NAMED_SHUTDOWN_TIMEOUT ]; then
|
|
Martin Stransky |
2e702b |
killproc $named -TERM >/dev/null 2>&1
|
|
Martin Stransky |
2e702b |
RETVAL=$?
|
|
Martin Stransky |
28242b |
echo -n $"no response, killing with -TERM "
|
|
Martin Stransky |
2e702b |
break
|
|
Martin Stransky |
2e702b |
else
|
|
Martin Stransky |
2e702b |
sleep 2 && echo -n "."
|
|
Martin Stransky |
2e702b |
timeout=$((timeout+2))
|
|
Martin Stransky |
2e702b |
fi;
|
|
Martin Stransky |
2e702b |
else
|
|
Martin Stransky |
2e702b |
break
|
|
Martin Stransky |
2e702b |
fi;
|
|
Martin Stransky |
2e702b |
done
|
|
Martin Stransky |
2e702b |
fi;
|
|
Martin Stransky |
2e702b |
if [ $RETVAL -eq 0 ]; then
|
|
jvdias |
b7b41a |
rm -f /var/lock/subsys/named
|
|
Martin Stransky |
2e702b |
rm -f /var/run/named.pid
|
|
jvdias |
e9f83d |
rm -f /var/run/named_sdb.pid 2>/dev/null
|
|
jvdias |
b7b41a |
fi;
|
|
Martin Stransky |
511f41 |
if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
|
|
Martin Stransky |
511f41 |
if egrep -q '^/proc[[:space:]]+'${ROOTDIR}'/proc' /proc/mounts; then
|
|
Martin Stransky |
511f41 |
umount ${ROOTDIR}/proc >/dev/null 2>&1
|
|
Martin Stransky |
511f41 |
fi
|
|
Martin Stransky |
511f41 |
if [ $dbusEnabled -eq 1 ]; then
|
|
Martin Stransky |
511f41 |
if egrep -q '^/[^[:space:]]+[[:space:]]+'${ROOTDIR}'/var/run/dbus' /proc/mounts; then
|
|
Martin Stransky |
511f41 |
umount ${ROOTDIR}/var/run/dbus > /dev/null 2>&1
|
|
Martin Stransky |
511f41 |
fi;
|
|
Martin Stransky |
511f41 |
fi;
|
|
Martin Stransky |
511f41 |
fi;
|
|
jvdias |
b7b41a |
if [ $RETVAL -eq 0 ]; then
|
|
jvdias |
b7b41a |
success
|
|
jvdias |
b7b41a |
else
|
|
jvdias |
b7b41a |
failure
|
|
jvdias |
b7b41a |
fi;
|
|
jvdias |
b7b41a |
echo
|
|
cvsdist |
2f7f4b |
return $RETVAL
|
|
cvsdist |
2f7f4b |
}
|
|
cvsdist |
2f7f4b |
rhstatus() {
|
|
cvsdist |
366442 |
/usr/sbin/rndc status
|
|
cvsdist |
366442 |
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
|
|
cvsdist |
2f7f4b |
return $?
|
|
cvsdist |
2f7f4b |
}
|
|
cvsdist |
2f7f4b |
probe() {
|
|
cvsdist |
2f7f4b |
# named knows how to reload intelligently; we don't want linuxconf
|
|
cvsdist |
2f7f4b |
# to offer to restart every time
|
|
cvsdist |
aed712 |
/usr/sbin/rndc reload >/dev/null 2>&1 || echo start
|
|
cvsdist |
2f7f4b |
return $?
|
|
jvdias |
b7b41a |
}
|
|
jvdias |
b7b41a |
checkconfig() {
|
|
jvdias |
b7b41a |
ckcf_options='-z'; # enable named-checkzone for each zone (9.3.1+) !
|
|
jvdias |
b7b41a |
if [ -n "${ROOTDIR}" -a "x${ROOTDIR}" != "x/" ]; then
|
|
jvdias |
b7b41a |
OPTIONS="${OPTIONS} -t ${ROOTDIR}"
|
|
jvdias |
b7b41a |
ckcf_options="$ckcf_options -t ${ROOTDIR}";
|
|
jvdias |
b7b41a |
fi;
|
|
jvdias |
31ab24 |
if [ -x /usr/sbin/named-checkconf ] && [ -x /usr/sbin/named-checkzone ] && /usr/sbin/named-checkconf $ckcf_options ${named_conf} | cat ; then
|
|
jvdias |
b7b41a |
return 0;
|
|
jvdias |
b7b41a |
else
|
|
jvdias |
b7b41a |
return 1;
|
|
jvdias |
b7b41a |
fi
|
|
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)
|
|
cvsdist |
2f7f4b |
rhstatus
|
|
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 |
probe)
|
|
cvsdist |
2f7f4b |
probe
|
|
cvsdist |
2f7f4b |
;;
|
|
jvdias |
e9f83d |
checkconfig|configtest|check|test)
|
|
jvdias |
b7b41a |
checkconfig
|
|
jvdias |
b7b41a |
;;
|
|
cvsdist |
2f7f4b |
*)
|
|
cvsdist |
aed712 |
echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|probe}"
|
|
cvsdist |
2f7f4b |
exit 1
|
|
cvsdist |
2f7f4b |
esac
|
|
cvsdist |
2f7f4b |
|
|
cvsdist |
2f7f4b |
exit $?
|
|
cvsdist |
2f7f4b |
|