~ubuntu-branches/debian/jessie/resource-agents/jessie

« back to all changes in this revision

Viewing changes to .pc/02_spelling_fixes.patch/heartbeat/SAPInstance

  • Committer: Bazaar Package Importer
  • Author(s): Martin Loschwitz
  • Date: 2011-10-20 12:10:13 UTC
  • Revision ID: james.westby@ubuntu.com-20111020121013-ficddzhosi473laz
Tags: 1:3.9.2-4
Adopted numerous changes from the Ubuntu packages, implemented by Andres 
Rodriguez to make co-maintaining these packages in Ubuntu and Debian a
bit easier.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# SAPInstance
 
4
#
 
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.
 
10
#
 
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
 
15
#
 
16
# An example usage: 
 
17
#      See usage() function below for more details...
 
18
#
 
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)
 
34
#
 
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
 
38
#
 
39
#######################################################################
 
40
# Initialization:
 
41
 
 
42
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
 
43
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
 
44
 
 
45
#######################################################################
 
46
 
 
47
SH=/bin/sh
 
48
 
 
49
sapinstance_usage() {
 
50
  methods=`sapinstance_methods`
 
51
  methods=`echo $methods | tr ' ' '|'`
 
52
  cat <<-!
 
53
        usage: $0 ($methods)
 
54
 
 
55
        $0 manages a SAP Instance as an HA resource.
 
56
 
 
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
 
66
 
 
67
        !
 
68
}
 
69
 
 
70
sapinstance_meta_data() {
 
71
        cat <<END
 
72
<?xml version="1.0"?>
 
73
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
 
74
<resource-agent name="SAPInstance">
 
75
<version>2.12</version>
 
76
 
 
77
<shortdesc lang="en">Manages a SAP instance as an HA resource.</shortdesc>
 
78
<longdesc lang="en">
 
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).
 
85
 
 
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.
 
87
 
 
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
 
93
 
 
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.
 
96
</longdesc>
 
97
<parameters>
 
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="" />
 
102
 </parameter>
 
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="" />
 
107
 </parameter>
 
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="" />
 
112
 </parameter>
 
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="" />
 
117
 </parameter>
 
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.
 
121
 
 
122
That is only useful for double stack systems.
 
123
  </longdesc>
 
124
  <shortdesc lang="en">Check the successful start after that time (do not wait for J2EE-Addin)</shortdesc>
 
125
  <content type="string" default="3600" />
 
126
 </parameter>
 
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"/>
 
131
 </parameter>
 
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:
 
135
 
 
136
- disp+work
 
137
- msg_server
 
138
- enserver
 
139
- enrepserver
 
140
- jcontrol
 
141
- jstart
 
142
 
 
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
 
146
  </longdesc>
 
147
  <shortdesc lang="en">Services to monitor</shortdesc>
 
148
  <content type="string" default="disp+work|msg_server|enserver|enrepserver|jcontrol|jstart"/>
 
149
 </parameter>
 
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"/>
 
154
 </parameter>
 
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.
 
159
 
 
160
The master-slave configuration in the cluster must use this properties:
 
161
clone_max = 2
 
162
clone_node_max = 1
 
163
master_node_max = 1
 
164
master_max = 1
 
165
  </longdesc>
 
166
  <shortdesc lang="en">Enqueue replication instance name: SID_INSTANCE_VIR-HOSTNAME</shortdesc>
 
167
  <content type="string" default=""/>
 
168
 </parameter>
 
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.
 
173
  </longdesc>
 
174
  <shortdesc lang="en">Enqueue replication start profile name</shortdesc>
 
175
  <content type="string" default=""/>
 
176
 </parameter>
 
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="" />
 
181
 </parameter>
 
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="" />
 
186
 </parameter>
 
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="" />
 
191
 </parameter>
 
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="" />
 
196
 </parameter>
 
197
</parameters>
 
198
 
 
199
<actions>
 
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" />
 
209
</actions>
 
210
</resource-agent>
 
211
END
 
212
}
 
213
 
 
214
 
 
215
#
 
216
# methods: What methods/operations do we support?
 
217
#
 
218
sapinstance_methods() {
 
219
  cat <<-!
 
220
        start
 
221
        stop
 
222
        status
 
223
        monitor
 
224
        promote
 
225
        demote
 
226
        notify
 
227
        validate-all
 
228
        methods
 
229
        meta-data
 
230
        usage
 
231
        !
 
232
}
 
233
 
 
234
 
 
235
 
 
236
#
 
237
# is_clone : find out if we are configured to run in a Master/Slave configuration
 
238
#
 
239
is_clone() {
 
240
  if [ -n "$OCF_RESKEY_CRM_meta_clone_max" ] \
 
241
   && [ "$OCF_RESKEY_CRM_meta_clone_max" -gt 0 ]
 
242
  then
 
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 ]
 
247
    then
 
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
 
250
    fi
 
251
 
 
252
    if [ -z "$OCF_RESKEY_ERS_InstanceName" ]
 
253
    then
 
254
      ocf_log err "In a Master/Slave configuration the ERS_InstanceName parameter is mandatory."
 
255
      exit $OCF_ERR_ARGS
 
256
    fi
 
257
  else
 
258
    return 0
 
259
  fi
 
260
  return 1
 
261
}
 
262
 
 
263
 
 
264
#
 
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.
 
269
#
 
270
abnormal_end() {
 
271
  err_msg=$1
 
272
 
 
273
  ocf_is_probe && {
 
274
    sapinstance_status
 
275
    exit $?
 
276
  }
 
277
 
 
278
  if [ "$ACTION" = "stop" ]
 
279
  then
 
280
    cleanup_instance
 
281
    exit $OCF_SUCCESS
 
282
  fi
 
283
 
 
284
  ocf_log err $err_msg
 
285
  exit $OCF_ERR_CONFIGURED
 
286
}
 
287
 
 
288
#
 
289
# sapinstance_init : Define global variables with default values, if optional parameters are not set
 
290
#
 
291
#
 
292
sapinstance_init() {
 
293
 
 
294
  myInstanceName="$1"
 
295
 
 
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`
 
300
 
 
301
  # optional OCF parameters, we try to guess which directories are correct
 
302
  if  [ -z "$OCF_RESKEY_DIR_EXECUTABLE" ]
 
303
  then
 
304
    if have_binary /usr/sap/$SID/$InstanceName/exe/sapstartsrv && have_binary /usr/sap/$SID/$InstanceName/exe/sapcontrol
 
305
    then
 
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
 
310
    then
 
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"
 
314
    fi
 
315
  else
 
316
    if have_binary "$OCF_RESKEY_DIR_EXECUTABLE/sapstartsrv" && have_binary "$OCF_RESKEY_DIR_EXECUTABLE/sapcontrol"
 
317
    then
 
318
      DIR_EXECUTABLE="$OCF_RESKEY_DIR_EXECUTABLE"
 
319
      SAPSTARTSRV="$OCF_RESKEY_DIR_EXECUTABLE/sapstartsrv"
 
320
      SAPCONTROL="$OCF_RESKEY_DIR_EXECUTABLE/sapcontrol"
 
321
    fi
 
322
  fi
 
323
 
 
324
  [ -z "$DIR_EXECUTABLE" ] && abnormal_end "Cannot find sapstartsrv and sapcontrol executable, please set DIR_EXECUTABLE parameter!"
 
325
 
 
326
  if [ -z "$OCF_RESKEY_DIR_PROFILE" ]
 
327
  then
 
328
    DIR_PROFILE="/usr/sap/$SID/SYS/profile"
 
329
  else
 
330
    DIR_PROFILE="$OCF_RESKEY_DIR_PROFILE"
 
331
  fi
 
332
 
 
333
  if [ "$myInstanceName" != "$OCF_RESKEY_InstanceName" ]
 
334
  then
 
335
    currentSTART_PROFILE=$OCF_RESKEY_ERS_START_PROFILE
 
336
  else
 
337
    currentSTART_PROFILE=$OCF_RESKEY_START_PROFILE
 
338
  fi
 
339
 
 
340
  if [ -z "$currentSTART_PROFILE" ]
 
341
  then
 
342
    SAPSTARTPROFILE="$DIR_PROFILE/START_${InstanceName}_${SAPVIRHOST}"
 
343
  else
 
344
    SAPSTARTPROFILE="$currentSTART_PROFILE"
 
345
  fi
 
346
 
 
347
  if [ -z "$OCF_RESKEY_START_WAITTIME" ]
 
348
  then
 
349
    export OCF_RESKEY_START_WAITTIME=3600
 
350
  fi
 
351
 
 
352
  if [ -z "$OCF_RESKEY_MONITOR_SERVICES" ]
 
353
  then
 
354
    export OCF_RESKEY_MONITOR_SERVICES="disp+work|msg_server|enserver|enrepserver|jcontrol|jstart"
 
355
  fi
 
356
 
 
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
 
361
  fi
 
362
 
 
363
  sidadm="`echo $SID | tr '[:upper:]' '[:lower:]'`adm"
 
364
 
 
365
  return $OCF_SUCCESS
 
366
}
 
367
 
 
368
 
 
369
#
 
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.
 
373
#
 
374
check_sapstartsrv() {
 
375
  restart=0
 
376
  runninginst=""
 
377
  chkrc=$OCF_SUCCESS
 
378
 
 
379
  output=`$SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script`
 
380
  if [ $? -eq 0 ]
 
381
  then
 
382
    runninginst=`echo "$output" | grep '^0 : ' | cut -d' ' -f3`
 
383
    if [ "$runninginst" != "$InstanceName" ]
 
384
    then 
 
385
      ocf_log warn "sapstartsrv is running for instance $runninginst, that service will be killed"
 
386
      restart=1
 
387
    fi
 
388
  else
 
389
    ocf_log warn "sapstartsrv is not running for instance $SID-$InstanceName, it will be started now"
 
390
    restart=1
 
391
  fi
 
392
 
 
393
  if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi
 
394
 
 
395
  if [ $restart -eq 1 ]
 
396
  then
 
397
 
 
398
    if [ -d /usr/sap/$SID/SYS/profile/ ]
 
399
    then
 
400
      DIR_PROFILE="/usr/sap/$SID/SYS/profile"
 
401
    else
 
402
      abnormal_end "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!"
 
403
    fi
 
404
 
 
405
    [ ! -r $SAPSTARTPROFILE ] && abnormal_end "Expected $SAPSTARTPROFILE to be the instance START profile, please set START_PROFILE parameter!"
 
406
 
 
407
    pkill -9 -f "sapstartsrv.*$runninginst"
 
408
    $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
 
409
 
 
410
    # now make sure the daemon has been started and is able to respond
 
411
    srvrc=1
 
412
    while [ $srvrc -eq 1 -a `pgrep -f "sapstartsrv.*$runninginst" | wc -l` -gt 0 ]
 
413
    do
 
414
      sleep 1
 
415
      $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1
 
416
      srvrc=$?
 
417
    done
 
418
 
 
419
    if [ $srvrc -ne 1 ]
 
420
    then
 
421
      ocf_log info "sapstartsrv for instance $SID-$InstanceName was restarted !"
 
422
      chkrc=$OCF_SUCCESS
 
423
    else
 
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
 
427
    fi
 
428
  fi
 
429
 
 
430
  return $chkrc
 
431
}
 
432
 
 
433
 
 
434
#
 
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
 
440
#               was introduced.
 
441
#
 
442
sapuserexit() {
 
443
  NAME="$1"
 
444
  VALUE="$2"
 
445
 
 
446
  if [ -n "$VALUE" ]
 
447
  then
 
448
    if have_binary "$VALUE"
 
449
    then
 
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: $?"
 
453
    else
 
454
      ocf_log warn "Attribute ${NAME} is set to ${VALUE}, but this file is not executable"
 
455
    fi
 
456
  fi
 
457
  return 0
 
458
}
 
459
 
 
460
 
 
461
#
 
462
# cleanup_instance : remove resources (processes and shared memory) from a crashed instance)
 
463
#
 
464
cleanup_instance() {
 
465
  pkill -9 -f -U $sidadm $InstanceName
 
466
  ocf_log info "Terminated instance using 'pkill -9 -f -U $sidadm $InstanceName'"
 
467
 
 
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"
 
471
 
 
472
  if [ -f "/usr/sap/$SID/$InstanceName/work/kill.sap" ]
 
473
  then
 
474
    rm -f /usr/sap/$SID/$InstanceName/work/kill.sap
 
475
    ocf_log info "Deleted /usr/sap/$SID/$InstanceName/work/kill.sap"
 
476
  fi
 
477
 
 
478
  return 0
 
479
}
 
480
 
 
481
#
 
482
# sapinstance_start : Start the SAP instance
 
483
#
 
484
sapinstance_start() {
 
485
 
 
486
  sapuserexit PRE_START_USEREXIT "$OCF_RESKEY_PRE_START_USEREXIT"
 
487
 
 
488
  rc=$OCF_NOT_RUNNING
 
489
  loopcount=0
 
490
  while [ $loopcount -lt 2 ]
 
491
  do
 
492
    loopcount=$(($loopcount + 1))
 
493
 
 
494
    check_sapstartsrv
 
495
    rc=$?
 
496
    if [ $rc -eq $OCF_SUCCESS ]; then
 
497
      output=`$SAPCONTROL -nr $InstanceNr -function Start`
 
498
      rc=$?
 
499
      ocf_log info "Starting SAP Instance $SID-$InstanceName: $output"
 
500
    fi
 
501
 
 
502
    if [ $rc -ne 0 ]
 
503
    then
 
504
      ocf_log err "SAP Instance $SID-$InstanceName start failed."
 
505
      return $OCF_ERR_GENERIC
 
506
    fi
 
507
 
 
508
    startrc=1
 
509
    while [ $startrc -gt 0 ]
 
510
    do
 
511
      waittime_start=`date +%s`
 
512
      output=`$SAPCONTROL -nr $InstanceNr -function WaitforStarted $OCF_RESKEY_START_WAITTIME 10`
 
513
      startrc=$?
 
514
      waittime_stop=`date +%s`
 
515
 
 
516
      if [ $startrc -ne 0 ]
 
517
      then
 
518
        if [ $(($waittime_stop - $waittime_start)) -ge $OCF_RESKEY_START_WAITTIME ]
 
519
        then
 
520
          sapinstance_monitor NOLOG
 
521
          if [ $? -eq $OCF_SUCCESS ]
 
522
          then
 
523
            output="START_WAITTIME ($OCF_RESKEY_START_WAITTIME) has elapsed, but instance monitor returned SUCCESS. Instance considered running."
 
524
            startrc=0; loopcount=2
 
525
          fi
 
526
        else
 
527
          if [ $loopcount -eq 1 ] && ocf_is_true $OCF_RESKEY_AUTOMATIC_RECOVER
 
528
          then
 
529
            ocf_log warn "SAP Instance $SID-$InstanceName start failed: $output"
 
530
            ocf_log warn "Try to recover $SID-$InstanceName"
 
531
            cleanup_instance
 
532
          else
 
533
            loopcount=2
 
534
          fi
 
535
          startrc=-1
 
536
        fi
 
537
      else
 
538
        loopcount=2
 
539
      fi
 
540
    done
 
541
  done
 
542
 
 
543
  if [ $startrc -eq 0 ]
 
544
  then
 
545
    ocf_log info "SAP Instance $SID-$InstanceName started: $output"
 
546
    rc=$OCF_SUCCESS
 
547
    sapuserexit POST_START_USEREXIT "$OCF_RESKEY_POST_START_USEREXIT"
 
548
  else
 
549
    ocf_log err "SAP Instance $SID-$InstanceName start failed: $output"
 
550
    rc=$OCF_NOT_RUNNING
 
551
  fi
 
552
 
 
553
  return $rc
 
554
}
 
555
 
 
556
 
 
557
#
 
558
# sapinstance_recover: Try startup of failed instance by cleaning up resources
 
559
#
 
560
sapinstance_recover() {
 
561
  cleanup_instance
 
562
  sapinstance_start
 
563
  return $?
 
564
}
 
565
 
 
566
 
 
567
#
 
568
# sapinstance_stop: Stop the SAP instance
 
569
#
 
570
sapinstance_stop() {
 
571
  sapuserexit PRE_STOP_USEREXIT "$OCF_RESKEY_PRE_STOP_USEREXIT"
 
572
 
 
573
  if [ "$OCF_RESKEY_SHUTDOWN_METHOD" = "KILL" ]
 
574
  then
 
575
    ocf_log info "Stopping SAP Instance $SID-$InstanceName with shutdown method KILL!"
 
576
    cleanup_instance
 
577
    return $OCF_SUCCESS
 
578
  fi
 
579
 
 
580
  check_sapstartsrv
 
581
  rc=$?
 
582
  if [ $rc -eq $OCF_SUCCESS ]; then
 
583
    output=`$SAPCONTROL -nr $InstanceNr -function Stop`
 
584
    rc=$?
 
585
    ocf_log info "Stopping SAP Instance $SID-$InstanceName: $output"
 
586
  fi
 
587
 
 
588
  if [ $? -eq 0 ]
 
589
  then
 
590
    output=`$SAPCONTROL -nr $InstanceNr -function WaitforStopped 3600 1`
 
591
    if [ $? -eq 0 ]
 
592
    then
 
593
      ocf_log info "SAP Instance $SID-$InstanceName stopped: $output"
 
594
      rc=$OCF_SUCCESS
 
595
    else
 
596
      ocf_log err "SAP Instance $SID-$InstanceName stop failed: $output"
 
597
      rc=$OCF_ERR_GENERIC
 
598
    fi
 
599
  else
 
600
    ocf_log err "SAP Instance $SID-$InstanceName stop failed: $output"
 
601
    rc=$OCF_ERR_GENERIC
 
602
  fi
 
603
 
 
604
  sapuserexit POST_STOP_USEREXIT "$OCF_RESKEY_POST_STOP_USEREXIT"
 
605
 
 
606
  return $rc
 
607
}
 
608
 
 
609
 
 
610
#
 
611
# sapinstance_monitor: Can the given SAP instance do anything useful?
 
612
#
 
613
sapinstance_monitor() {
 
614
  MONLOG=$1
 
615
  check_sapstartsrv
 
616
  rc=$?
 
617
 
 
618
  if [ $rc -eq $OCF_SUCCESS ]
 
619
  then
 
620
    count=0
 
621
    output=`$SAPCONTROL -nr $InstanceNr -function GetProcessList -format script`
 
622
 
 
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`
 
625
    do
 
626
      COLOR=`echo "$output" | grep "^$SERVNO dispstatus: " | cut -d' ' -f3`
 
627
      SERVICE=`echo "$output" | grep "^$SERVNO name: " | cut -d' ' -f3`
 
628
      STATE=0
 
629
 
 
630
      case $COLOR in
 
631
        GREEN|YELLOW)       STATE=$OCF_SUCCESS;;
 
632
        *)                  STATE=$OCF_NOT_RUNNING;;
 
633
      esac 
 
634
 
 
635
      SEARCH=`echo "$OCF_RESKEY_MONITOR_SERVICES" | sed 's/\+/\\\+/g' | sed 's/\./\\\./g'`
 
636
      if [ `echo "$SERVICE" | egrep -c "$SEARCH"` -eq 1 ]
 
637
      then
 
638
          if [ $STATE -eq $OCF_NOT_RUNNING ]
 
639
          then
 
640
            [ "$MONLOG" != "NOLOG" ] && ocf_log err "SAP instance service $SERVICE is not running with status $COLOR !"
 
641
            rc=$STATE
 
642
          fi
 
643
          count=1
 
644
      fi
 
645
    done
 
646
 
 
647
    if [ $count -eq 0 -a $rc -eq $OCF_SUCCESS ]
 
648
    then
 
649
      if ocf_is_probe
 
650
      then
 
651
        rc=$OCF_NOT_RUNNING
 
652
      else
 
653
        [ "$MONLOG" != "NOLOG" ] && ocf_log err "The SAP instance does not run any services which this RA could monitor!"
 
654
        rc=$OCF_ERR_GENERIC
 
655
      fi
 
656
    fi
 
657
  fi
 
658
 
 
659
  return $rc
 
660
}
 
661
 
 
662
 
 
663
#
 
664
# sapinstance_status: Lightweight check of SAP instance only with OS tools
 
665
#
 
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}'`
 
669
  for pid in $pids
 
670
  do
 
671
    [ `pgrep -f -U $sidadm $InstanceName | grep -c $pid` -gt 0 ] && return $OCF_SUCCESS
 
672
  done
 
673
  return $OCF_NOT_RUNNING
 
674
}
 
675
 
 
676
 
 
677
#
 
678
# sapinstance_validate: Check the symantic of the input parameters 
 
679
#
 
680
sapinstance_validate() {
 
681
  rc=$OCF_SUCCESS
 
682
  if [ `echo "$SID" | grep -c '^[A-Z][A-Z0-9][A-Z0-9]$'` -ne 1 ]
 
683
  then
 
684
    ocf_log err "Parsing instance profile name: '$SID' is not a valid system ID!"
 
685
    rc=$OCF_ERR_ARGS
 
686
  fi
 
687
 
 
688
  if [ `echo "$InstanceName" | grep -c '^[A-Z].*[0-9][0-9]$'` -ne 1 ]
 
689
  then
 
690
    ocf_log err "Parsing instance profile name: '$InstanceName' is not a valid instance name!"
 
691
    rc=$OCF_ERR_ARGS
 
692
  fi
 
693
 
 
694
  if [ `echo "$InstanceNr" | grep -c '^[0-9][0-9]$'` -ne 1 ]
 
695
  then
 
696
    ocf_log err "Parsing instance profile name: '$InstanceNr' is not a valid instance number!"
 
697
    rc=$OCF_ERR_ARGS
 
698
  fi
 
699
 
 
700
  if [ `echo "$SAPVIRHOST" | grep -c '^[A-Za-z][A-Za-z0-9_-]*$'` -ne 1 ]
 
701
  then
 
702
    ocf_log err "Parsing instance profile name: '$SAPVIRHOST' is not a valid hostname!"
 
703
    rc=$OCF_ERR_ARGS
 
704
  fi
 
705
 
 
706
  return $rc
 
707
}
 
708
 
 
709
 
 
710
#
 
711
# sapinstance_start_clone
 
712
#
 
713
sapinstance_start_clone() {
 
714
  sapinstance_init $OCF_RESKEY_ERS_InstanceName
 
715
  ${HA_SBIN_DIR}/crm_master -v 50 -l reboot
 
716
  sapinstance_start
 
717
  return $?
 
718
}
 
719
 
 
720
 
 
721
#
 
722
# sapinstance_stop_clone
 
723
#
 
724
sapinstance_stop_clone() {
 
725
  sapinstance_init $OCF_RESKEY_ERS_InstanceName
 
726
  ${HA_SBIN_DIR}/crm_master -v 0 -l reboot
 
727
  sapinstance_stop
 
728
  return $?
 
729
}
 
730
 
 
731
 
 
732
#
 
733
# sapinstance_monitor_clone
 
734
#
 
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
 
739
 
 
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
 
745
    fi
 
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
 
752
  fi
 
753
 
 
754
  sapinstance_init $OCF_RESKEY_ERS_InstanceName
 
755
  sapinstance_status && sapinstance_monitor
 
756
  rc=$?
 
757
  if [ $rc -eq $OCF_SUCCESS ]; then
 
758
    ${HA_SBIN_DIR}/crm_master -Q -v 100 -l reboot
 
759
  fi
 
760
  return $rc
 
761
}
 
762
 
 
763
 
 
764
#
 
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
 
767
#
 
768
sapinstance_promote_clone() {
 
769
  sapinstance_init $OCF_RESKEY_InstanceName
 
770
  ocf_log info "Promoting $SID-$InstanceName to running Master."
 
771
  sapinstance_start
 
772
  rc=$?
 
773
 
 
774
  if [ $rc -eq $OCF_SUCCESS ]; then
 
775
    sapinstance_init $OCF_RESKEY_ERS_InstanceName
 
776
    sapinstance_stop
 
777
    rc=$?
 
778
  fi
 
779
 
 
780
  return $rc
 
781
}
 
782
 
 
783
 
 
784
#
 
785
# sapinstance_demote_clone: In a Master/Slave configuration get Slave by stopping the SCS instance and starting the ERS instance
 
786
#
 
787
sapinstance_demote_clone() {
 
788
  sapinstance_init $OCF_RESKEY_InstanceName
 
789
  ocf_log info "Demoting $SID-$InstanceName to a slave."
 
790
  sapinstance_stop
 
791
  rc=$?
 
792
 
 
793
  if [ $rc -eq $OCF_SUCCESS ]; then
 
794
    sapinstance_init $OCF_RESKEY_ERS_InstanceName
 
795
    sapinstance_start
 
796
    rc=$?
 
797
  fi
 
798
 
 
799
  return $rc
 
800
}
 
801
 
 
802
 
 
803
#
 
804
# sapinstance_notify: Handle master scoring - to make sure a slave gets the next master
 
805
#
 
806
sapinstance_notify() {
 
807
  local n_type="$OCF_RESKEY_CRM_meta_notify_type"
 
808
  local n_op="$OCF_RESKEY_CRM_meta_notify_operation"
 
809
 
 
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
 
822
    fi
 
823
  fi
 
824
}
 
825
 
 
826
 
 
827
#
 
828
#       'main' starts here...
 
829
#
 
830
 
 
831
## GLOBALS
 
832
SID=""
 
833
sidadm=""
 
834
InstanceName=""
 
835
InstanceNr=""
 
836
SAPVIRHOST=""
 
837
DIR_EXECUTABLE=""
 
838
SAPSTARTSRV=""
 
839
SAPCONTROL=""
 
840
DIR_PROFILE=""
 
841
SAPSTARTPROFILE=""
 
842
CLONE=0
 
843
 
 
844
 
 
845
if
 
846
  ( [ $# -ne 1 ] )
 
847
then
 
848
  sapinstance_usage
 
849
  exit $OCF_ERR_ARGS
 
850
fi
 
851
 
 
852
ACTION=$1
 
853
if [ "$ACTION" = "status" ]; then
 
854
  ACTION=monitor
 
855
fi
 
856
 
 
857
# These operations don't require OCF instance parameters to be set
 
858
case "$ACTION" in
 
859
  usage|methods)                sapinstance_$ACTION
 
860
                                exit $OCF_SUCCESS;;
 
861
  meta-data)                    sapinstance_meta_data
 
862
                                exit $OCF_SUCCESS;;
 
863
  notify)                       sapinstance_notify
 
864
                                exit $OCF_SUCCESS;;
 
865
  *);;
 
866
esac
 
867
 
 
868
if ! ocf_is_root
 
869
then
 
870
  ocf_log err "$0 must be run as root"
 
871
  exit $OCF_ERR_PERM
 
872
fi
 
873
 
 
874
# parameter check
 
875
if  [ -z "$OCF_RESKEY_InstanceName" ]
 
876
then
 
877
  ocf_log err "Please set OCF_RESKEY_InstanceName to the name to the SAP instance profile!"
 
878
  exit $OCF_ERR_ARGS
 
879
fi
 
880
 
 
881
is_clone; CLONE=$?
 
882
if [ ${CLONE} -eq 1 ]
 
883
then
 
884
  CLACT=_clone
 
885
else
 
886
  if [ "$ACTION" = "promote" -o "$ACTION" = "demote" ]
 
887
  then
 
888
    ocf_log err "$ACTION called in a non master/slave environment"
 
889
    exit $OCF_ERR_ARGS
 
890
  fi
 
891
  sapinstance_init $OCF_RESKEY_InstanceName
 
892
fi
 
893
 
 
894
# What kind of method was invoked?
 
895
case "$ACTION" in
 
896
  start|stop|monitor|promote|demote)      sapinstance_$ACTION$CLACT
 
897
                                          exit $?;;
 
898
  validate-all)                           sapinstance_validate
 
899
                                          exit $?;;
 
900
  *)                                      sapinstance_methods
 
901
                                          exit $OCF_ERR_UNIMPLEMENTED;;
 
902
esac