Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Sidebar 1
Sidebar 2 jul2006.tar

Listing 8 /etc/ha.d/mon/alert.d/db2inst_down.alert

			
/etc/ha.d/mon/alert.d/db2inst_down.alert

#!/bin/ksh -x

DB2HADRDBNAMES="WSI811"
ALERTMAILS="youremail@yourhost.com yourpager@yourpager.com"

. /etc/ha.d/shellfuncs

tempHost=$(echo $HOSTNAME)
 case $tempHost in
     db01.example.com)
     DB2INST=db2inst1;;
     db02.example.com)
     DB2INST=db2inst1;;
 esac
logger -i -p notice -t $0 "NOTICE: TRYING TO START THE INSTANCE"
echo "`date` :: db2inst_down.alert running" >> /var/log/hb.debug
su - $DB2INST -c "db2start"
if [[ $? = "0" ]];
then
    echo "`date` :: db2inst_down.alert started DB2" >> /var/log/hb.debug
    logger -i -p info -t $0 "INFO: DB2 INSTANCE HAS BEEN RESTARTED"

    for DB2HADRDBNAME in $DB2HADRDBNAMES
    do
     su - $DB2INST -c "db2 activate db $DB2HADRDBNAME"
     su - $DB@INST -c "db2 start hadr on db $DB2HADRDBNAME as primary"
     if [[ $? = "0" ]];
     then
      logger -i -p info -t $0 "INFO: $tempHost is primary for $DB2HADRDBNAME"
     else
      logger -i -p info -t $0 "ERROR: $tempHost FAILED to become \
        primary for $DB2HADRDBNAME"
     fi
    done
else
    echo "`date` :: db2inst_down.alert failed to start \
      DB2" >> /var/log/hb.debug
    logger -i -p ERROR -t $0 "ERROR: DB2 INSTANCE CAN NOT BE STARTED"
fi

# And yell, very loudly
/etc/ha.d/mon/alert.d/mail.alert -s db2inst -g $tempHost $ALERTMAILS