|
#!/usr/bin/sh
#Thu Nov 28 16:33:50 EAT 2002
# Define variables
SID_NAME=test1
ORACLE_HOME=/oracle/product/8.1.7
LISTENER_NAME=LISTENER
LISTENER_PASS=
MONITOR_INTERVAL=10
PACKAGE_NAME=pkg1
TIME_OUT=40
set -A MONITOR_PROCESSES ora_pmon_${SID_NAME} ora_dbw0_${SID_NAME} ora_ckpt_${SID_NAME} ora_smon_${SID_NAME} ora_lgwr_${SID_NAME} ora_reco_${SID_NAME} tnslsnr
HOST=`hostname`
DATE=`date`
PATH=${ORACLE_HOME}/bin:/sbin:/usr/bin:/usr/sbin:/etc:/bin
export ORACLE_SID=${SID_NAME}
export ORACLE_HOME
ret=0
function oracle_run_cmds
{
su oracle -c "${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF
connect / as sysdba
startup
exit
EOF
ret=$?
if [[ $ret != 0 ]]
then
print "Oracle startup failed!"
return $ret
else
print "Oracle startup done."
fi
su oracle -c "${ORACLE_HOME}/bin/lsnrctl start ${LISTENER_NAME}"
ret=$?
if [[ $ret != 0 ]]
then
print "Oracle lsnrctl start failed! Stop instance [$ORACLE_SID]."
oracle_shutdown_cmds >/dev/null 2>&1
return 1
else
print "Oracle lsnrctl start done."
fi
}
function oracle_shutdown_cmds
{
ret=0
su oracle -c "${ORACLE_HOME}/bin/lsnrctl" <<EOF
set password ${LISTENER_PASS}
stop ${LISTENER_NAME}
exit
EOF
ret=$?
if [[ $ret != 0 ]]
then
print "Oracle lsnrctl stop failed!"
else
print "Oracle lsnrctl stop done."
fi
su oracle -c "${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF
connect / as sysdba
shutdown immediate
exit
EOF
ret=$?
if [[ $ret != 0 ]]
then
print "Oracle shutdown failed!"
return $ret
else
print "Oracle shutdown done."
fi
}
function oracle_abort_cmds
{
set -m
${0} kill &
KILL_PID=$!
su oracle -c "${ORACLE_HOME}/bin/lsnrctl" <<EOF
set password ${LISTENER_PASS}
stop ${LISTENER_NAME}
exit
EOF
su oracle -c "${ORACLE_HOME}/bin/sqlplus /nolog" <<EOF
connect / as sysdba
shutdown abort
exit
EOF
if [[ $? != 0 ]]
then
print "Oracle abort failed."
else
print "Oracle abort done."
fi
typeset -i c
typeset -i num_procs=${#MONITOR_PROCESSES[@]}
while true
do
for i in ${MONITOR_PROCESSES[@]}
do
ps -ef | grep ${i} | grep -v grep > /dev/null
if [[ $? != 0 ]]
then
print "\n *** ${i} process has stopped. ***\n"
c=0
while (( c < $num_procs ))
do
if [[ ${MONITOR_PROCESSES[$c]} = $i ]]
then
unset MONITOR_PROCESSES[$c]
c=$num_procs
fi
(( c = c + 1 ))
done
fi
done
if [[ ${MONITOR_PROCESSES[@]} = "" ]]
then
job=$(jobs | grep -v Done)
if [[ ${job} != "" ]]
then
print "Killing the kill_hung_processes script\n"
kill %1
fi
exit 0
fi
sleep 5
done
}
function terminate
{
print "This monitor script has been signaled to terminate\n"
exit
}
function kill_hung_processes
{
sleep ${TIME_OUT}
for i in ${MONITOR_PROCESSES[@]}
do
id=`ps -fu oracle | awk '/'${i}'/ { print $2 }'`
if [[ ${id} != "" ]]
then
kill -9 ${id}
if [[ $? != 0 ]]
then
print "\n *** ${0} kill_hung_processes function did NOT find process ***\n *** ${i} running. ***\n"
else
print "\n *** ${0} kill_hung_processes function did find process ***\n *** ${i} running. Sent SIGKILL. ***\n"
fi
else
print " *** kill_hung_processes function did NOT find ANY process running. ***\n"
fi
done
}
function monitor_processes
{
typeset -i n=0
for i in ${MONITOR_PROCESSES[@]}
do
MONITOR_PROCESSES_PID[$n]=`ps -fu oracle | awk '/'${i}'/ { print $2 }'`
print "Monitored process = ${i}, pid = ${MONITOR_PROCESSES_PID[$n]}"
|