Article Listing 1 oct2006.tar

Listing 1 qguard

#!/usr/bin/ksh

#no guarantees whatsoever (<--this is a disclaimer)
#peter van der weerd 2004
#
INFRASTRUCTURE=/etc/cluster/ccr/infrastructure
SCDIDADM=/usr/cluster/bin/scdidadm
SCCONF=/usr/cluster/bin/scconf
DIDFILE=/tmp/didfile
SCDPM=/usr/cluster/bin/scdpm
QUORUMSET=0
AVAILABLEDISKS=/tmp/availabledisks

#first determine current quorumdisk
QUORUM=`grep gdevname $INFRASTRUCTURE| awk '{print $2}' | cut -f5 \
  -d"/" | cut -c1,2 `

#write to syslog 
logger "quorum-rg started or switched"
logger "current quorumdevice is $QUORUM"

#monitor the quorumdevice
while true
do
    #build list of all devices with scdpm
     #this list is used to determine whether new quorum is ok or 
     #failed already
    $SCDPM -p all:all |grep -v Fail > $AVAILABLEDISKS
    #check status of current quorumdisk
    if $SCDPM -p all:$QUORUM | grep Fail
    then
        logger $QUORUM Quorumdisk broken

        #find the next available quorumdisk i.e. find a shared device
        $SCDIDADM -L | grep -v $QUORUM | awk '{print $3}' > $DIDFILE 
        
        CURRENT=`head -1 $DIDFILE`
        for i in `tail +2 $DIDFILE`
        do
            NEXT=$i
            if test $CURRENT = $NEXT -a $QUORUMSET = 0
            then
                if grep $CURRENT $AVAILABLEDISKS
                then
                    logger "$CURRENT is in $AVAILABLEDISKS    "
                    logger "$CURRENT is available to become quorum"
                    NEWQUORUM=`echo $CURRENT|cut -f5 -d"/"`
                    $SCCONF -a -q globaldev=$NEWQUORUM
                    logger "new quorumdevice chosen $NEWQUORUM"
                    OLDQUORUM=$QUORUM
                    $SCCONF -r -q globaldev=$OLDQUORUM
                    logger "broken quorumdevice removed $OLDQUORUM"
                    QUORUMSET=1
                fi    

            else
                    CURRENT=$NEXT 
               fi
        done
        #write to syslog that no available devices were found
        #otherwise set up for a new round and report to syslog
        if test $QUORUMSET = 0
                then
          logger "No available devices for the new quorum..."
          logger "The cluster is in degraded state..."
          logger "You are in trouble!"
        else
          QUORUM=`grep gdevname $INFRASTRUCTURE| awk \
            '{print $2}' | cut -f5 -d"/" | cut -c1,2 `
          logger "successfully chosen new quorumdevice $QUORUM"
          QUORUMSET=0
        fi
    fi
sleep 300
done