5
# Description: Manages a single SAP Instance as a High-Availability
6
# resource. One SAP Instance is defined by one
7
# SAP Instance-Profile. start/stop handels all services
8
# of the START-Profile, status and monitor care only
9
# about essential services.
11
# Author: Alexander Krauth, June 2006
12
# Support: linux@sap.com
13
# License: GNU General Public License (GPL)
14
# Copyright: (c) 2006-2008 Alexander Krauth
17
# See usage() function below for more details...
19
# OCF instance parameters:
20
# OCF_RESKEY_InstanceName
21
# OCF_RESKEY_DIR_EXECUTABLE (optional, well known directories will be searched by default)
22
# OCF_RESKEY_DIR_PROFILE (optional, well known directories will be searched by default)
23
# OCF_RESKEY_START_PROFILE (optional, well known directories will be searched by default)
24
# OCF_RESKEY_START_WAITTIME (optional, to solve timing problems during J2EE-Addin start)
25
# OCF_RESKEY_AUTOMATIC_RECOVER (optional, automatic startup recovery using cleanipc, default is false)
26
# OCF_RESKEY_MONITOR_SERVICES (optional, default is to monitor critical services only)
27
# OCF_RESKEY_SHUTDOWN_METHOD (optional, defaults to NORMAL, KILL: terminate the SAP instance with OS commands - faster, at your own risk)
28
# OCF_RESKEY_ERS_InstanceName (optional, InstanceName of the ERS instance in a Master/Slave configuration)
29
# OCF_RESKEY_ERS_START_PROFILE (optional, START_PROFILE of the ERS instance in a Master/Slave configuration)
30
# OCF_RESKEY_PRE_START_USEREXIT (optional, lists a script which can be executed before the resource is started)
31
# OCF_RESKEY_POST_START_USEREXIT (optional, lists a script which can be executed after the resource is started)
32
# OCF_RESKEY_PRE_STOP_USEREXIT (optional, lists a script which can be executed before the resource is stopped)
33
# OCF_RESKEY_POST_STOP_USEREXIT (optional, lists a script which can be executed after the resource is stopped)
35
# TODO: - Option to shutdown sapstartsrv for non-active instances -> that means: do probes only with OS tools (sapinstance_status)
36
# - Option for better standalone enqueue server monitoring, using ensmon (test enque-deque)
37
# - Option for cleanup abandoned enqueue replication tables
39
#######################################################################
42
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
43
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
45
#######################################################################
50
methods=`sapinstance_methods`
51
methods=`echo $methods | tr ' ' '|'`
55
$0 manages a SAP Instance as an HA resource.
57
The 'start' operation starts the instance or the ERS instance in a Master/Slave configuration
58
The 'stop' operation stops the instance
59
The 'status' operation reports whether the instance is running
60
The 'monitor' operation reports whether the instance seems to be working
61
The 'promote' operation starts the primary instance in a Master/Slave configuration
62
The 'demote' operation stops the primary instance and starts the ERS instance
63
The 'notify' operation always returns SUCCESS
64
The 'validate-all' operation reports whether the parameters are valid
65
The 'methods' operation reports on the methods $0 supports
70
sapinstance_meta_data() {
73
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
74
<resource-agent name="SAPInstance">
75
<version>2.12</version>
77
<shortdesc lang="en">Manages a SAP instance as an HA resource.</shortdesc>
79
Usually a SAP system consists of one database and at least one or more SAP instances (sometimes called application servers). One SAP Instance is defined by having exactly one instance profile. The instance profiles can usually be found in the directory /sapmnt/SID/profile. Each instance must be configured as it's own resource in the cluster configuration.
80
The resource agent supports the following SAP versions:
81
- SAP WebAS ABAP Release 6.20 - 7.30
82
- SAP WebAS Java Release 6.40 - 7.30
83
- SAP WebAS ABAP + Java Add-In Release 6.20 - 7.30 (Java is not monitored by the cluster in that case)
84
When using a SAP Kernel 6.40 please check and implement the actions from the section "Manual postprocessing" from SAP note 995116 (http://sdn.sap.com).
86
All operations of the SAPInstance resource agent are done by using the startup framework called SAP Management Console or sapstartsrv that was introduced with SAP kernel release 6.40. Find more information about the SAP Management Console in SAP note 1014480. Using this framework defines a clear interface for the Heartbeat cluster, how it sees the SAP system. The options for monitoring the SAP system are also much better than other methods like just watching the ps command for running processes or doing some pings to the application. sapstartsrv uses SOAP messages to request the status of running SAP processes. Therefore it can actually ask a process itself what it's status is, independent from other problems that might exist at the same time.
88
sapstartsrv knows 4 status colours:
89
- GREEN = everything is fine
90
- YELLOW = something is wrong, but the service is still working
91
- RED = the service does not work
92
- GRAY = the service has not been started
94
The SAPInstance resource agent will interpret GREEN and YELLOW as OK. That means that minor problems will not be reported to the Heartbeat cluster. This prevents the cluster from doing an unwanted failover.
95
The statuses RED and GRAY are reported as NOT_RUNNING to the cluster. Depending on the status the cluster expects from the resource, it will do a restart, failover or just nothing.
98
<parameter name="InstanceName" unique="1" required="1">
99
<longdesc lang="en">The full qualified SAP instance name. e.g. P01_DVEBMGS00_sapp01ci. Usually this is the name of the SAP instance profile.</longdesc>
100
<shortdesc lang="en">Instance name: SID_INSTANCE_VIR-HOSTNAME</shortdesc>
101
<content type="string" default="" />
103
<parameter name="DIR_EXECUTABLE" unique="1" required="0">
104
<longdesc lang="en">The full qualified path where to find sapstartsrv and sapcontrol. Specify this parameter, if you have changed the SAP kernel directory location after the default SAP installation.</longdesc>
105
<shortdesc lang="en">Path of sapstartsrv and sapcontrol</shortdesc>
106
<content type="string" default="" />
108
<parameter name="DIR_PROFILE" unique="1" required="0">
109
<longdesc lang="en">The full qualified path where to find the SAP START profile. Specify this parameter, if you have changed the SAP profile directory location after the default SAP installation.</longdesc>
110
<shortdesc lang="en">Path of start profile</shortdesc>
111
<content type="string" default="" />
113
<parameter name="START_PROFILE" unique="1" required="0">
114
<longdesc lang="en">The name of the SAP START profile. Specify this parameter, if you have changed the name of the SAP START profile after the default SAP installation. As SAP release 7.10 does not have a START profile anymore, you need to specify the Instance Profile than.</longdesc>
115
<shortdesc lang="en">Start profile name</shortdesc>
116
<content type="string" default="" />
118
<parameter name="START_WAITTIME" unique="1" required="0">
119
<longdesc lang="en">After that time in seconds a monitor operation is executed by the resource agent. Does the monitor return SUCCESS, the start ishandled as SUCCESS. This is useful to resolve timing problems with e.g. the J2EE-Addin instance.Usually the resource agent waits until all services are started and the SAP Management Console reports a GREEN status. A double stack installation (ABAP + Java AddIn) consists of an ABAP dispatcher and aJAVA instance. Normally the start of the JAVA instance takes much longer than the start of the ABAP instance. For a JAVA Instance you may need to configure a much higher timeout for the start operation of the resource in Heartbeat. The disadvantage here is, that the discovery of a failed start by the cluster takes longer. Somebody might say: For me it is important, that the ABAP instance is up and running. A failure of the JAVA instance shall not cause a failover of the SAP instance.
120
Actually the SAP MC reports a YELLOW status, if the JAVA instance of a double stack system fails. From the resource agent point of view YELLOW means:everything is OK. Setting START_WAITTIME to a lower value determines the resource agent to check the status of the instance during a start operation after that time. As it would wait normally for a GREEN status, now it reports SUCCESS to the cluster in case of a YELLOW status already after the specified time.
122
That is only useful for double stack systems.
124
<shortdesc lang="en">Check the successful start after that time (do not wait for J2EE-Addin)</shortdesc>
125
<content type="string" default="3600" />
127
<parameter name="AUTOMATIC_RECOVER" unique="1" required="0">
128
<longdesc lang="en">The SAPInstance resource agent tries to recover a failed start attempt automaticaly one time. This is done by killing runing instance processes, removing the kill.sap file and executing cleanipc. Sometimes a crashed SAP instance leaves some processes and/or shared memory segments behind. Setting this option to true will try to remove those leftovers during a start operation. That is to reduce manual work for the administrator.</longdesc>
129
<shortdesc lang="en">Enable or disable automatic startup recovery</shortdesc>
130
<content type="boolean" default="false"/>
132
<parameter name="MONITOR_SERVICES" unique="1" required="0">
133
<longdesc lang="en">Within a SAP instance there can be several services. Usually you will find the defined services in the START profile of the related instance (Attention: with SAP Release 7.10 the START profile content was moved to the instance profile). Not all of those services are worth to monitor by the cluster. For example you properly do not like to failover your SAP instance, if the central syslog collector daemon fails.
134
Those services are monitored within the SAPInstance resource agent:
143
That names match the strings used in the output of the command 'sapcontrol -nr [Instance-Nr] -function GetProcessList'.
144
The default should fit most cases where you want to manage a SAP Instance from the cluster. You may change this with this parameter, if you like to monitor more/less or other services that sapstartsrv supports.
145
You may specify multiple services seperated by a | (pipe) sign in this parameter: disp+work|msg_server|enserver
147
<shortdesc lang="en">Services to monitor</shortdesc>
148
<content type="string" default="disp+work|msg_server|enserver|enrepserver|jcontrol|jstart"/>
150
<parameter name="SHUTDOWN_METHOD" unique="1" required="0">
151
<longdesc lang="en">Usual a SAP Instance is stopped by the command 'sapcontrol -nr InstanceNr -function Stop'. SHUTDOWN_METHOD=KILL means to kill the SAP Instance using OS commands. SAP processes of the instance are terminated with 'kill -9', shared memory is deleted with 'cleanipc' and the 'kill.sap' file will be deleted. That method is much faster than the gracefull stop, but the instance does not have the chance to say goodbye to other SAPinstances in the same system. USE AT YOUR OWN RISK !!</longdesc>
152
<shortdesc lang="en">Shutdown graceful or kill a SAP instance by terminating the processes. (normal|KILL)</shortdesc>
153
<content type="string" default="normal"/>
155
<parameter name="ERS_InstanceName" unique="1" required="0">
156
<longdesc lang="en">Only used in a Master/Slave resource configuration:
157
The full qualified SAP enqueue replication instance name. e.g. P01_ERS02_sapp01ers. Usually this is the name of the SAP instance profile.
158
The enqueue replication instance must be installed, before you want to configure a master-slave cluster recource.
160
The master-slave configuration in the cluster must use this properties:
166
<shortdesc lang="en">Enqueue replication instance name: SID_INSTANCE_VIR-HOSTNAME</shortdesc>
167
<content type="string" default=""/>
169
<parameter name="ERS_START_PROFILE" unique="1" required="0">
170
<longdesc lang="en">Only used in a Master/Slave resource configuration:
171
The parameter ERS_InstanceName must also be set in this configuration.
172
The name of the SAP START profile. Specify this parameter, if you have changed the name of the SAP START profile after the default SAP installation. As SAP release 7.10 does not have a START profile anymore, you need to specify the Instance Profile than.
174
<shortdesc lang="en">Enqueue replication start profile name</shortdesc>
175
<content type="string" default=""/>
177
<parameter name="PRE_START_USEREXIT" unique="1" required="0">
178
<longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets started.</longdesc>
179
<shortdesc lang="en">Path to a pre-start script</shortdesc>
180
<content type="string" default="" />
182
<parameter name="POST_START_USEREXIT" unique="1" required="0">
183
<longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got started.</longdesc>
184
<shortdesc lang="en">Path to a post-start script</shortdesc>
185
<content type="string" default="" />
187
<parameter name="PRE_STOP_USEREXIT" unique="1" required="0">
188
<longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets stopped.</longdesc>
189
<shortdesc lang="en">Path to a pre-start script</shortdesc>
190
<content type="string" default="" />
192
<parameter name="POST_STOP_USEREXIT" unique="1" required="0">
193
<longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got stopped.</longdesc>
194
<shortdesc lang="en">Path to a post-start script</shortdesc>
195
<content type="string" default="" />
200
<action name="start" timeout="180" />
201
<action name="stop" timeout="240" />
202
<action name="status" timeout="60" />
203
<action name="monitor" depth="0" timeout="60" interval="120" />
204
<action name="promote" timeout="320" />
205
<action name="demote" timeout="320" />
206
<action name="validate-all" timeout="5" />
207
<action name="meta-data" timeout="5" />
208
<action name="methods" timeout="5" />
216
# methods: What methods/operations do we support?
218
sapinstance_methods() {
237
# is_clone : find out if we are configured to run in a Master/Slave configuration
240
if [ -n "$OCF_RESKEY_CRM_meta_clone_max" ] \
241
&& [ "$OCF_RESKEY_CRM_meta_clone_max" -gt 0 ]
243
if [ "$OCF_RESKEY_CRM_meta_clone_max" -ne 2 ] || \
244
[ "$OCF_RESKEY_CRM_meta_clone_node_max" -ne 1 ] || \
245
[ "$OCF_RESKEY_CRM_meta_master_node_max" -ne 1 ] || \
246
[ "$OCF_RESKEY_CRM_meta_master_max" -ne 1 ]
248
ocf_log err "Clone options misconfigured. (expect: clone_max=2,clone_node_max=1,master_node_max=1,master_max=1)"
249
exit $OCF_ERR_CONFIGURED
252
if [ -z "$OCF_RESKEY_ERS_InstanceName" ]
254
ocf_log err "In a Master/Slave configuration the ERS_InstanceName parameter is mandatory."
265
# abnormal_end : essential things are missing, but in the natur of a SAP installation - which can be very different
266
# from customer to customer - we cannot handle this always as an error
267
# This would be the case, if the software is installed on shared disks and not visible
268
# to all cluster nodes at all times.
278
if [ "$ACTION" = "stop" ]
285
exit $OCF_ERR_CONFIGURED
289
# sapinstance_init : Define global variables with default values, if optional parameters are not set
296
SID=`echo "$myInstanceName" | cut -d_ -f1`
297
InstanceName=`echo "$myInstanceName" | cut -d_ -f2`
298
InstanceNr=`echo "$InstanceName" | sed 's/.*\([0-9][0-9]\)$/\1/'`
299
SAPVIRHOST=`echo "$myInstanceName" | cut -d_ -f3`
301
# optional OCF parameters, we try to guess which directories are correct
302
if [ -z "$OCF_RESKEY_DIR_EXECUTABLE" ]
304
if have_binary /usr/sap/$SID/$InstanceName/exe/sapstartsrv && have_binary /usr/sap/$SID/$InstanceName/exe/sapcontrol
306
DIR_EXECUTABLE="/usr/sap/$SID/$InstanceName/exe"
307
SAPSTARTSRV="/usr/sap/$SID/$InstanceName/exe/sapstartsrv"
308
SAPCONTROL="/usr/sap/$SID/$InstanceName/exe/sapcontrol"
309
elif have_binary /usr/sap/$SID/SYS/exe/run/sapstartsrv && have_binary /usr/sap/$SID/SYS/exe/run/sapcontrol
311
DIR_EXECUTABLE="/usr/sap/$SID/SYS/exe/run"
312
SAPSTARTSRV="/usr/sap/$SID/SYS/exe/run/sapstartsrv"
313
SAPCONTROL="/usr/sap/$SID/SYS/exe/run/sapcontrol"
316
if have_binary "$OCF_RESKEY_DIR_EXECUTABLE/sapstartsrv" && have_binary "$OCF_RESKEY_DIR_EXECUTABLE/sapcontrol"
318
DIR_EXECUTABLE="$OCF_RESKEY_DIR_EXECUTABLE"
319
SAPSTARTSRV="$OCF_RESKEY_DIR_EXECUTABLE/sapstartsrv"
320
SAPCONTROL="$OCF_RESKEY_DIR_EXECUTABLE/sapcontrol"
324
[ -z "$DIR_EXECUTABLE" ] && abnormal_end "Cannot find sapstartsrv and sapcontrol executable, please set DIR_EXECUTABLE parameter!"
326
if [ -z "$OCF_RESKEY_DIR_PROFILE" ]
328
DIR_PROFILE="/usr/sap/$SID/SYS/profile"
330
DIR_PROFILE="$OCF_RESKEY_DIR_PROFILE"
333
if [ "$myInstanceName" != "$OCF_RESKEY_InstanceName" ]
335
currentSTART_PROFILE=$OCF_RESKEY_ERS_START_PROFILE
337
currentSTART_PROFILE=$OCF_RESKEY_START_PROFILE
340
if [ -z "$currentSTART_PROFILE" ]
342
SAPSTARTPROFILE="$DIR_PROFILE/START_${InstanceName}_${SAPVIRHOST}"
344
SAPSTARTPROFILE="$currentSTART_PROFILE"
347
if [ -z "$OCF_RESKEY_START_WAITTIME" ]
349
export OCF_RESKEY_START_WAITTIME=3600
352
if [ -z "$OCF_RESKEY_MONITOR_SERVICES" ]
354
export OCF_RESKEY_MONITOR_SERVICES="disp+work|msg_server|enserver|enrepserver|jcontrol|jstart"
357
# as root user we need the library path to the SAP kernel to be able to call sapcontrol
358
if [ `echo $LD_LIBRARY_PATH | grep -c "^$DIR_EXECUTABLE\>"` -eq 0 ]; then
359
LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
360
export LD_LIBRARY_PATH
363
sidadm="`echo $SID | tr '[:upper:]' '[:lower:]'`adm"
370
# check_sapstartsrv : Before using sapcontrol we make sure that the sapstartsrv is running for the correct instance.
371
# We cannot use sapinit and the /usr/sap/sapservices file in case of an enquerep instance,
372
# because then we have two instances with the same instance number.
374
check_sapstartsrv() {
379
output=`$SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script`
382
runninginst=`echo "$output" | grep '^0 : ' | cut -d' ' -f3`
383
if [ "$runninginst" != "$InstanceName" ]
385
ocf_log warn "sapstartsrv is running for instance $runninginst, that service will be killed"
389
ocf_log warn "sapstartsrv is not running for instance $SID-$InstanceName, it will be started now"
393
if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi
395
if [ $restart -eq 1 ]
398
if [ -d /usr/sap/$SID/SYS/profile/ ]
400
DIR_PROFILE="/usr/sap/$SID/SYS/profile"
402
abnormal_end "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!"
405
[ ! -r $SAPSTARTPROFILE ] && abnormal_end "Expected $SAPSTARTPROFILE to be the instance START profile, please set START_PROFILE parameter!"
407
pkill -9 -f "sapstartsrv.*$runninginst"
408
$SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
410
# now make sure the daemon has been started and is able to respond
412
while [ $srvrc -eq 1 -a `pgrep -f "sapstartsrv.*$runninginst" | wc -l` -gt 0 ]
415
$SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1
421
ocf_log info "sapstartsrv for instance $SID-$InstanceName was restarted !"
424
ocf_log error "sapstartsrv for instance $SID-$InstanceName could not be started!"
425
chkrc=$OCF_ERR_GENERIC
426
ocf_is_probe && chkrc=$OCF_NOT_RUNNING
435
# sapuserexit : Many SAP customers need some additional processes/tools to run their SAP systems.
436
# This specialties do not allow a totally generic SAP cluster resource agent.
437
# Someone should write a resource agent for each additional process you need, if it
438
# is required to monitor that process within the cluster manager. To enable
439
# you to extent this resource agent without developing a new one, this user exit
448
if have_binary "$VALUE"
450
ocf_log info "Calling userexit ${NAME} with customer script file ${VALUE}"
451
"$VALUE" >/dev/null 2>&1
452
ocf_log info "Exiting userexit ${NAME} with customer script file ${VALUE}, returncode: $?"
454
ocf_log warn "Attribute ${NAME} is set to ${VALUE}, but this file is not executable"
462
# cleanup_instance : remove resources (processes and shared memory) from a crashed instance)
465
pkill -9 -f -U $sidadm $InstanceName
466
ocf_log info "Terminated instance using 'pkill -9 -f -U $sidadm $InstanceName'"
468
# it is necessary to call cleanipc as user sidadm if the system has 'vmcj/enable = ON' set - otherwise SHM-segments in /dev/shm/SAP_ES2* cannot beremoved
469
su - $sidadm -c "cleanipc $InstanceNr remove"
470
ocf_log info "Tried to remove shared memory resources using 'cleanipc $InstanceNr remove' as user $sidadm"
472
if [ -f "/usr/sap/$SID/$InstanceName/work/kill.sap" ]
474
rm -f /usr/sap/$SID/$InstanceName/work/kill.sap
475
ocf_log info "Deleted /usr/sap/$SID/$InstanceName/work/kill.sap"
482
# sapinstance_start : Start the SAP instance
484
sapinstance_start() {
486
sapuserexit PRE_START_USEREXIT "$OCF_RESKEY_PRE_START_USEREXIT"
490
while [ $loopcount -lt 2 ]
492
loopcount=$(($loopcount + 1))
496
if [ $rc -eq $OCF_SUCCESS ]; then
497
output=`$SAPCONTROL -nr $InstanceNr -function Start`
499
ocf_log info "Starting SAP Instance $SID-$InstanceName: $output"
504
ocf_log err "SAP Instance $SID-$InstanceName start failed."
505
return $OCF_ERR_GENERIC
509
while [ $startrc -gt 0 ]
511
waittime_start=`date +%s`
512
output=`$SAPCONTROL -nr $InstanceNr -function WaitforStarted $OCF_RESKEY_START_WAITTIME 10`
514
waittime_stop=`date +%s`
516
if [ $startrc -ne 0 ]
518
if [ $(($waittime_stop - $waittime_start)) -ge $OCF_RESKEY_START_WAITTIME ]
520
sapinstance_monitor NOLOG
521
if [ $? -eq $OCF_SUCCESS ]
523
output="START_WAITTIME ($OCF_RESKEY_START_WAITTIME) has elapsed, but instance monitor returned SUCCESS. Instance considered running."
524
startrc=0; loopcount=2
527
if [ $loopcount -eq 1 ] && ocf_is_true $OCF_RESKEY_AUTOMATIC_RECOVER
529
ocf_log warn "SAP Instance $SID-$InstanceName start failed: $output"
530
ocf_log warn "Try to recover $SID-$InstanceName"
543
if [ $startrc -eq 0 ]
545
ocf_log info "SAP Instance $SID-$InstanceName started: $output"
547
sapuserexit POST_START_USEREXIT "$OCF_RESKEY_POST_START_USEREXIT"
549
ocf_log err "SAP Instance $SID-$InstanceName start failed: $output"
558
# sapinstance_recover: Try startup of failed instance by cleaning up resources
560
sapinstance_recover() {
568
# sapinstance_stop: Stop the SAP instance
571
sapuserexit PRE_STOP_USEREXIT "$OCF_RESKEY_PRE_STOP_USEREXIT"
573
if [ "$OCF_RESKEY_SHUTDOWN_METHOD" = "KILL" ]
575
ocf_log info "Stopping SAP Instance $SID-$InstanceName with shutdown method KILL!"
582
if [ $rc -eq $OCF_SUCCESS ]; then
583
output=`$SAPCONTROL -nr $InstanceNr -function Stop`
585
ocf_log info "Stopping SAP Instance $SID-$InstanceName: $output"
590
output=`$SAPCONTROL -nr $InstanceNr -function WaitforStopped 3600 1`
593
ocf_log info "SAP Instance $SID-$InstanceName stopped: $output"
596
ocf_log err "SAP Instance $SID-$InstanceName stop failed: $output"
600
ocf_log err "SAP Instance $SID-$InstanceName stop failed: $output"
604
sapuserexit POST_STOP_USEREXIT "$OCF_RESKEY_POST_STOP_USEREXIT"
611
# sapinstance_monitor: Can the given SAP instance do anything useful?
613
sapinstance_monitor() {
618
if [ $rc -eq $OCF_SUCCESS ]
621
output=`$SAPCONTROL -nr $InstanceNr -function GetProcessList -format script`
623
# we have to parse the output, because the returncode doesn't tell anything about the instance status
624
for SERVNO in `echo "$output" | grep '^[0-9] ' | cut -d' ' -f1 | sort -u`
626
COLOR=`echo "$output" | grep "^$SERVNO dispstatus: " | cut -d' ' -f3`
627
SERVICE=`echo "$output" | grep "^$SERVNO name: " | cut -d' ' -f3`
631
GREEN|YELLOW) STATE=$OCF_SUCCESS;;
632
*) STATE=$OCF_NOT_RUNNING;;
635
SEARCH=`echo "$OCF_RESKEY_MONITOR_SERVICES" | sed 's/\+/\\\+/g' | sed 's/\./\\\./g'`
636
if [ `echo "$SERVICE" | egrep -c "$SEARCH"` -eq 1 ]
638
if [ $STATE -eq $OCF_NOT_RUNNING ]
640
[ "$MONLOG" != "NOLOG" ] && ocf_log err "SAP instance service $SERVICE is not running with status $COLOR !"
647
if [ $count -eq 0 -a $rc -eq $OCF_SUCCESS ]
653
[ "$MONLOG" != "NOLOG" ] && ocf_log err "The SAP instance does not run any services which this RA could monitor!"
664
# sapinstance_status: Lightweight check of SAP instance only with OS tools
666
sapinstance_status() {
667
[ ! -f "/usr/sap/$SID/$InstanceName/work/kill.sap" ] && return $OCF_NOT_RUNNING
668
pids=`grep '^kill -[0-9]' /usr/sap/$SID/$InstanceName/work/kill.sap | awk '{print $3}'`
671
[ `pgrep -f -U $sidadm $InstanceName | grep -c $pid` -gt 0 ] && return $OCF_SUCCESS
673
return $OCF_NOT_RUNNING
678
# sapinstance_validate: Check the symantic of the input parameters
680
sapinstance_validate() {
682
if [ `echo "$SID" | grep -c '^[A-Z][A-Z0-9][A-Z0-9]$'` -ne 1 ]
684
ocf_log err "Parsing instance profile name: '$SID' is not a valid system ID!"
688
if [ `echo "$InstanceName" | grep -c '^[A-Z].*[0-9][0-9]$'` -ne 1 ]
690
ocf_log err "Parsing instance profile name: '$InstanceName' is not a valid instance name!"
694
if [ `echo "$InstanceNr" | grep -c '^[0-9][0-9]$'` -ne 1 ]
696
ocf_log err "Parsing instance profile name: '$InstanceNr' is not a valid instance number!"
700
if [ `echo "$SAPVIRHOST" | grep -c '^[A-Za-z][A-Za-z0-9_-]*$'` -ne 1 ]
702
ocf_log err "Parsing instance profile name: '$SAPVIRHOST' is not a valid hostname!"
711
# sapinstance_start_clone
713
sapinstance_start_clone() {
714
sapinstance_init $OCF_RESKEY_ERS_InstanceName
715
${HA_SBIN_DIR}/crm_master -v 50 -l reboot
722
# sapinstance_stop_clone
724
sapinstance_stop_clone() {
725
sapinstance_init $OCF_RESKEY_ERS_InstanceName
726
${HA_SBIN_DIR}/crm_master -v 0 -l reboot
733
# sapinstance_monitor_clone
735
sapinstance_monitor_clone() {
736
# first check with the status function (OS tools) if there could be something like a SAP instance running
737
# as we do not know here, if we are in master or slave state we do not want to start our monitoring
738
# agents (sapstartsrv) on the wrong host
740
sapinstance_init $OCF_RESKEY_InstanceName
741
if sapinstance_status; then
742
if sapinstance_monitor; then
743
${HA_SBIN_DIR}/crm_master -Q -v 100 -l reboot
744
return $OCF_RUNNING_MASTER
746
# by nature of the SAP enqueue server we have to make sure
747
# that we do a failover to the slave (enqueue replication server)
748
# in case the enqueue process has failed. We signal this to the
749
# cluster by setting our master preference to a lower value than the slave.
750
${HA_SBIN_DIR}/crm_master -v 10 -l reboot
751
return $OCF_FAILED_MASTER
754
sapinstance_init $OCF_RESKEY_ERS_InstanceName
755
sapinstance_status && sapinstance_monitor
757
if [ $rc -eq $OCF_SUCCESS ]; then
758
${HA_SBIN_DIR}/crm_master -Q -v 100 -l reboot
765
# sapinstance_promote_clone: In a Master/Slave configuration get Master by starting the SCS instance and stopping the ERS instance
766
# The order is important here to behave correct from the application levels view
768
sapinstance_promote_clone() {
769
sapinstance_init $OCF_RESKEY_InstanceName
770
ocf_log info "Promoting $SID-$InstanceName to running Master."
774
if [ $rc -eq $OCF_SUCCESS ]; then
775
sapinstance_init $OCF_RESKEY_ERS_InstanceName
785
# sapinstance_demote_clone: In a Master/Slave configuration get Slave by stopping the SCS instance and starting the ERS instance
787
sapinstance_demote_clone() {
788
sapinstance_init $OCF_RESKEY_InstanceName
789
ocf_log info "Demoting $SID-$InstanceName to a slave."
793
if [ $rc -eq $OCF_SUCCESS ]; then
794
sapinstance_init $OCF_RESKEY_ERS_InstanceName
804
# sapinstance_notify: Handle master scoring - to make sure a slave gets the next master
806
sapinstance_notify() {
807
local n_type="$OCF_RESKEY_CRM_meta_notify_type"
808
local n_op="$OCF_RESKEY_CRM_meta_notify_operation"
810
if [ "${n_type}_${n_op}" = "post_promote" ]; then
811
# After promotion of one master in the cluster, we make sure that all clones reset their master
812
# value back to 100. This is because a failed monitor on a master might have degree one clone
813
# instance to score 10.
814
${HA_SBIN_DIR}/crm_master -v 100 -l reboot
815
elif [ "${n_type}_${n_op}" = "pre_demote" ]; then
816
# if we are a slave and a demote event is anounced, make sure we have the highes wish to became master
817
# that is, when a slave resource was startet after the promote event of a already running master (e.g. node of slave was down)
818
# We also have to make sure to overrule the globaly set resource_stickiness or any fail-count factors => INFINITY
819
local n_uname="$OCF_RESKEY_CRM_meta_notify_demote_uname"
820
if [ ${n_uname} != ${HOSTNAME} ]; then
821
${HA_SBIN_DIR}/crm_master -v INFINITY -l reboot
828
# 'main' starts here...
853
if [ "$ACTION" = "status" ]; then
857
# These operations don't require OCF instance parameters to be set
859
usage|methods) sapinstance_$ACTION
861
meta-data) sapinstance_meta_data
863
notify) sapinstance_notify
870
ocf_log err "$0 must be run as root"
875
if [ -z "$OCF_RESKEY_InstanceName" ]
877
ocf_log err "Please set OCF_RESKEY_InstanceName to the name to the SAP instance profile!"
882
if [ ${CLONE} -eq 1 ]
886
if [ "$ACTION" = "promote" -o "$ACTION" = "demote" ]
888
ocf_log err "$ACTION called in a non master/slave environment"
891
sapinstance_init $OCF_RESKEY_InstanceName
894
# What kind of method was invoked?
896
start|stop|monitor|promote|demote) sapinstance_$ACTION$CLACT
898
validate-all) sapinstance_validate
900
*) sapinstance_methods
901
exit $OCF_ERR_UNIMPLEMENTED;;