#!/bin/ksh -p # ***************************************************************** # * * # * Copyright (c) 2002, 2003 Oracle Corporation. * # * All rights reserved. * # * * # * Copyright (c) 1991, 1999, 2002 Digital Equipment * # * Corporation * # * * # * * # * All Rights Reserved. Unpublished rights reserved under * # * the copyright laws of the United States. * # * * # * The software contained on this media is proprietary to * # * and embodies the confidential technology of Digital * # * Equipment Corporation and Oracle Corporation. Possession, * # * use, duplication or dissemination of the software * # * and media is authorized only pursuant to a valid written * # * license from Digital Equipment Corporation and Oracle * # * Corporation * # * * # * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * # * by the U.S. Government is subject to restrictions as set * # * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * # * or in FAR 52.227-19, as applicable. * # * * # * * # ***************************************************************** # # @(#)$RCSfile: crstmpl.scr $ $Revision: has/crs/template/crstmpl.scr#0 $ (DEC) $Date: 21-feb-2005.14:52:54 $ # # # #################################################################### # # The following section contains variables that can be set to best # suit your application. # # Please review each variable and set as needed. # # Set CAA_SCRIPT_DEBUG when invoking the script from command line # for testing. This will cause all output events to go to the terminal, # rather than being sent to EVM. # #################################################################### # # Application name - set this variable to a name that describes this # (mandatory) application. Enclose the name in double quotes. # Examples: "apache", "netscape" SERVICE_NAME="" # Associated Processes - the application configured may consist of # (mandatory single or multiple processes. Specifying the names # of the processes here allows CAA to monitor that they # are running and allows CAA to completely clean up when # stopping the application. # Ex: "proc1 proc2" PROBE_PROCS="" # Application Startup Command - CAA will invoke this command when starting # (mandatory) the application. Include the command to execute along # with any flags and arguments needed. Use this # variable along with START_APPCMD2 (see below) when # dealing with a simple application start procedure. # # If the start procedure is complicated and/or involves # many commands, you may find it easier to disregard # this variable and manually code the commands needed # in the "Start" section of this script (see below). # # Another alternative for a complicated start procedure # is to create a separate script containing those # commands and specifying that script in this variable. # # Ex: "/cludemo/avs/avsetup -s" # # NOTE: if not set, you must manually code the commands # to start the application in the "Start" section of # this script. START_APPCMD="" # Secondary Application Startup Command - used in conjunction with the # (optional) Application Startup Command just described above. Use # if desired to implement a two-step startup process for # your application, if needed. START_APPCMD2="" # Application Stop Command - CAA will invoke this command when stopping # (optional) the application. Include the command to execute along # with any flags and arguments needed. Use this # variable along with STOP_APPCMD2 (see below) when # dealing with a simple application stop procedure. # # If the stop procedure is complicated and/or involves # many commands, you may find it easier to disregard # this variable and manually code the commands needed # in the "Stop" section of this script (see below). # # Another alternative for a complicated stop procedure # is to create a separate script containing those # commands and specifying that script in this variable. # # Ex: "/cludemo/avs/avsetup -k" # # NOTE: if not set, you should manually code the commands # to stop the application in the "Stop" section of # this script. Otherwise, this script will not stop the # application in a graceful manner. STOP_APPCMD="" # Secondary Application Stop Command - used in conjunction with the # (optional) Application Stop Command just described above. Use # if desired to implement a two-step stop process for # your application, if needed. STOP_APPCMD2="" # Application Directory - If set, this script will change to this directory # (optional) prior to executing the start process. This may allow # you to not have to specify full path names for # commands or files in this directory. # # Ex: "/var/opt/product1" APPDIR="" export SERVICE_NAME START_APPCMD START_APPCMD2 export APPDIR PROBE_PROCS STOP_APPCMD STOP_APPCMD2 UNAME="/bin/uname" if [ ! -x "$UNAME" ]; then UNAME="/usr/bin/uname" fi if [ `$UNAME` = "HP-UX" ]; then export UNIX95=XPG4 fi ################################################################# # # The following section contains variables used by CAA. We recommend # leaving them defined as is. # ################################################################# DEBUG_PRIORITY=100 INFO_PRIORITY=200 ERROR_PRIORITY=500 SCRIPT=$0 ACTION=$1 # Action (start, stop or check) EVMPOST="evmpost" # EVM command to post events DEBUG=0 if [[ "$CAA_SCRIPT_DEBUG" != "" ]]; then DEBUG=1 EVMPOST="evmpost -r | evmshow -D" fi export EVMPOST ACTION SCRIPT ################################################################### # # The following section contains procedures that are available to # be used from the start, stop, and check portions of this script. # ################################################################### # # postevent - Posts EVM event with specified parameters # # Argument: $1 - priority (optional) # $2 - message (optional) # # postevent () { typeset pri=$1 typeset msg=${2:-failed} typeset evt='event { name sys.ora.clu.crs.action_script ' if [ ! -z "$pri" ]; then evt="$evt priority $pri " fi evt="$evt var {name name value \\\"$SERVICE_NAME\\\" } " evt="$evt var {name script value \\\"$SCRIPT\\\" } " evt="$evt var {name action value \\\"$ACTION\\\" } " evt="$evt var {name message value \\\"$msg\\\" }" evt="$evt }" evt="echo $evt | $EVMPOST" eval $evt } # # getpid - list PIDs of all processes with supplied name # # Modified /sbin/init.d/bin/getpid to list all matches # # Arguments: process name # getpid () { if [ -n "$1" ]; then GETMYPID=$1 shift /bin/ps -e -o pid,comm | while read mypid command args do if [ "$command" = "$GETMYPID" ]; then echo "$mypid" fi done fi } # # checkdaemon - return the number of instances of a daemon # # Argument: process name # Return: number of instances of the named daemon currently running # checkdaemon () { R=`getpid $1 | wc -l` return $R } # # zapdaemon - kill a given process using brutal force (i.e. -9) # # Argument: list of processes to kill # Return: 1 - failed to kill some process # 0 - killed all processes # zapdaemon () { typeset ret=0 for i in ${1} do checkdaemon ${i} if [ $? -ne 0 ]; then kill `getpid ${i}` checkdaemon ${i} if [ $? -ne 0 ]; then kill -9 `getpid ${i}` checkdaemon ${i} if [ $? -ne 0 ]; then postevent $ERROR_PRIORITY "${i}: stuck - could not kill -KILL" ret=1 else postevent $ERROR_PRIORITY "${i}: killed with -KILL" fi else postevent "" "${i}: killed" fi fi done return $ret } # # probeapp - Probe process to see if in process list. # # This simple form of process probing searches the process list for an # entry corresponding to the specified process. If found, all is assumed # to be well. # # More accurate process probing may be available depending upon the nature # of your application. For instance, you might invoke a test command that # the process should respond to and check the returned results. You should # consider adding this type of probing to this script, if possible. # # Argument: process name # # Return: 1 - process not running # 0 - process running # probeapp () { checkdaemon $1 if [ $? -ne 0 ]; then postevent $DEBUG_PRIORITY "$1 check OK" return 0 else postevent $DEBUG_PRIORITY "$1 check failed" return 1 fi } ######################################################################### # # Main section of Action Script - starts, stops, or checks an application # # This script is invoked by CAA when managing the application associated # with this script. # # Argument: $1 - start | stop | check # # Returns: 0 - successful start, stop, or check # 1 - error # ######################################################################### # # Start section - start the process and report results # # If the Application Startup Commands (see description above) were used, # little, if any modifications are needed in this section. If not used, # you may replace most of the contents in this section with your own # start procedure code. # # For improved serviceability, preserve the commands below that log # messages or posts events. # case $1 in 'start') postevent $DEBUG_PRIORITY "trying to start" cd $APPDIR if [ "$START_APPCMD" != "" ]; then out=`$START_APPCMD` if [ $? -ne 0 ]; then postevent $ERROR_PRIORITY "start: $out" exit 1 fi fi if [ "$START_APPCMD2" != "" ]; then out=`$START_APPCMD2` if [ $? -ne 0 ]; then postevent $ERROR_PRIORITY "start 2: $out" exit 1 fi fi ;; # # Stop section - stop the process and report results # # If the Application Stop Commands or Associated Processes (see descriptions # above) were used,little, if any modifications are needed in this section. # If not used, you may replace most of the contents in this section with # your own stop procedure code. # # For improved serviceability, preserve the commands below that log # messages or posts events. # 'stop') postevent $DEBUG_PRIORITY "trying to stop" cd $APPDIR if [ "$STOP_APPCMD" != "" ]; then out=`$STOP_APPCMD` if [ $? -ne 0 ]; then postevent $ERROR_PRIORITY "stop: $out" exit 1 fi fi if [ "$STOP_APPCMD2" != "" ]; then out=`$STOP_APPCMD2` if [ $? -ne 0 ]; then postevent $ERROR_PRIORITY "stop 2: $out" exit 1 fi fi # # Kill stubborn processes and applications that don't have a stop command # for i in ${PROBE_PROCS}; do zapdaemon ${i} done ;; # # Check section - check the process and report results # # If you specified $PROBE_PROCS (see earlier description), very little, # if any, changes are needed to have simple process checking. # # Your application might allow you to implement more accurate process # checking. If so, you may choose to implement that code here. See the # description for the probeapp function earlier in this script. # 'check') for i in ${PROBE_PROCS}; do postevent $DEBUG_PRIORITY "trying to check $i" probeapp $i if [ $? -ne 0 ]; then postevent "" "check failed for $i" exit 1 fi done ;; #-- start clone 'clone') PATH=/usr/bin:/bin:${PATH} postevent $DEBUG_PRIORITY "cloning with $*" sed -e "s;^SERVICE_NAME=\";SERVICE_NAME=\"$2;" \ -e "s;^PROBE_PROCS=\";PROBE_PROCS=\"$3;" \ -e "s;^START_APPCMD=\";START_APPCMD=\"$3;" \ -e "/^#-- start clone/,/^#-- end clone/d" \ < $SCRIPT > $4 chmod 0744 $4 ;; #-- end clone *) postevent $ERROR_PRIORITY "usage: $0 {start stop check}" exit 1 ;; esac postevent "" success exit 0