Hi,

please consider the attached re-worked init script for the
authoritative server. It does away with the twisted backwards
NOTRUNNING variable which has confused me multiple times in the past.

doPC now returns a meaningful string if pdns is not running, which
eases the use of doPC in the big case, allowing the script to just
print $ret even in the "not running" case, and the pdns_running
function allows idioms like "if pdns_running; then".

Please test before committing, it is currently in the state "works for
me", and only on two test boxes

Greetings
Marc

-- 
-----------------------------------------------------------------------------
Marc Haber         | "I don't trust Computers. They | Mailadresse im Header
Mannheim, Germany  |  lose things."    Winona Ryder | Fon: *49 621 31958061
Nordisch by Nature |  How to make an American Quilt | Fax: *49 621 31958062
#!/bin/sh
# chkconfig: - 80 75
# description: PDNS is a versatile high performance authoritative nameserver

### BEGIN INIT INFO
# Provides:          pdns
# Required-Start:    $remote_fs $network $syslog
# Required-Stop:     $remote_fs $network $syslog
# Should-Start:      $all
# Should-Stop:       $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop PowerDNS authoritative server
# Description:       Start/stop PowerDNS authoritative server
### END INIT INFO

set -e

prefix=/usr
exec_prefix=${prefix}
BINARYPATH=${exec_prefix}/bin
SBINARYPATH=${exec_prefix}/sbin
SOCKETPATH=/var/run

[ -f "$SBINARYPATH/pdns_server" ] || exit 0

[ -r /etc/default/pdns ] && . /etc/default/pdns

cd $SOCKETPATH
suffix=`basename $0 | cut -d- -f2- -s`
if [ $suffix ] 
then
        EXTRAOPTS=--config-name=$suffix
        PROGNAME=pdns-$suffix
else
        PROGNAME=pdns
fi

pdns_server="$SBINARYPATH/pdns_server $EXTRAOPTS"

doPC()
{
        if ! ret=$($BINARYPATH/pdns_control $EXTRAOPTS $1 $2 2> /dev/null); then
          ret="not running"
        fi
}

pdns_running()
{
        doPC ping
        if [ "$ret" = "not running" ]; then
          return 1
        else
          return 0
        fi
}

case "$1" in
        status)
                doPC status
                echo $ret
        ;;      

        stop)
                echo -n "Stopping PowerDNS authoritative nameserver: "
                doPC quit
                echo $ret
        ;;              


        force-stop)
                echo -n "Stopping PowerDNS authoritative nameserver: "
                killall -v -9 pdns_server
                echo "killed"
        ;;

        start)
                echo -n "Starting PowerDNS authoritative nameserver: "
                if pdns_running; then
                        echo "already running"
                else
                        if $pdns_server --daemon --guardian=yes; then
                                echo "started"
                        else
                                echo "error starting"
                        fi
                fi 
        ;;              

        force-reload | restart)
                echo -n "Restarting PowerDNS authoritative nameserver: "
                echo -n stopping and waiting.. 
                doPC quit
                sleep 3
                echo done
                $0 start
        ;;

        reload) 
                echo -n "Reloading PowerDNS authoritative nameserver: "
                if pdns_running; then
                        doPC cycle
                        echo requested reload
                else
                        echo not running yet
                        $0 start
                fi 
        ;;              
                
        monitor)
                if pdns_running; then 
                        echo "already running"
                else
                        $pdns_server --daemon=no --guardian=no 
--control-console --loglevel=9
                fi 
        ;;              

        dump)
                doPC list
                echo $ret
        ;;              

        show)
                if [ $# -lt 2 ]
                then
                        echo Insufficient parameters
                        exit
                fi
                echo -n "$2="
                doPC show $2
                echo $ret
        ;;              

        mrtg)
                if [ $# -lt 2 ]
                then
                        echo Insufficient parameters
                        exit
                fi 
                if pdns_running; then
                        doPC show $2 ; echo $ret
                        if [ "$3x" != "x" ]
                        then
                                doPC show $3 ; echo $ret
                        else
                                echo 0
                        fi
                        doPC uptime ; echo $ret
                        echo PowerDNS daemon
                else
                        echo "not running"
                fi 
        
        ;;              

        cricket)
                if [ $# -lt 2 ]
                then
                        echo Insufficient parameters
                        exit
                fi
                doPC show $2
                echo $ret
        
        ;;              



        *)
        echo pdns 
[start\|stop\|force-reload\|reload\|restart\|status\|dump\|show\|mrtg\|cricket\|monitor]

        ;;
esac


_______________________________________________
Pdns-dev mailing list
[email protected]
http://mailman.powerdns.com/mailman/listinfo/pdns-dev

Reply via email to