I found that exit codes are bad in other cases too :(.
If I do a bug in named.conf, init script returns
zero even it fails to start named!

sid:/etc/init.d# ./bind9 start; echo $?
Starting domain name service...: bind9 failed!
0

More changes are needed.
Attached is a better patch than original in the bugreport.
Best Regards
-- 
Zito
#!/bin/sh

### BEGIN INIT INFO
# Provides:          bind9
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Should-Start:      $network $syslog
# Should-Stop:       $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start and stop bind9
# Description:       bind9 is a Domain Name Server (DNS)
#        which translates ip addresses to and from internet names
### END INIT INFO

PATH=/sbin:/bin:/usr/sbin:/usr/bin

# for a chrooted server: "-u bind -t /var/lib/named"
# Don't modify this line, change or create /etc/default/bind9.
OPTIONS=""
RESOLVCONF=no

test -f /etc/default/bind9 && . /etc/default/bind9

test -x /usr/sbin/rndc || exit 0

. /lib/lsb/init-functions
DISTRO=$(lsb_release -is 2>/dev/null || echo Debian)
PIDFILE=/var/run/bind/run/named.pid

check_network() {
    if [ -x /usr/bin/uname ] && [ "X$(/usr/bin/uname -o)" = XSolaris ]; then
        IFCONFIG_OPTS="-au"
    else
        IFCONFIG_OPTS=""
    fi
    if [ -z "$(/sbin/ifconfig $IFCONFIG_OPTS)" ]; then
       #log_action_msg "No networks configured."
       return 1
    fi
    return 0
}

ret=0
case "$1" in
    start)
        log_daemon_msg "Starting domain name service..." "bind9"

        modprobe capability >/dev/null 2>&1 || true

        # dirs under /var/run can go away on reboots.
        mkdir -p /var/run/bind/run
        chmod 775 /var/run/bind/run
        chown root:bind /var/run/bind/run >/dev/null 2>&1 || true

        if [ ! -x /usr/sbin/named ]; then
            log_action_msg "named binary missing - not starting"
            log_end_msg 1
            exit 1
        fi

        if ! check_network; then
            log_end_msg 1
            exit 1
        fi

        if start-stop-daemon --start --oknodo --quiet --exec /usr/sbin/named \
                --pidfile ${PIDFILE} -- $OPTIONS; then
            if [ "X$RESOLVCONF" != "Xno" ] && [ -x /sbin/resolvconf ] ; then
                echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.named
            fi
            log_end_msg 0
        else
            ret=$?
            log_end_msg 1
        fi
    ;;

    stop)
        log_daemon_msg "Stopping domain name service..." "bind9"
        if ! check_network; then
            log_end_msg 1
            exit 1
        fi

        if [ "X$RESOLVCONF" != "Xno" ] && [ -x /sbin/resolvconf ] ; then
            /sbin/resolvconf -d lo.named
        fi
        pid=$(/usr/sbin/rndc stop -p | awk '/^pid:/ {print $2}')
        if [ -n "$pid" ]; then
          while kill -0 $pid 2>/dev/null; do
            log_progress_msg "waiting for pid $pid to die"
            sleep 1
          done
        fi
        log_end_msg $?
    ;;

    reload|force-reload)
        log_daemon_msg "Reloading domain name service..." "bind9"
        if ! check_network; then
            log_end_msg 1
            exit 1
        fi

        /usr/sbin/rndc reload >/dev/null
        ret=$?
        log_end_msg $?
    ;;

    restart)
        if ! check_network; then
            exit 1
        fi

        $0 stop
        $0 start
        ret=$?
    ;;
    
    status)
        status_of_proc -p ${PIDFILE} /usr/sbin/named bind9 2>/dev/null
        ret=$?
        ;;

    *)
        log_action_msg "Usage: /etc/init.d/bind9 
{start|stop|reload|restart|force-reload|status}"
        exit 1
    ;;
esac

exit $ret
diff --git a/init.d/bind9 b/init.d/bind9
index a4c55e8..4558b35 100755
--- a/init.d/bind9
+++ b/init.d/bind9
@@ -41,6 +41,7 @@ check_network() {
     return 0
 }
 
+ret=0
 case "$1" in
     start)
 	log_daemon_msg "Starting domain name service..." "bind9"
@@ -70,6 +71,7 @@ case "$1" in
 	    fi
 	    log_end_msg 0
 	else
+	    ret=$?
 	    log_end_msg 1
 	fi
     ;;
@@ -102,6 +104,7 @@ case "$1" in
 	fi
 
 	/usr/sbin/rndc reload >/dev/null
+	ret=$?
 	log_end_msg $?
     ;;
 
@@ -112,11 +115,12 @@ case "$1" in
 
 	$0 stop
 	$0 start
+	ret=$?
     ;;
     
     status)
-    	ret=0
-	status_of_proc -p ${PIDFILE} /usr/sbin/named bind9 2>/dev/null || ret=$?
+	status_of_proc -p ${PIDFILE} /usr/sbin/named bind9 2>/dev/null
+	ret=$?
 	;;
 
     *)
@@ -125,4 +129,4 @@ case "$1" in
     ;;
 esac
 
-exit 0
+exit $ret

Reply via email to