shell(三)-数据库启停脚本
【摘要】 #!/usr/bin/sh# VERSION="@(#)B5139DA (11.x):"# "@(#) B.01.08 $Revision: 2.00 $ $Date: 02/02/21 10:18:02 $"# *****************************************************************************# ******** S...
#!/usr/bin/sh # VERSION="@(#)B5139DA (11.x):" # "@(#) B.01.08 $Revision: 2.00 $ $Date: 02/02/21 10:18:02 $" # ***************************************************************************** # ******** Startup, Shutdown and Monitor Script for ORACLE (Template) ********* # ***************************************************************************** # ********** Note: This file MUST be edited before it can be used. ************ # ***************************************************************************** # # ***************************************************************************** # * This script supports Oracle 9i only. * # * For Oracle 7 or 8, use the ORACLE_7_8.sh script. * # ***************************************************************************** # # This script executes one Oracle instance only. If you are running more than # one instance on a node, it must be duplicated for each instance. This script # should be edited and moved to "/etc/cmcluster/${SID_NAME}/${SID_NAME}.sh", # where ${SID_NAME} is the name of the Oracle instance. Consult the README # file for more information. # # Environment Variables: # # ORA_ver: To run Oracle 9i (9.0.1). # Set the variable: ORA_ver=9_0_1 # If you are running a prior version of Oracle please # use the correct version of this template. # # SID_NAME: The Oracle session name. This is sometimes called the # session ID (SID). # # ORACLE_HOME: The home directory of Oracle. # # LISTENER: Set to "yes" if you want this template to start/stop # the Listener # # LISTENER_NAME: The name of the listener process. # # LISTENER_PASS: The password of the listener process. (optional) # # MONITOR_INTERVAL: The time interval, in seconds, that this script will # wait between checks that the Oracle database is # running. # # MONITOR_PROCESSES: The names of all processes that must be executing to # assume this Oracle instance is up and running. # # PACKAGE_NAME: The name of the package as defined in the # MC/ServiceGuard package configuration file. # # TIME_OUT: The amount of time, in seconds, to wait for the Oracle # abort to complete before killing the Oracle processes # defined in MONITOR_PROCESSES. The TIME_OUT variable is # used to protect against a worst case scenario where a # hung database prevents the halt script from completing, # therefore preventing the standby node from starting the # database. The value of TIME_OUT must be less than the # time-out set in the package configuration file. This # variable has no effect package failover times. # # Examples: # # ORA_ver=9_0_1 # SID_NAME=owas # ORACLE_HOME=/mnt1/base/app/oracle/product/9.0.1 # LISTENER=yes # LISTENER_NAME=LSNR_${SID_NAME} # LISTENER_PASS=1DF5C2FD0FE9CFA2 # MONITOR_INTERVAL=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} ora_arc0_${SID_NAME} # PACKAGE_NAME=dbs # TIME_OUT=30 # ############################################################################### ORA_ver=10_2_0 SID_NAME=bpayl1 ORACLE_BASE=/ora10grun/app/oracle ORACLE_HOME=${ORACLE_BASE}/product/10.2.0 LISTENER=yes LISTENER_NAME=bpayl1 #LISTENER_PASS= MONITOR_INTERVAL=30 PACKAGE_NAME=ayzgdb_pkg 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} set -A MONITOR_PROCESSES HOSTNAME=`hostname` DATE=`date` PATH=${ORACLE_HOME}/bin:/sbin:/usr/bin:/usr/sbin:/etc:/bin export SHLIB_PATH=${ORACLE_HOME}/lib:${ORACLE_HOME}/rdbms/lib:${ORACLE_HOME}/lib32:${ORACLE_HOME}/rdbms/lib32 export ORACLE_SID=${SID_NAME} export ORACLE_BASE export ORACLE_HOME ############################################################################### ############################################################################### # Function: oracle_run_cmds # # Start the ORACLE instance defined in the environment variables ORACLE_HOME # and SID_NAME. ############################################################################### 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_BASE}/product/10.2.0/dbs/spfiletjprod.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) echo $HOSTNAME if [[ $HOSTNAME = "ayzgdb" ]] then route add net 179.196.173.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.200.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.50.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.130.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.135.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.124.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.80.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.48.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.75.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.100.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.30.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.40.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.205.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.175.0 netmask 255.255.255.0 10.17.133.254 1 route add net 179.196.140.0 netmask 255.255.255.0 10.17.133.254 1 su - orarun -c /home/orarun/scripts/startdb_bpayl1.sh if [[ $? != 0 ]] then print "Oracle on ayzgdb startup failed." else print "Oracle on ayzgdb startup done." fi elif [[ $HOSTNAME = "ayzgapp" ]] then su - xcomrun -c stopxcom.sh #su - bpayl1 -c "tmshutdown -y" sleep 1 su - bpayl1 -c /BSMesWare/BPAYL1/Bin/tuxedo_force_shutdown sleep 3 su - orarun -c /home/orarun/scripts/startdb_bpayl1.sh if [[ $? != 0 ]] then print "Oracle on ayzgapp startup failed." else print "Oracle on ayzgapp startup done." su - bpayl1 -c "tmboot -y" su - xcomrun -c startxcom.sh fi fi ;; *) print "Oracle startup failed, check configuration variables." ;; esac # Start the listener process. #case $LISTENER in #yes ) #su orarun -c "${ORACLE_HOME}/bin/lsnrctl start ${LISTENER_NAME}" # if [[ $? != 0 ]] # then # print "Oracle lsnrctl start failed." # else # print "Oracle lsnrctl start done." # sleep 30 # cmhaltpkg ayzgapp_pkg # sleep 5 # cmrunpkg -n ayzgapp ayzgapp_pkg # cmmodpkg -e ayzgapp_pkg # fi #;; #*) # print "Not starting the listener, configured not to start." #;; #esac # AP_STATUS=`cmviewcl | grep ayzgapp_pkg| awk '{ print $2 }'` # if [[ ${AP_STATUS} = "starting" ]] # then # print "Waiting pkgapp up, then restart it ..." # sleep 60 # cmhaltpkg pkgapp # sleep 2 # cmmodpkg -e pkgapp # elif [[ ${AP_STATUS} = "up" ]] # if [[ ${AP_STATUS} = "up" ]] # then # print "Restart tuxedo ..." # cmhaltpkg pkgapp # sleep 2 # cmmodpkg -e pkgapp # fi } ############################################################################### # 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. ############################################################################### function oracle_shutdown_cmds { case $ORA_ver in 10_2_0) echo $HOSTNAME sleep 20 if [[ $HOSTNAME = "ayzgdb" ]] then remsh ayzgapp "su - bpayl1 -c /BSMesWare/BPAYL1/Bin/tuxedo_force_shutdown" su - bpayl1 -c /BSMesWare/BPAYL1/Bin/tuxedo_force_shutdown su - xcomrun -c stopxcom.sh kill -9 `ps -ef | grep -v grep | grep ora | grep "LOCAL=NO" | awk '{print $2}'` su - orarun -c /home/orarun/scripts/stopdb_bpayl1.sh if [[ $? != 0 ]] then print "Oracle on ayzgdb shutdown failed." else fuser -kuc /msrundata fuser -kuc /msrunlog print "Oracle on ayzgdb shutdown done." fi elif [[ $HOSTNAME = "ayzgapp" ]] then su - xcomrun -c stopxcom.sh sleep 3 su - bpayl1 -c "tmshutdown -y" sleep 3 su - bpayl1 -c /BSMesWare/BPAYL1/Bin/tuxedo_force_shutdown sleep 3 su - orarun -c /home/orarun/scripts/stopdb_bpayl1.sh if [[ $? != 0 ]] then print "Oracle on ayzgapp shutdown failed." else fuser -kuc /msrundata fuser -kuc /msrunlog print "Oracle on ayzgapp shutdown done." fi fi ;; *) print "Oracle startup failed, check configuration variables." ;; esac } ############################################################################### # 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. ############################################################################### 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 orarun -c "${ORACLE_HOME}/bin/sqlplus '/ as sysdba'" <<EOF shutdown abort exit EOF if [[ $? != 0 ]] then print "Oracle abort failed." else print "Oracle abort done." fuser -kuc /msrundata fuser -kuc /msrunlog fuser -kuc /msrunexp fi ;; esac # Stop the listener process for Oracle. case $LISTENER in yes ) su orarun -c ${ORACLE_HOME}/bin/lsnrctl <<EOF 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 (( 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 # 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 script\n" 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 orarun | 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 } ############################################################################### # Function: monitor_processes # # Monitor the Oracle processes by making sure that all required processes are # running. ############################################################################## function monitor_processes { typeset -i n=0 for i in ${MONITOR_PROCESSES[@]} do MONITOR_PROCESSES_PID[$n]=`ps -fu orarun | awk '/'${i}$'/ { print $2 }'` #JAGad06432 print "Monitored process = ${i}, pid = ${MONITOR_PROCESSES_PID[$n]}" if [[ ${MONITOR_PROCESSES_PID[$n]} = "" ]] then print "\n\n" 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 "\n\n" 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 sleep ${MONITOR_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 ;; start) print "\n \"${HOST}\": Starting Oracle SESSION $SID_NAME at ${DATE} " 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
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)