Listing 3 /etc/ha.d/resources.d/hadr
/etc/ha.d/resources.d/hadr
#/bin/ksh
. /etc/ha.d/shellfuncs
DB2HADRDBNAMES="WSI811"
temp_log_file=/source/scripttemp.out
temp_stat_file=/source/scripttemp.stat
touch $temp_log_file > /dev/null 2> /dev/null
chmod a+w $temp_log_file > /dev/null 2> /dev/null
touch $temp_stat_file > /dev/null 2> /dev/null
chmod a+w $temp_stat_file > /dev/null 2> /dev/null
echo "`date` :: hadr(.sh) running" >> /var/log/hb.debug
tempHost=$(echo $HOSTNAME)
case $tempHost in
db01.example.com)
DB2INST=db2inst1;;
db02.example.com)
DB2INST=db2inst1;;
esac
echo "tempHost=$tempHost "
for DB2HADRDBNAME in $DB2HADRDBNAMES
do
echo "xxxxxxxxxxxxxxxxxxx $1 xxxxxxxxxxxxxxx"
case "$1" in start)
hadrRole=$(su - $DB2INST -c "db2 get snapshot for all on \
$DB2HADRDBNAME" |grep -i "Role" |awk '{print $3 }')
echo $hadrRole >> $temp_log_file
echo "`date` :: hadr(.sh) starting" >> /var/log/hb.debug
if [[ $hadrRole = "Standby" ]];
then
echo "`date` :: hadr(.sh) taking over" >> /var/log/hb.debug
logger -i -p notice -t $0 "su - $DB2INST -c db2 takeover hadr \
on db $DB2HADRDBNAME"
su - $DB2INST -c "db2 takeover hadr on db \
$DB2HADRDBNAME >> $temp_log_file" > /dev/null
if [[ $? = "0" ]];
then
logger -i -p info -t $0 "Info: db2 takeover succeed "
else
echo "`date` :: hadr(.sh) forcing takeover" >> /var/log/hb.debug
logger -i -p notice -t $0 "su - $DB2INST -c db2 takeover hadr \
on db $DB2HADRDBNAME by force"
su - $DB2INST -c "db2 takeover hadr on db $DB2HADRDBNAME \
by force >> $temp_log_file" > /dev/null
if [[ $? = "0" ]];
then
logger -i -p notice -t $0 "Notice: Takeover by force is succeed"
else
logger -i -p err -t $0 "ERROR: Takeover by force failed"
fi
fi
else
echo "`date` :: hadr(.sh) already running primary" >> /var/log/hb.debug
logger -i -p notice -t $0 "Notice: Primary hadrdb is running \
on this node"
fi;;
stop)
echo "`date` :: hadr(.sh) stopping" >> /var/log/hb.debug
logger -i -p notice -t $0 "Notice: stop the heartbeat";;
status)
logger -i -p notice -t $0 "Notice: get $DB2HADRDBNAME status....."
echo "---- $DB2HADRDBNAME Status -------" >> $temp_stat_file
echo $HOSTNAME >> $temp_stat_file
echo "" >> $temp_stat_file
su - $DB2INST -c "db2 get snapshot for all on $DB2HADRDBNAME" \
|grep -A14 "HADR Status" >> $temp_stat_file
#
cat $temp_stat_file 1>&2
rm -f $temp_stat_file;;
esac
done
exit 0
|