- 论坛徽章:
- 0
|
请问MC/SG中程序包 配置文件和控制脚本中的service有什么用?
oracle.sh如下
#!/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=9_0_1
SID_NAME=
ORACLE_HOME=
LISTENER=
LISTENER_NAME=
LISTENER_PASS=
MONITOR_INTERVAL=30
PACKAGE_NAME=
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}
HOST=`hostname`
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.
###############################################################################
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
9_0_1) su oracle -c "${ORACLE_HOME}/bin/sqlplus '/as sysdba'"<<EOF
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 )
su oracle -c "${ORACLE_HOME}/bin/lsnrctl start ${LISTENER_NAME}"
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.
###############################################################################
function oracle_shutdown_cmds
{
case $ORA_ver in
9_0_1) su oracle -c "${ORACLE_HOME}/bin/sqlplus '/as sysdba'" <<EOF
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
}
###############################################################################
# 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
9_0_1)
su oracle -c "${ORACLE_HOME}/bin/sqlplus '/as sysdba'" <<EOF
shutdown abort
exit
EOF
if [[ $? != 0 ]]
then
print "Oracle abort failed."
else
print "Oracle abort done."
fi
;;
esac
# Stop the listener process for Oracle.
case $LISTENER in
yes )
su oracle -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 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
}
###############################################################################
# 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 oracle | 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 |
|