Pages

Thursday, February 18, 2021

GG Restart from crontab

=========================
General
=========================

 Restart GG processes from crontab

=========================
Code
=========================
crontab entry
1 06 1 * * /software/oracle/oracle/scripts/gg_restart/gg_restart_all_groups.sh

gg_restart_all_groups.sh
#!/bin/bash

WORK_HOME=/software/oracle/oracle/scripts/gg_restart
LOG_FILE=gg_restart.log

cd $WORK_HOME

./gg_restart_log.sh "${WORK_HOME}" "${LOG_FILE}" "START"

./gg_restart_group.sh EXT_S "ext ext_s*" "${WORK_HOME}" "${LOG_FILE}"
./gg_restart_group.sh EXT_P "ext ext_p*" "${WORK_HOME}" "${LOG_FILE}"
./gg_restart_group.sh EXT_I "ext ext_i*" "${WORK_HOME}" "${LOG_FILE}"

./gg_restart_group.sh DPM_S "ext dpm_s*" "${WORK_HOME}" "${LOG_FILE}"
./gg_restart_group.sh DPM_P "ext dpm_p*" "${WORK_HOME}" "${LOG_FILE}"
./gg_restart_group.sh DPM_I "ext dpm_i*" "${WORK_HOME}" "${LOG_FILE}"

./gg_restart_group.sh REP_S "rep rep_s*" "${WORK_HOME}" "${LOG_FILE}"
./gg_restart_group.sh REP_P "rep rep_p*" "${WORK_HOME}" "${LOG_FILE}"
./gg_restart_group.sh REP_I "rep rep_i*" "${WORK_HOME}" "${LOG_FILE}"

./gg_restart_log.sh "${WORK_HOME}" "${LOG_FILE}" "FINISH" 


gg_restart_log.sh

#!/bin/bash

WORK_HOME=$1
LOG_FILE_NAME=$2
VERB=$3

cd $WORK_HOME

LOG_FILE=${WORK_HOME}/${LOG_FILE_NAME}
RUN_DATE=`date "+%Y%m%d"_"%H%M%S"`

touch $LOG_FILE

if [[ $VERB == "START" ]]; then

 echo "" >>$LOG_FILE
 echo ========================================== >>$LOG_FILE
 echo Start at $RUN_DATE >>$LOG_FILE
 echo ========================================== >>$LOG_FILE
 echo "" >>$LOG_FILE
 echo "Before Restart: " >>$LOG_FILE
 echo "" >>$LOG_FILE 
 free -m >> $LOG_FILE
 echo "" >> $LOG_FILE
 sar -r >> $LOG_FILE
  echo "" >>$LOG_FILE 
fi

if [[ $VERB == "FINISH" ]]; then
  echo "" >>$LOG_FILE
  echo "---------------------------" >>$LOG_FILE
  echo "After Restart: " >>$LOG_FILE
  echo "---------------------------" >>$LOG_FILE  
  echo "" >>$LOG_FILE  
  free -m >> $LOG_FILE
  echo "" >> $LOG_FILE
  sar -r >> $LOG_FILE
  echo "" >>$LOG_FILE    
  echo ========================================== >>$LOG_FILE
  echo Finished at $RUN_DATE >>$LOG_FILE
  echo ========================================== >>$LOG_FILE
  echo "" >>$LOG_FILE
fi

exit 0 

gg_restart_group.sh
#!/bin/bash

GROUP_NAME=$1
RESTART_GROUP=$2
WORK_DIR=$3
LOG_FILE_NAME=$4

#GROUP_NAME=EXT_S
#RESTART_GROUP="ext ext_s*"

LOG_FILE=${WORK_DIR}/${LOG_FILE_NAME}


clear
echo "Restarting ${GROUP_NAME} ${RESTART_GROUP}" >> ${LOG_FILE}
echo "Log File is: ${LOG_FILE}"
exit 0

. /etc/profile > /dev/null 2> /dev/null
TEMP_LOG_FILE="/tmp/restart_temp.tmp"

RUN_DATE=`date "+%Y%m%d"_"%H%M%S"`

# Setting Oracle GoldenGate environments
if [ "$OGGSH" = "" ]; then
   OGGSH=$INFRA_ROOT/oggsh
fi

if [ "$ORACLE_SID" = "" ]; then
   INSTANCE=igt
else
   INSTANCE=$ORACLE_SID
fi
. $OGGSH/gg_login.sh $INSTANCE

touch $LOG_FILE
touch $TEMP_LOG_FILE

echo "" >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo Start Restart for ${GROUP_NAME} group ${RESTART_GROUP} at $RUN_DATE >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo "" >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo Initial State >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo "" >>$LOG_FILE

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOD
info all
exit
EOD
cat  $TEMP_LOG_FILE | grep ${GROUP_NAME} >>$LOG_FILE

echo about to do  "stop ext $RESTART_GROUP" >>$LOG_FILE

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOF
stop ${RESTART_GROUP}
exit
EOF
cat  $TEMP_LOG_FILE >>$LOG_FILE

echo "" >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo After Stop >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo "" >>$LOG_FILE

sleep 10

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOD
info all
exit
EOD
cat  $TEMP_LOG_FILE | grep ${GROUP_NAME}  >>$LOG_FILE


echo "Starting  ${RESTART_GROUP}" >> $LOG_FILE

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOF
start ${RESTART_GROUP}
exit
EOF
cat $TEMP_LOG_FILE >>$LOG_FILE

echo "" >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo After Start >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo "" >>$LOG_FILE

sleep 10

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOD
info all
exit
EOD
cat  $TEMP_LOG_FILE | grep ${GROUP_NAME} >>$LOG_FILE


NOT_RUNNING=`grep STOPPED $TEMP_LOG_FILE |grep ${GROUP_NAME} | wc -l`

if [ $NOT_RUNNING -gt 0 ]; then

echo "Some Processes were not started. Attempting restart" >>$LOG_FILE

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOF
start ${RESTART_GROUP}
exit
EOF
cat $TEMP_LOG_FILE >>$LOG_FILE

fi

#============================================================
# Second restart
#============================================================
sleep 10

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOD
info all
exit
EOD
cat  $TEMP_LOG_FILE | grep ${GROUP_NAME} >>$LOG_FILE

NOT_RUNNING=`grep STOPPED $TEMP_LOG_FILE | wc -l`
if [ $NOT_RUNNING -gt 0 ]; then

echo "Some Processes were not started. Attempting restart" >>$LOG_FILE

$GG_HOME/ggsci > $TEMP_LOG_FILE <<EOF
start ${RESTART_GROUP}
exit
EOF
cat $TEMP_LOG_FILE >>$LOG_FILE

sleep 10

$GG_HOME/ggsci >$TEMP_LOG_FILE <<EOD
info all
exit
EOD
cat  $TEMP_LOG_FILE | grep ${GROUP_NAME} >>$LOG_FILE

fi

echo "" >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo Finished Restart for $GROUP_NAME $RESTART_GROUP at $RUN_DATE >>$LOG_FILE
echo ========================================== >>$LOG_FILE
echo "" >>$LOG_FILE
 




No comments:

Post a Comment