Sophie

Sophie

distrib > Mageia > 1 > i586 > media > core-updates-src > by-pkgid > da5215faf967679904623e7047107846 > files > 23

bind-9.8.3P2-1.mga1.src.rpm

#!/bin/bash
#
# named           This shell script takes care of starting and stopping
#                 named (BIND DNS server).
#
# chkconfig: 345 55 45
# description: named (BIND) is a Domain Name Server (DNS) \
# that is used to resolve host names to IP addresses.
# probe: false

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: $named
# Required-Start: $network
# Required-Stop: $network
# Should-Start: mysqld postgresql ldap
# Should-Stop: mysqld postgresql ldap
# Default-Start:  3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop BIND
# Description: named (BIND) is a Domain Name Server (DNS).
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network

RETVAL=0
prog="named"

# Check that networking is up.
[ "${NETWORKING}" = "no" ] && exit 0

[ -f /etc/sysconfig/named ] && . /etc/sysconfig/named

[ -f /usr/sbin/named ] || exit 0

[ -f /var/lib/named/etc/named.conf ] || exit 0

start() {
        # Start daemons.
	if [ -n "`/sbin/pidof named`" ]; then
            gprintf "$prog: already running"
	    echo
            return 1
        fi
        gprintf "Starting %s: " $prog

	# prepare the chroot if needed
	[ -e /var/lib/named/dev/null ] || mknod -m 0666 /var/lib/named/dev/null c 1 3
	[ -e /var/lib/named/dev/random ] || mknod -m 0666 /var/lib/named/dev/random c 1 8
	[ -e /var/lib/named/dev/urandom ] || mknod -m 0666 /var/lib/named/dev/urandom c 1 8

	# better always copy localtime so it respects the system's timezone
	install -m 0644 -o root -g root /etc/localtime /var/lib/named/etc/

	# libgost.so needs to be in the chroot, so copy it there
	# first we need to find the lib for the right architecture
	BUILD_ARCH=@BUILD_ARCH@
	TABLE="$(rpm -ql --qf '%{ARCH}\n' --whatprovides openssl-engines)"
	ARCH_FOUND=0
	for i in $TABLE; do
		if [ $i = $BUILD_ARCH ]; then 
			ARCH_FOUND=1
		else
			if [ $ARCH_FOUND = 1 ]; then 
				if [ ${i%/libgost.so} != $i ]; then 
					LIBGOST=$i
					break
				fi
			fi
		fi
	done
	if [ -n "$LIBGOST" ]; then
		# copy everytime as we need to make sure everything is in sync
		CHROOT_LIBGOST=/var/lib/named/$LIBGOST
		mkdir -p "${CHROOT_LIBGOST%[/]*}" 
		cp -p $LIBGOST $CHROOT_LIBGOST
	fi

	[ -d /var/lib/named/proc ] || mkdir -p /var/lib/named/proc
	if ! egrep -q '^/proc[[:space:]]+'/var/lib/named'/proc' /proc/mounts; then
	    mount --bind /proc /var/lib/named/proc -o ro >/dev/null 2>&1
	fi

	daemon named -u named -t /var/lib/named ${OPTIONS}
	RETVAL=$?
 	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/named
	echo
	return $RETVAL
}
stop() {
	# Stop daemons.
        gprintf "Stopping %s: " $prog
	    /usr/sbin/rndc -c /var/lib/named/etc/rndc.conf stop "$1"
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named || {
            killproc named
            RETVAL=$?
            [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/named
            echo
            return $RETVAL
        }       

	if egrep -q '^/proc[[:space:]]+'/var/lib/named'/proc' /proc/mounts; then
	    umount /var/lib/named/proc >/dev/null 2>&1
	fi

        success
        echo
        return $RETVAL
}
status() {
	/usr/sbin/rndc -c /var/lib/named/etc/rndc.conf status
	return $?
}	
restart() {
	stop
	# wait a couple of seconds for the named to finish closing down
	sleep 2
	start
}	
reload() {
	/usr/sbin/rndc -c /var/lib/named/etc/rndc.conf reload "$1" >/dev/null 2>&1 || /usr/bin/killall -HUP named
	return $?
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop "$2"
		;;
	status)
		status
		;;
	restart)
		restart
		;;
	condrestart)
		[ -f /var/lock/subsys/named ] && restart
		;;
	reload)
		reload "$2"
		;;
	*)
        	gprintf "Usage: %s {start|stop|status|restart|condrestart|reload|probe}\n" $0
		exit 1
esac