在HP Unix上安装MC软件来运行Oracle 10G双机(7)oracle10g.sh内容

详细内容见扩展,用的时候需要Dos to Unix[@more@]#*****************************************************************************
#Oracle相关变量
ORA_ver=10_2_0
SID_NAME=ora
ORACLE_HOME=/db0/product/10.2.0
LISTENER=yes
LISTENER_NAME=${SID_NAME}#LISTENER_NAME=LSNR_${SID_NAME}
LISTENER_PASS=
MONITOR_INTERVAL=30
MONITOR2_INTERVAL=5
PACKAGE_NAME=ora
TIME_OUT=30
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}
LISTENERDIR=/db0/product/10.2.0/network/admin
LISTENERORA=/etc/cmcluster/ora/listener.ora
HOST=`uname-n`
DATE=`date`
PATH=${ORACLE_HOME}/bin:/sbin:/usr/bin:/usr/sbin:/etc:/bin
export ORACLE_SID=${SID_NAME}
export ORACLE_HOME
#########################################################################
######
#########################################################################
######
#Function:oracle_run_cmds
#
#Start the ORACLE instance defined in the environment variables ORACLE_HOME
#and SID_NAME.
#########################################################################
######
#Oracle启动函数
function oracle_run_cmds
{
#The Oracle initialization file(init${SID_NAME}.ora)can contain node
#specific information.A large memory configuration might not run on a
#smaller backup system so you might need to create node specific
#configuration files as shown below:
#
#${ORACLE_HOME}/dbs/init${SID_NAME}.ora.${HOST}
#Note:You must have node specific files for ALL NODES in the cluster.
#PFILE=${ORACLE_HOME}/dbs/init${SID_NAME}.ora
#if[[-f${PFILE}.${HOST}]]
#then
#PFILE=${PFILE}.${HOST}
#fi
#Make sure that the configuration file exists.If not,then the
#database cannot be started on this node.
#if[[!-f${PFILE}]]
#then
#print"ORACLE:The file${PFILE}does not exist."
#print"tERROR:Failed to start Oracle database."
#exit 1
#fi
#Startup Oracle.
#These commands will not return any error codes;therefore,anything
#that fails after this point will cause a failover to another node.
#
case$ORA_ver in
10_2_0)su oracle-c"${ORACLE_HOME}/bin/sqlplus'/as sysdba'"<startup
#pfile=${PFILE}
exit
EOF
if[[$?!=0]]
then
print"Oracle startup failed."
else
print"Oracle startup done."
fi
;;
*)
print"Oracle startup failed,check configuration variables."
;;
esac
#Start the listener process.
case$LISTENER in
yes)
cp/etc/cmcluster/ora/listener.ora/oracle/product/10.2.0/network/admin
su oracle-c"${ORACLE_HOME}/bin/lsnrctl start"
if[[$?!=0]]
then
print"Oracle lsnrctl start failed."
else
print"Oracle lsnrctl start done."
fi
;;
*)
print"Not starting the listener,configured not to start."
;;
esac
}
#########################################################################
######
#Function:oracle_shutdown_cmds
#
#Shutdown Oracle using the shutdown immediate command.
#This will do a clean shutdown of the database.
#Do NOT use'cmhaltpkg'to shutdown the database as'cmhaltpkg'
#does a database abort and all transactions in memory will be lost.
#########################################################################
######
#Oracle停止函数
function oracle_shutdown_cmds
{
case$ORA_ver in
10_2_0)su oracle-c"${ORACLE_HOME}/bin/sqlplus'/as sysdba'"<shutdown immediate
exit
EOF
if[[$?!=0]]
then
print"Oracle shutdown failed."
else
print"Oracle shutdown done."
fi
;;
*)
print"Oracle shutdown failed,check configuration variables."
;;
esac
su oracle-c"${ORACLE_HOME}/bin/lsnrctl stop"
}
#########################################################################
######
#Function:oracle_abort_cmds
#
#Recursively call this script with the"kill"option to terminate any process
#that will not die normally after waiting for the TIME_OUT period.
#########################################################################
######
#Oracle中止函数
function oracle_abort_cmds
{
#Something is wrong so we will abort.If you wish to shutdown the database
#without an abort,you must manually execute"${SID_NAME}.sh shutdown"from
#the command line instead of using cmhaltpkg."Abort"is used because
#"immediate"and"normal"will wait for all users to log off and they are
#not deterministic.
#
#Call this script with the kill option to terminate any process that will
#not die normally after waiting for the TIME_OUT period.
set-m
${0}kill&
#Stop Oracle process.
case$ORA_ver in
10_2_0)
su oracle-c"${ORACLE_HOME}/bin/sqlplus'/as sysdba'"<shutdown abort
exit
EOF
if[[$?!=0]]
then
print"Oracle abort failed."
else
print"Oracle abort done."
fi
;;
esac
#Stop the listener process for Oracle.
su oracle-c"${ORACLE_HOME}/bin/lsnrctl stop"
#case$LISTENER in
#yes)
#su oracle-c${ORACLE_HOME}/bin/lsnrctl<#set password${LISTENER_PASS}
#stop${LISTENER_NAME}
#exit
#EOF
#;;
#esac
#Make sure all processes have gone away before determining that shutdown
is
#complete.This stops the other node from starting up the package before
it
#has been stopped and the file system has been unmounted.
typeset-i c
typeset-i num_procs=${#MONITOR_PROCESSES[@]}
while true
do
for i in${MONITOR_PROCESSES[@]}
do
id=`ps-fu oracle|awk'/'${i}$'/{print$2}'`#JAGad06432
if[[${id}=""]]#JAGad06432
then
print"n***${i}process has stopped.***n"
c=0
while((cdo
if[[${MONITOR_PROCESSES[$c]}=$i]]
then
unset MONITOR_PROCESSES[$c]
c=$num_procs
fi
((c=c+1))
done
fi
done
if[[${MONITOR_PROCESSES[@]}=""]]
then
#The shutdown was successful;therefore,get rid of the script(which
#was started earlier)to kill any existing hung processes.Check
to
#see if the script is still running.If the result from the'job'
#command indicates that the script is done,then there is no need
#to kill it.
job=$(jobs|grep-v Done)
if[[${job}!=""]]
then
print"Killing the kill_hung_processes scriptn"
kill%1
fi
exit 0#fix for 1653287920
fi
sleep 5
done
}
#########################################################################
######
#Function:kill_hung_processes
#
#If the database is hung,spawn a background process that will issue a
#a SIGKILL to each of the monitored processes.This allows us to guarantee
#a time limit for clean halt attempts.
#########################################################################
######
#杀掉挂起进程
function kill_hung_processes
{
#Wait for the TIME_OUT period before sending a kill signal.The TIME_OUT
#value should be less than the MC/Serviceguard package time-out.
sleep${TIME_OUT}
for i in${MONITOR_PROCESSES[@]}
do
id=`ps-fu oracle|awk'/'${i}$'/{print$2}'`#JAGad06432
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
}
#
*************************************************************************
****
#return code
#0-succeed
#1-fail
#
*************************************************************************
****
#监控Oracle监听是否启动
function monitor_listener
{
su-oracle-c"${ORACLE_HOME}/bin/lsnrctl status
${ORACLE_LISTENER_NAME}">/dev/null
if[$?=0]
then
MONITOR_PROCESSES_PID=`ps-fu oracle|grep tnslsnr|awk'{print
$2}'`
print"Monitored process=tnslsnr,pid=${MONITOR_PROCESSES_PID}"
>>${LOG_FILE}
return 0
fi
su-oracle-c"${ORACLE_HOME}/bin/lsnrctl start
${ORACLE_LISTENER_NAME}">/dev/null
if[$?=0]
then
MONITOR_PROCESSES_PID=`ps-fu oracle|grep tnslsnr|awk'{print
$2}'`
print"Monitored process=tnslsnr,pid=${MONITOR_PROCESSES_PID}"
>>${LOG_FILE}
print"n***listener has restarted.***">>${LOG_FILE}
return 0
fi
print"n***listener has failed.Aborting Oracle.***">>${LOG_FILE}
return 1
}
#########################################################################
######
#Function:monitor_processes
#
#Monitor the Oracle processes by making sure that all required processes are
#running.
#########################################################################
#####
#监视函数。监视Oracle相关进程。
function monitor_processes
{
typeset -i n=0
for i in ${MONITOR_PROCESSES[@]}
do
MONITOR_PROCESSES_PID[$n]=`ps -fu oracle | awk '/'${i}$'/ {print$2}'`
#JAGad06432
print "Monitored process = ${i},pid = ${MONITOR_PROCESSES_PID[$n]}"
if [ [ ${MONITOR_PROCESSES_PID[$n]} = "" ] ]
then
print "nn"
ps -ef
print "n***${i} has failed at startup time.Aborting Oracle.***"
set -m
nohup ${0} fault& #The script calls itself with the fault option.
set +m
sleep 999999
fi
((n=n+1))
done
sleep${MONITOR_INTERVAL}
while true
do
for i in${MONITOR_PROCESSES_PID[@]}
do
kill -s 0${i} > /dev/null
if [ [ $? != 0 ] ]
then
print "nn"
ps -ef
print "n***${i}has failed.Aborting Oracle.***"
set -m
nohup ${0} fault& #The script calls itself with the fault option.
set +m
sleep 999999
fi
done
monitor_listener
if [ $? = 1 ]
then
print "n Listener has failed.Aborting Oracle.***"
set -m
nohup ${0} fault& #The script calls itself with the fault option.
set +m
sleep 999999
fi
sleep ${MONITOR_INTERVAL}
done
}
#监视用户是否可以连接。注意修改用户名密码
function monitor_processes2
{
while true
do
su oracle -c "${ORACLE_HOME}/bin/sqlplus system/oracle" <WHENEVER SQLERROR EXIT 1
select 'success' from dual;
exit
EOF
if [ [ $? != 0 ] ]
then
print "Connect to oracle failed."
set -m
nohup ${0} fault& #The script calls itself with the fault option.
set +m
sleep 999999
else
print "Connected to oracle."
fi
sleep ${MONITOR2_INTERVAL}
done
}
###############################################################################
#Function:halt_package#
#Because there is no move command in MC/Serviceguard,the package must first
#be halted,disabled from running on the host,and then enabled to run in the
#cluster.
###############################################################################
#中止包函数
function halt_package
{
cmhaltpkg ${PACKAGE_NAME}
cmmodpkg -d -n ${HOST}${PACKAGE_NAME}
sleep 1
cmmodpkg -e ${PACKAGE_NAME}
}
#########################################################################
######
#MAIN
#
#Check the command-line option and take the appropriate action.
#########################################################################
######
print "n***$0 called with$1 argument.***n"
case$1 in
fault)
halt_package
;;
kill)
kill_hung_processes
;;
monitor)
monitor_processes"
oracle_run_cmds
;;
halt)
print "n"${HOST}":Aborting Oracle SESSION$SID_NAME at${DATE}"
oracle_abort_cmds
;;
shutdown)
print "n"${HOST}":Shutting down Oracle SESSION$SID_NAME at${DATE}"
oracle_shutdown_cmds
;;
*)
print "Usage:${0}[shutdown|halt|start|monitor]"
;;
esac

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/41451/viewspace-1047907/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/41451/viewspace-1047907/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值