Friday, June 8, 2012

Script to monitor and restart failed GoldenGate Processes

The below script should restart aborted GG processes.
The script is capable of restarting Manager, Extract and Replicat Processes.

The logic is it just looks at info all command (of ggsci) and attempts to restart any process which it sees as not RUNNING .
A non-running process can be either in STOPPED or ABORTED status.

It is intelligent enough to find out whether the stopped process is an extract, replicat or manager.

Please note I have used a script call ed /usr/local/bin/sid to set the env parameters. This script can be replaced by your own script or by setting env variables manually.



#!/bin/ksh
. /usr/local/bin/sid xxx
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export GG_HOME=/oracle/software/goldengate/11.1.1.1.2
export PATH=$PATH:.
MSGFILE="/tmp/mail.txt"
EMAILFILE="/tmp/email.txt"
SERVERNAME=`hostname`
rm -rf $EMAILFILE 2>/dev/null



cd $GG_HOME
ggsci <<EOF >$MSGFILE
info all
exit
EOF

ERROR_CTR=`cat $MSGFILE|grep -v -i "running"|wc -l`


#following loop is for manager process restart

if  [ $ERROR_CTR -ne 0 ] ; then

cat $MSGFILE|grep -v -i "running"|grep -i "manager"|while read LINE ;do

echo "Manager has aborted ">>$EMAILFILE
echo "Attempting to restart" >>$EMAILFILE


cd $GG_HOME
ggsci <<EOF >>$EMAILFILE
start mgr
info all
exit
EOF

done
fi

#following loop is for extract process restart


if  [ $ERROR_CTR -ne 0 ] ; then

cat $MSGFILE|grep -v -i "running"|grep -i "extract"|awk '  {print $3 } '|while read LINE ;do

echo "EXTRACT $LINE has aborted ">>$EMAILFILE
echo "attempting to restart" >>$EMAILFILE


cd $GG_HOME
ggsci <<EOF >>$EMAILFILE
start extract $LINE
info all
exit
EOF



done
fi

#following loop is for replicat process restart

if  [ $ERROR_CTR -ne 0 ] ; then

cat $MSGFILE|grep -v -i "running"|grep -i "replicat"|awk '  {print $3 } '|while read LINE ;do

echo "REPLICAT $LINE has aborted ">>$EMAILFILE
echo "Attempting to restart" >>$EMAILFILE


cd $GG_HOME
ggsci <<EOF >>$EMAILFILE
start replicat $LINE
info all
exit
EOF



done
fi


[ -f $EMAILFILE ] && cat $EMAILFILE|mailx -s "Extract died on $SERVERNAME" gautha@xxx.xxx

No comments:

Post a Comment