~ubuntu-branches/ubuntu/precise/resource-agents/precise-updates

« back to all changes in this revision

Viewing changes to .pc/CVE-2010-3389--bug598549.patch/heartbeat/SAPDatabase

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2011-10-26 11:35:07 UTC
  • mfrom: (1.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20111026113507-p2vrydodf38hxiuf
Tags: 1:3.9.2-4ubuntu1
* Resync from debian unstable (LP: #882097)
* debian/control:
  - rgmanager conflicts/replaces to Ubuntu versions.
  - add conflicts/replaces for ldirectord.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
# SAPDatabase
 
4
#
 
5
# Description:  Manages any type of SAP supported database instance
 
6
#               as a High-Availability OCF compliant resource.
 
7
#
 
8
# Author:       Alexander Krauth, October 2006
 
9
# Support:      linux@sap.com
 
10
# License:      GNU General Public License (GPL)
 
11
# Copyright:    (c) 2006, 2007 Alexander Krauth
 
12
#
 
13
# An example usage: 
 
14
#      See usage() function below for more details...
 
15
#
 
16
# OCF instance parameters:
 
17
#       OCF_RESKEY_SID
 
18
#       OCF_RESKEY_DIR_EXECUTABLE   (optional, well known directories will be searched by default)
 
19
#       OCF_RESKEY_DBTYPE
 
20
#       OCF_RESKEY_NETSERVICENAME   (optional, non standard name of Oracle Listener)
 
21
#       OCF_RESKEY_DBJ2EE_ONLY      (optional, default is false)
 
22
#       OCF_RESKEY_JAVA_HOME        (optional, only needed if DBJ2EE_ONLY is true and JAVA_HOME enviroment variable is not set)
 
23
#       OCF_RESKEY_STRICT_MONITORING (optional, activate application level monitoring - with Oracle a failover will occur in case of an archiver stuck)
 
24
#       OCF_RESKEY_AUTOMATIC_RECOVER (optional, automatic startup recovery, default is false)
 
25
#       OCF_RESKEY_DIR_BOOTSTRAP    (optional, if non standard J2EE server directory)
 
26
#       OCF_RESKEY_DIR_SECSTORE     (optional, if non standard J2EE secure store directory)
 
27
#       OCF_RESKEY_DB_JARS          (optional, if maintained in bootstrap.properties, mandatory for WebAS Java 7.10)
 
28
#       OCF_RESKEY_PRE_START_USEREXIT   (optional, lists a script which can be executed before the resource is started)
 
29
#       OCF_RESKEY_POST_START_USEREXIT  (optional, lists a script which can be executed after the resource is started)
 
30
#       OCF_RESKEY_PRE_STOP_USEREXIT    (optional, lists a script which can be executed before the resource is stopped)
 
31
#       OCF_RESKEY_POST_STOP_USEREXIT   (optional, lists a script which can be executed after the resource is stopped)
 
32
#
 
33
# ToDo:
 
34
# Remove all the database dependend stuff from the agent and use
 
35
# saphostcontrol daemon as soon as SAP will release it.
 
36
#
 
37
#######################################################################
 
38
# Initialization:
 
39
 
 
40
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
 
41
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
 
42
 
 
43
#######################################################################
 
44
 
 
45
SH=/bin/sh
 
46
 
 
47
usage() {
 
48
  methods=`sapdatabase_methods`
 
49
  methods=`echo $methods | tr ' ' '|'`
 
50
  cat <<-!
 
51
        usage: $0 ($methods)
 
52
 
 
53
        $0 manages a SAP database of any type as an HA resource.
 
54
        Currently Oracle, MaxDB and DB/2 UDB are supported.
 
55
        ABAP databases as well as JAVA only databases are supported.
 
56
 
 
57
        The 'start' operation starts the instance.
 
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 'recover' operation tries to recover the instance after a crash (instance will be stopped first!)
 
62
        The 'validate-all' operation reports whether the parameters are valid
 
63
        The 'methods' operation reports on the methods $0 supports
 
64
 
 
65
        !
 
66
}
 
67
 
 
68
meta_data() {
 
69
        cat <<END
 
70
<?xml version="1.0"?>
 
71
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
 
72
<resource-agent name="SAPDatabase">
 
73
<version>1.93</version>
 
74
 
 
75
<longdesc lang="en">
 
76
Resource script for SAP databases. It manages a SAP database of any type as an HA resource.
 
77
</longdesc>
 
78
<shortdesc lang="en">Manages any SAP database (based on Oracle, MaxDB, or DB2)</shortdesc>
 
79
 
 
80
<parameters>
 
81
 <parameter name="SID" unique="1" required="1">
 
82
  <longdesc lang="en">The unique SAP system identifier. e.g. P01</longdesc>
 
83
  <shortdesc lang="en">SAP system ID</shortdesc>
 
84
  <content type="string" default="" />
 
85
 </parameter>
 
86
 <parameter name="DIR_EXECUTABLE" unique="1" required="0">
 
87
  <longdesc lang="en">The full qualified path where to find sapstartsrv and sapcontrol.</longdesc>
 
88
  <shortdesc lang="en">path of sapstartsrv and sapcontrol</shortdesc>
 
89
  <content type="string" default="" />
 
90
 </parameter>
 
91
 <parameter name="DBTYPE" unique="1" required="1">
 
92
  <longdesc lang="en">The name of the database vendor you use. Set either: ORA,DB6,ADA</longdesc>
 
93
  <shortdesc lang="en">database vendor</shortdesc>
 
94
  <content type="string" default="" />
 
95
 </parameter>
 
96
 <parameter name="NETSERVICENAME" unique="1" required="0">
 
97
  <longdesc lang="en">The Oracle TNS listener name.</longdesc>
 
98
  <shortdesc lang="en">listener name</shortdesc>
 
99
  <content type="string" default="" />
 
100
 </parameter>
 
101
 <parameter name="DBJ2EE_ONLY" unique="1" required="0">
 
102
  <longdesc lang="en">If you do not have a ABAP stack installed in the SAP database, set this to TRUE</longdesc>
 
103
  <shortdesc lang="en">only JAVA stack installed</shortdesc>
 
104
  <content type="boolean" default="false"/>
 
105
 </parameter>
 
106
 <parameter name="JAVA_HOME" unique="1" required="0">
 
107
  <longdesc lang="en">This is only needed if the DBJ2EE_ONLY parameter is set to true. Enter the path to the Java SDK which is used by the SAP WebAS Java</longdesc>
 
108
  <shortdesc lang="en">Path to Java SDK</shortdesc>
 
109
  <content type="string" default=""/>
 
110
 </parameter>
 
111
 <parameter name="STRICT_MONITORING" unique="1" required="0">
 
112
  <longdesc lang="en">This controls how the resource agent monitors the database. If set to true, it will use SAP tools to test the connect to the database. Do not use with Oracle, because it will result in unwanted failovers in case of an archiver stuck</longdesc>
 
113
  <shortdesc lang="en">Activates application level monitoring</shortdesc>
 
114
  <content type="boolean" default="false"/>
 
115
 </parameter>
 
116
 <parameter name="AUTOMATIC_RECOVER" unique="1" required="0">
 
117
  <longdesc lang="en">The SAPDatabase resource agent tries to recover a failed start attempt automatically one time. This is done by running a forced abort of the RDBMS and/or executing recovery commands.</longdesc>
 
118
  <shortdesc lang="en">Enable or disable automatic startup recovery</shortdesc>
 
119
  <content type="boolean" default="false"/>
 
120
 </parameter>
 
121
 <parameter name="DIR_BOOTSTRAP" unique="1" required="0">
 
122
  <longdesc lang="en">The full qualified path where to find the J2EE instance bootstrap directory. e.g. /usr/sap/P01/J00/j2ee/cluster/bootstrap</longdesc>
 
123
  <shortdesc lang="en">path to j2ee bootstrap directory</shortdesc>
 
124
  <content type="string" default="" />
 
125
 </parameter>
 
126
 <parameter name="DIR_SECSTORE" unique="1" required="0">
 
127
  <longdesc lang="en">The full qualified path where to find the J2EE security store directory. e.g. /usr/sap/P01/SYS/global/security/lib/tools</longdesc>
 
128
  <shortdesc lang="en">path to j2ee secure store directory</shortdesc>
 
129
  <content type="string" default="" />
 
130
 </parameter>
 
131
 <parameter name="DB_JARS" unique="1" required="0">
 
132
  <longdesc lang="en">The full qualified filename of the jdbc driver for the database connection test. It will be automatically read from the bootstrap.properties file in Java engine 6.40 and 7.00. For Java engine 7.10 and higher the parameter is mandatory.</longdesc>
 
133
  <shortdesc lang="en">file name of the jdbc driver</shortdesc>
 
134
  <content type="string" default="" />
 
135
 </parameter>
 
136
 <parameter name="PRE_START_USEREXIT" unique="1" required="0">
 
137
  <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets started.</longdesc>
 
138
  <shortdesc lang="en">path to a pre-start script</shortdesc>
 
139
  <content type="string" default="" />
 
140
 </parameter>
 
141
 <parameter name="POST_START_USEREXIT" unique="1" required="0">
 
142
  <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got started.</longdesc>
 
143
  <shortdesc lang="en">path to a post-start script</shortdesc>
 
144
  <content type="string" default="" />
 
145
 </parameter>
 
146
 <parameter name="PRE_STOP_USEREXIT" unique="1" required="0">
 
147
  <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets stopped.</longdesc>
 
148
  <shortdesc lang="en">path to a pre-start script</shortdesc>
 
149
  <content type="string" default="" />
 
150
 </parameter>
 
151
 <parameter name="POST_STOP_USEREXIT" unique="1" required="0">
 
152
  <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got stopped.</longdesc>
 
153
  <shortdesc lang="en">path to a post-start script</shortdesc>
 
154
  <content type="string" default="" />
 
155
 </parameter>
 
156
</parameters>
 
157
 
 
158
<actions>
 
159
<action name="start" timeout="1800" />
 
160
<action name="stop" timeout="1800" />
 
161
<action name="status" timeout="60" />
 
162
<action name="monitor" depth="0" timeout="60" interval="120" />
 
163
<action name="validate-all" timeout="5" />
 
164
<action name="meta-data" timeout="5" />
 
165
<action name="methods" timeout="5" />
 
166
</actions>
 
167
</resource-agent>
 
168
END
 
169
}
 
170
 
 
171
trap_handler() {
 
172
  rm -f $TEMPFILE
 
173
  exit $OCF_ERR_GENERIC
 
174
}
 
175
 
 
176
 
 
177
#
 
178
# listener_start: Start the given listener
 
179
#
 
180
listener_start() {
 
181
  local orasid="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
 
182
  local lrc=$OCF_SUCCESS
 
183
  local output
 
184
  output=`echo "lsnrctl start $NETSERVICENAME" | su - $orasid 2>&1`
 
185
  if [ $? -eq 0 ]
 
186
  then
 
187
    ocf_log info "Oracle Listener $NETSERVICENAME started: $output"
 
188
    lrc=$OCF_SUCCESS
 
189
  else
 
190
    ocf_log err "Oracle Listener $NETSERVICENAME start failed: $output"
 
191
    lrc=$OCF_ERR_GENERIC
 
192
  fi
 
193
  return $lrc
 
194
}
 
195
 
 
196
#
 
197
# listener_stop: Stop the given listener
 
198
#
 
199
listener_stop() {
 
200
  local orasid="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
 
201
  local lrc=$OCF_SUCCESS
 
202
  if
 
203
      listener_status
 
204
  then
 
205
      : listener is running, trying to stop it later...
 
206
  else
 
207
      return $OCF_SUCCESS
 
208
  fi
 
209
  local output
 
210
  output=`echo "lsnrctl stop $NETSERVICENAME" | su - $orasid 2>&1`
 
211
  if [ $? -eq 0 ]
 
212
  then
 
213
    ocf_log info "Oracle Listener $NETSERVICENAME stopped: $output"
 
214
  else
 
215
    ocf_log err "Oracle Listener $NETSERVICENAME stop failed: $output"
 
216
    lrc=$OCF_ERR_GENERIC
 
217
  fi
 
218
  return $lrc
 
219
}
 
220
 
 
221
#
 
222
# listener_status: is the given listener running?
 
223
#
 
224
listener_status() {
 
225
  local lrc=$OCF_SUCCESS
 
226
  local orasid="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
 
227
  # Note: ps cuts off it's output at column $COLUMNS, so "ps -ef" can not be used here
 
228
  # as the output might be to long.
 
229
  local cnt=`ps efo args --user $orasid | grep $NETSERVICENAME | grep -c tnslsnr`
 
230
  if [ $cnt -eq 1 ]
 
231
  then
 
232
    lrc=$OCF_SUCCESS
 
233
  else
 
234
    ocf_log info "listener process not running for $NETSERVICENAME for $SID"
 
235
    lrc=$OCF_ERR_GENERIC
 
236
  fi
 
237
  return $lrc
 
238
}
 
239
 
 
240
#
 
241
# x_server_start: Start the given x_server
 
242
#
 
243
x_server_start() {
 
244
  local rc=$OCF_SUCCESS
 
245
  local output
 
246
  output=`echo "x_server start" | su - $sidadm 2>&1`
 
247
  if [ $? -eq 0 ]
 
248
  then
 
249
    ocf_log info "MaxDB x_server start: $output"
 
250
    lrc=$OCF_SUCCESS
 
251
  else
 
252
    ocf_log err "MaxDB x_server start failed: $output"
 
253
    lrc=$OCF_ERR_GENERIC
 
254
  fi
 
255
  return $lrc
 
256
}
 
257
 
 
258
#
 
259
# x_server_stop: Stop the x_server
 
260
#
 
261
x_server_stop() {
 
262
  local lrc=$OCF_SUCCESS
 
263
  local output
 
264
  output=`echo "x_server stop" | su - $sidadm 2>&1`
 
265
  if [ $? -eq 0 ]
 
266
  then
 
267
    ocf_log info "MaxDB x_server stop: $output"
 
268
  else
 
269
    ocf_log err "MaxDB x_server stop failed: $output"
 
270
    lrc=$OCF_ERR_GENERIC
 
271
  fi
 
272
  return $lrc
 
273
}
 
274
 
 
275
#
 
276
# x_server_status: is the x_server running?
 
277
#
 
278
x_server_status() {
 
279
  local lrc=$OCF_SUCCESS
 
280
  local sdbuser=`grep "^SdbOwner" /etc/opt/sdb | awk -F'=' '{print $2}'`
 
281
  # Note: ps cuts off it's output at column $COLUMNS, so "ps -ef" can not be used here
 
282
  # as the output might be to long.
 
283
  local cnt=`ps efo args --user $sdbuser | grep -c vserver`
 
284
  if [ $cnt -ge 1 ]
 
285
  then
 
286
    lrc=$OCF_SUCCESS
 
287
  else
 
288
    ocf_log info "x_server process not running"
 
289
    lrc=$OCF_ERR_GENERIC
 
290
  fi
 
291
  return $lrc
 
292
}
 
293
 
 
294
#
 
295
# oracle_stop: Stop the Oracle database without any condition
 
296
#
 
297
oracle_stop() {
 
298
echo '#!/bin/sh
 
299
LOG=$HOME/stopdb.log
 
300
date > $LOG
 
301
 
 
302
if [ -x "${ORACLE_HOME}/bin/sqlplus" ]
 
303
then
 
304
    SRVMGRDBA_EXE="${ORACLE_HOME}/bin/sqlplus"
 
305
else
 
306
   echo "Can not find executable sqlplus" >> $LOG
 
307
   exit 1
 
308
fi
 
309
 
 
310
$SRVMGRDBA_EXE /NOLOG >> $LOG << !
 
311
connect / as sysdba
 
312
shutdown immediate
 
313
exit
 
314
!
 
315
rc=$?
 
316
cat $LOG
 
317
exit $rc' > $TEMPFILE
 
318
 
 
319
chmod 700 $TEMPFILE
 
320
chown $sidadm $TEMPFILE
 
321
 
 
322
su - $sidadm -c $TEMPFILE
 
323
retcode=$?
 
324
rm -f $TEMPFILE
 
325
 
 
326
if [ $retcode -eq 0 ]; then
 
327
  sapdatabase_status
 
328
  if [ $? -ne $OCF_NOT_RUNNING ]; then
 
329
    retcode=1
 
330
  fi
 
331
fi
 
332
 
 
333
return $retcode
 
334
}
 
335
 
 
336
#
 
337
# maxdb_stop: Stop the MaxDB database without any condition
 
338
#
 
339
maxdb_stop() {
 
340
 
 
341
# x_Server must be running to stop database
 
342
x_server_status
 
343
if [ $? -ne $OCF_SUCCESS ]; then x_server_start; fi
 
344
 
 
345
if [ $DBJ2EE_ONLY -eq 1 ]; then
 
346
   userkey=c_J2EE
 
347
else
 
348
   userkey=c
 
349
fi
 
350
 
 
351
echo "#!/bin/sh
 
352
LOG=\$HOME/stopdb.log
 
353
date > \$LOG
 
354
echo \"Stop database with xuserkey >$userkey<\" >> \$LOG
 
355
dbmcli -U ${userkey} db_offline >> \$LOG 2>&1
 
356
exit \$?" > $TEMPFILE
 
357
 
 
358
chmod 700 $TEMPFILE
 
359
chown $sidadm $TEMPFILE
 
360
 
 
361
su - $sidadm -c $TEMPFILE
 
362
retcode=$?
 
363
rm -f $TEMPFILE
 
364
 
 
365
if [ $retcode -eq 0 ]; then
 
366
  sapdatabase_status
 
367
  if [ $? -ne $OCF_NOT_RUNNING ]; then
 
368
    retcode=1
 
369
  fi
 
370
fi
 
371
 
 
372
return $retcode
 
373
}
 
374
 
 
375
#
 
376
# db6udb_stop: Stop the DB2/UDB database without any condition
 
377
#
 
378
db6udb_stop() {
 
379
echo '#!/bin/sh
 
380
LOG=$HOME/stopdb.log
 
381
date > $LOG
 
382
echo "Shut down the database" >> $LOG
 
383
$INSTHOME/sqllib/bin/db2 deactivate database $DB2DBDFT |tee -a $LOG  2>&1
 
384
$INSTHOME/sqllib/adm/db2stop force |tee -a $LOG  2>&1
 
385
exit $?' > $TEMPFILE
 
386
 
 
387
chmod 700 $TEMPFILE
 
388
chown $sidadm $TEMPFILE
 
389
 
 
390
su - $sidadm -c $TEMPFILE
 
391
retcode=$?
 
392
rm -f $TEMPFILE
 
393
 
 
394
if [ $retcode -eq 0 ]; then
 
395
  sapdatabase_status
 
396
  if [ $? -ne $OCF_NOT_RUNNING ]; then
 
397
    retcode=1
 
398
  fi
 
399
fi
 
400
 
 
401
return $retcode
 
402
}
 
403
 
 
404
#
 
405
# oracle_recover: try to clean up oracle after a crash
 
406
#
 
407
oracle_recover() {
 
408
echo '#!/bin/sh
 
409
LOG=$HOME/recover.log
 
410
date > $LOG
 
411
echo "Logfile written by heartbeat SAPDatabase resource agent" >> $LOG
 
412
 
 
413
if [ -x "${ORACLE_HOME}/bin/sqlplus" ]
 
414
then
 
415
    SRVMGRDBA_EXE="${ORACLE_HOME}/bin/sqlplus"
 
416
else
 
417
   echo "Can not find executable sqlplus" >> $LOG
 
418
   exit 1
 
419
fi
 
420
 
 
421
$SRVMGRDBA_EXE /NOLOG >> $LOG << !
 
422
connect / as sysdba
 
423
shutdown abort
 
424
startup mount
 
425
alter database end backup;
 
426
alter database open;
 
427
exit
 
428
!
 
429
rc=$?
 
430
cat $LOG
 
431
exit $rc' > $TEMPFILE
 
432
 
 
433
  chmod 700 $TEMPFILE
 
434
  chown $sidadm $TEMPFILE
 
435
 
 
436
  su - $sidadm -c $TEMPFILE
 
437
  retcode=$?
 
438
  rm -f $TEMPFILE
 
439
 
 
440
  return $retcode
 
441
}
 
442
 
 
443
#
 
444
# maxdb_recover: try to clean up MaxDB after a crash
 
445
#
 
446
maxdb_recover() {
 
447
  # x_Server must be running to stop database
 
448
  x_server_status
 
449
  if [ $? -ne $OCF_SUCCESS ]; then x_server_start; fi
 
450
 
 
451
  if [ $DBJ2EE_ONLY -eq 1 ]; then
 
452
     userkey=c_J2EE
 
453
  else
 
454
     userkey=c
 
455
  fi
 
456
 
 
457
echo "#!/bin/sh
 
458
LOG=\$HOME/recover.log
 
459
date > \$LOG
 
460
echo \"Logfile written by heartbeat SAPDatabase resource agent\" >> \$LOG
 
461
echo \"Cleanup database with xuserkey >$userkey<\" >> \$LOG
 
462
echo \"db_stop\" >> \$LOG 2>&1
 
463
dbmcli -U ${userkey} db_stop >> \$LOG 2>&1
 
464
echo \"db_clear\" >> \$LOG 2>&1
 
465
dbmcli -U ${userkey} db_clear >> \$LOG 2>&1
 
466
echo \"db_online\" >> \$LOG 2>&1
 
467
dbmcli -U ${userkey} db_online >> \$LOG 2>&1
 
468
rc=\$?
 
469
cat \$LOG
 
470
exit \$rc" > $TEMPFILE
 
471
 
 
472
  chmod 700 $TEMPFILE
 
473
  chown $sidadm $TEMPFILE
 
474
 
 
475
  su - $sidadm -c $TEMPFILE
 
476
  retcode=$?
 
477
  rm -f $TEMPFILE
 
478
 
 
479
  return $retcode
 
480
}
 
481
 
 
482
#
 
483
# db6udb_recover: try to recover DB/2 after a crash
 
484
#
 
485
db6udb_recover() {
 
486
  db2sid="db2`echo $SID | tr '[:upper:]' '[:lower:]'`"
 
487
 
 
488
echo '#!/bin/sh
 
489
LOG=$HOME/recover.log
 
490
date > $LOG
 
491
echo "Logfile written by heartbeat SAPDatabase resource agent" >> $LOG
 
492
$INSTHOME/sqllib/bin/db2_kill >> $LOG  2>&1
 
493
$INSTHOME/sqllib/adm/db2start >> $LOG  2>&1
 
494
$INSTHOME/sqllib/bin/db2 activate database $DB2DBDFT >> $LOG  2>&1
 
495
rc=$?
 
496
cat $LOG
 
497
exit $rc' > $TEMPFILE
 
498
 
 
499
  chmod 700 $TEMPFILE
 
500
  chown $db2sid $TEMPFILE
 
501
 
 
502
  su - $db2sid -c $TEMPFILE
 
503
  retcode=$?
 
504
  rm -f $TEMPFILE
 
505
 
 
506
  return $retcode
 
507
}
 
508
 
 
509
#
 
510
# methods: What methods/operations do we support?
 
511
#
 
512
sapdatabase_methods() {
 
513
  cat <<-!
 
514
        start
 
515
        stop
 
516
        status
 
517
        monitor
 
518
        recover
 
519
        validate-all
 
520
        methods
 
521
        meta-data
 
522
        usage
 
523
        !
 
524
}
 
525
 
 
526
 
 
527
#
 
528
# sapuserexit : Many SAP customers need some additional processes/tools to run their SAP systems.
 
529
#               This specialties do not allow a totally generic SAP cluster resource agent.
 
530
#               Someone should write a resource agent for each additional process you need, if it
 
531
#               is required to monitor that process within the cluster manager. To enable
 
532
#               you to extent this resource agent without developing a new one, this user exit
 
533
#               was introduced.
 
534
#
 
535
sapuserexit() {
 
536
  NAME="$1"
 
537
  VALUE="$2"
 
538
 
 
539
  if [ -n "$VALUE" ]
 
540
  then
 
541
    if [ -x "$VALUE" ]
 
542
    then
 
543
      ocf_log info "Calling userexit ${NAME} with customer script file ${VALUE}"
 
544
      "$VALUE" >/dev/null 2>&1
 
545
      ocf_log info "Exiting userexit ${NAME} with customer script file ${VALUE}, returncode: $?"
 
546
    else
 
547
      ocf_log warn "Attribute ${NAME} is set to ${VALUE}, but this file is not executable"
 
548
    fi
 
549
  fi
 
550
  return 0
 
551
}
 
552
 
 
553
 
 
554
#
 
555
# sapdatabase_start : Start the SAP database
 
556
#
 
557
sapdatabase_start() {
 
558
  sapuserexit PRE_START_USEREXIT "$OCF_RESKEY_PRE_START_USEREXIT"
 
559
 
 
560
  case $DBTYPE in
 
561
    ADA) x_server_start
 
562
         ;;
 
563
    ORA) listener_start
 
564
         ;;
 
565
  esac
 
566
 
 
567
  output=`su - $sidadm -c $SAPSTARTDB`
 
568
  rc=$?
 
569
 
 
570
  if [ $DBJ2EE_ONLY -eq 1 ]
 
571
  then
 
572
    sapdatabase_monitor 1
 
573
    rc=$?
 
574
  fi
 
575
 
 
576
  if [ $rc -ne 0 -a $OCF_RESKEY_AUTOMATIC_RECOVER -eq 1 ]
 
577
  then
 
578
    ocf_log warn "SAP database $SID start failed: $output"
 
579
    ocf_log warn "Try to recover database $SID"
 
580
 
 
581
    output=''
 
582
    sapdatabase_recover
 
583
    rc=$?
 
584
  fi
 
585
 
 
586
  if [ $rc -eq 0 ]
 
587
  then
 
588
    ocf_log info "SAP database $SID started: $output"
 
589
    rc=$OCF_SUCCESS
 
590
    sapuserexit POST_START_USEREXIT "$OCF_RESKEY_POST_START_USEREXIT"
 
591
  else
 
592
    ocf_log err "SAP database $SID start failed: $output"
 
593
    rc=$OCF_ERR_GENERIC
 
594
  fi
 
595
 
 
596
  return $rc
 
597
}
 
598
 
 
599
#
 
600
# sapdatabase_stop: Stop the SAP database
 
601
#
 
602
sapdatabase_stop() {
 
603
 
 
604
  sapuserexit PRE_STOP_USEREXIT "$OCF_RESKEY_PRE_STOP_USEREXIT"
 
605
 
 
606
  # use of the stopdb kernel script is not possible, because there are to may checks in that
 
607
  # script. We want to stop the database regardless of anything.
 
608
  #output=`su - $sidadm -c $SAPSTOPDB`
 
609
 
 
610
  case $DBTYPE in
 
611
    ORA) output=`oracle_stop`
 
612
         ;;
 
613
    ADA) output=`maxdb_stop`
 
614
         ;;
 
615
    DB6) output=`db6udb_stop`
 
616
         ;;
 
617
  esac
 
618
 
 
619
  if [ $? -eq 0 ]
 
620
  then
 
621
    ocf_log info "SAP database $SID stopped: $output"
 
622
    rc=$OCF_SUCCESS
 
623
  else
 
624
    ocf_log err "SAP database $SID stop failed: $output"
 
625
    rc=$OCF_ERR_GENERIC
 
626
  fi
 
627
 
 
628
  case $DBTYPE in
 
629
    ORA) listener_stop
 
630
         ;;
 
631
    ADA) x_server_stop
 
632
         ;;
 
633
  esac
 
634
 
 
635
  sapuserexit POST_STOP_USEREXIT "$OCF_RESKEY_POST_STOP_USEREXIT"
 
636
 
 
637
  return $rc
 
638
}
 
639
 
 
640
 
 
641
#
 
642
# sapdatabase_monitor: Can the given database instance do anything useful?
 
643
#
 
644
sapdatabase_monitor() {
 
645
  strict=$1
 
646
 
 
647
  sapdatabase_status
 
648
  rc=$?
 
649
  if [ $rc -ne $OCF_SUCCESS ]; then
 
650
    return $rc
 
651
  fi
 
652
 
 
653
  case $DBTYPE in
 
654
    ADA) x_server_status 
 
655
         if [ $? -ne $OCF_SUCCESS ]; then x_server_start; fi
 
656
         ;;
 
657
    ORA) listener_status
 
658
         if [ $? -ne $OCF_SUCCESS ]; then listener_start; fi
 
659
         ;;
 
660
  esac
 
661
 
 
662
  if [ $strict -eq 0 ]
 
663
  then
 
664
    return $rc
 
665
  else
 
666
    if [ $DBJ2EE_ONLY -eq 0 ]
 
667
    then
 
668
      output=`echo "$SAPDBCONNECT -d -w /dev/null" | su $sidadm 2>&1`
 
669
      if [ $? -le 4 ]
 
670
      then
 
671
        rc=$OCF_SUCCESS
 
672
      else
 
673
        rc=$OCF_NOT_RUNNING
 
674
      fi
 
675
    else
 
676
      MYCP=""
 
677
      EXECMD=""
 
678
 
 
679
      # WebAS Java 6.40+7.00
 
680
      IAIK_JCE="$SECSTORE"/iaik_jce.jar
 
681
      IAIK_JCE_EXPORT="$SECSTORE"/iaik_jce_export.jar
 
682
      EXCEPTION="$BOOTSTRAP"/exception.jar
 
683
      LOGGING="$BOOTSTRAP"/logging.jar
 
684
      OPENSQLSTA="$BOOTSTRAP"/opensqlsta.jar
 
685
      TC_SEC_SECSTOREFS="$BOOTSTRAP"/tc_sec_secstorefs.jar
 
686
      JDDI="$BOOTSTRAP"/../server0/bin/ext/jdbdictionary/jddi.jar
 
687
      ANTLR="$BOOTSTRAP"/../server0/bin/ext/antlr/antlr.jar
 
688
      FRAME="$BOOTSTRAP"/../server0/bin/system/frame.jar
 
689
  
 
690
      # only start jdbcconnect when all jars available
 
691
      if [ -f "$EXCEPTION" -a -f "$LOGGING" -a -f "$OPENSQLSTA" -a -f "$TC_SEC_SECSTOREFS" -a -f "$JDDI" -a -f "$ANTLR" -a -f "$FRAME" -a -f "$SAPDBCONNECT" ]
 
692
      then
 
693
        MYCP=".:$FRAME:$ANTLR:$JDDI:$IAIK_JCE_EXPORT:$IAIK_JCE:$EXCEPTION:$LOGGING:$OPENSQLSTA:$TC_SEC_SECSTOREFS:$DB_JARS:$SAPDBCONNECT" 
 
694
        EXECMD="com.sap.inst.jdbc.connect.JdbcCon -sec $SID:$SID"
 
695
      else
 
696
      # WebAS Java 7.10
 
697
        LAUNCHER=${BOOTSTRAP}/sap.com~tc~bl~offline_launcher~impl.jar
 
698
 
 
699
        if [ -f "$DB_JARS" -a -f "$SAPDBCONNECT" -a -f "$LAUNCHER" ]
 
700
        then
 
701
          MYCP="$LAUNCHER"
 
702
          EXECMD="com.sap.engine.offline.OfflineToolStart com.sap.inst.jdbc.connect.JdbcCon ${SAPDBCONNECT}:${SECSTORE}:${DB_JARS}:${BOOTSTRAP} -sec $SID:$SID"
 
703
        fi
 
704
      fi
 
705
 
 
706
      if [ -n "$EXECMD" ]
 
707
      then
 
708
        output=`${JAVA_HOME}/bin/java -cp $MYCP $EXECMD 2> /dev/null`
 
709
        if [ $? -le 0 ]
 
710
        then
 
711
          rc=$OCF_SUCCESS
 
712
        else
 
713
          rc=$OCF_NOT_RUNNING
 
714
        fi
 
715
      else
 
716
        output="Cannot find all jar files needed for database monitoring."
 
717
        rc=$OCF_ERR_GENERIC
 
718
      fi
 
719
    fi
 
720
  fi
 
721
 
 
722
  if [ $rc -ne $OCF_SUCCESS ]
 
723
  then
 
724
    ocf_log err "The SAP database $SID ist not running: $output"
 
725
  fi
 
726
  return $rc
 
727
}
 
728
 
 
729
 
 
730
#
 
731
# sapdatabase_status: Are there any database processes on this host ?
 
732
#
 
733
sapdatabase_status() {
 
734
  case $DBTYPE in
 
735
    ADA) SEARCH="$SID/db/pgm/kernel"
 
736
         SUSER=`grep "^SdbOwner" /etc/opt/sdb | awk -F'=' '{print $2}'`
 
737
         SNUM=2
 
738
         ;;
 
739
    ORA) SEARCH="ora_[a-z][a-z][a-z][a-z]_"
 
740
         SUSER="ora`echo $SID | tr '[:upper:]' '[:lower:]'`"
 
741
         SNUM=4
 
742
         ;;
 
743
    DB6) SEARCH="db2[a-z][a-z][a-z]"
 
744
         SUSER="db2`echo $SID | tr '[:upper:]' '[:lower:]'`"
 
745
         SNUM=2
 
746
         ;;
 
747
  esac
 
748
 
 
749
  # Note: ps cuts off it's output at column $COLUMNS, so "ps -ef" can not be used here
 
750
  # as the output might be to long.
 
751
  cnt=`ps efo args --user $SUSER 2> /dev/null | grep -c "$SEARCH"`
 
752
  if [ $cnt -ge $SNUM ]
 
753
  then
 
754
    rc=$OCF_SUCCESS
 
755
  else
 
756
    # ocf_log info "Database Instance $SID is not running on `hostname`"
 
757
    rc=$OCF_NOT_RUNNING
 
758
  fi
 
759
  return $rc
 
760
}
 
761
 
 
762
 
 
763
#
 
764
# sapdatabase_recover:
 
765
#
 
766
sapdatabase_recover() {
 
767
 
 
768
  case $DBTYPE in
 
769
    ORA) recoutput=`oracle_recover`
 
770
         ;;
 
771
    ADA) recoutput=`maxdb_recover`
 
772
         ;;
 
773
    DB6) recoutput=`db6udb_recover`
 
774
         ;;
 
775
  esac
 
776
 
 
777
  sapdatabase_monitor 1
 
778
  retcode=$?
 
779
 
 
780
  if [ $retcode -eq $OCF_SUCCESS ]
 
781
  then
 
782
    ocf_log info "Recover of SAP database $SID was successful: $recoutput"
 
783
  else
 
784
    ocf_log err "Recover of SAP database $SID failed: $recoutput"
 
785
  fi
 
786
 
 
787
  return $retcode
 
788
}
 
789
 
 
790
 
 
791
#
 
792
# sapdatabase_validate: Check the symantic of the input parameters 
 
793
#
 
794
sapdatabase_validate() {
 
795
  rc=$OCF_SUCCESS
 
796
  if [ `echo "$SID" | grep -c '^[A-Z][A-Z0-9][A-Z0-9]$'` -ne 1 ]
 
797
  then
 
798
    ocf_log err "Parsing parameter SID: '$SID' is not a valid system ID!"
 
799
    rc=$OCF_ERR_ARGS
 
800
  fi
 
801
 
 
802
  case "$DBTYPE" in
 
803
   ORA|ADA|DB6) ;;
 
804
   *) ocf_log err "Parsing parameter DBTYPE: '$DBTYPE' is not a supported database type!"
 
805
      rc=$OCF_ERR_ARGS ;;
 
806
  esac
 
807
 
 
808
  return $rc
 
809
}
 
810
 
 
811
 
 
812
#
 
813
#       'main' starts here...
 
814
#
 
815
 
 
816
if
 
817
  ( [ $# -ne 1 ] )
 
818
then
 
819
  usage
 
820
  exit $OCF_ERR_ARGS
 
821
fi
 
822
 
 
823
# Set a tempfile and make sure to clean it up again
 
824
TEMPFILE="/tmp/SAPDatabase.$$.tmp"
 
825
trap trap_handler INT TERM
 
826
 
 
827
# These operations don't require OCF instance parameters to be set
 
828
case "$1" in
 
829
  meta-data)    meta_data
 
830
                exit $OCF_SUCCESS;;
 
831
 
 
832
  usage)        usage
 
833
                exit $OCF_SUCCESS;;
 
834
 
 
835
  methods)      sapdatabase_methods
 
836
                exit $?;;
 
837
 
 
838
  *);;
 
839
esac
 
840
 
 
841
US=`id -u -n`
 
842
US=`echo $US`
 
843
if
 
844
  [ $US != root  ]
 
845
then
 
846
  ocf_log err "$0 must be run as root"
 
847
  exit $OCF_ERR_PERM
 
848
fi
 
849
 
 
850
# mandatory parameter check
 
851
if  [ -z "$OCF_RESKEY_SID" ]; then
 
852
  ocf_log err "Please set OCF_RESKEY_SID to the SAP system id!"
 
853
  exit $OCF_ERR_ARGS
 
854
fi
 
855
SID=`echo "$OCF_RESKEY_SID"`
 
856
 
 
857
if [ -z "$OCF_RESKEY_DBTYPE" ]; then
 
858
  ocf_log err "Please set OCF_RESKEY_DBTYPE to the database vendor specific tag (ORA,ADA,DB6)!"
 
859
  exit $OCF_ERR_ARGS
 
860
fi
 
861
DBTYPE=`echo "$OCF_RESKEY_DBTYPE" | tr "[a-z]" "[A-Z]"`
 
862
 
 
863
# optional OCF parameters, we try to guess which directories are correct
 
864
EXESTARTDB="startdb"
 
865
EXESTOPDB="stopdb"
 
866
EXEDBCONNECT="R3trans"
 
867
if [ -z "$OCF_RESKEY_DBJ2EE_ONLY" ]; then
 
868
  DBJ2EE_ONLY=0
 
869
else
 
870
  case "$OCF_RESKEY_DBJ2EE_ONLY" in
 
871
   1|true|TRUE|yes|YES) DBJ2EE_ONLY=1
 
872
                        EXESTARTDB="startj2eedb"
 
873
                        EXESTOPDB="stopj2eedb"
 
874
                        EXEDBCONNECT="jdbcconnect.jar"
 
875
                        ;;
 
876
   0|false|FALSE|no|NO) DBJ2EE_ONLY=0;;
 
877
   *) ocf_log err "Parsing parameter DBJ2EE_ONLY: '$DBJ2EE_ONLY' is not a boolean value!"
 
878
      exit $OCF_ERR_ARGS ;;
 
879
  esac
 
880
fi
 
881
 
 
882
if [ -z "$OCF_RESKEY_NETSERVICENAME" ]; then
 
883
  case "$DBTYPE" in
 
884
    ORA|ora) NETSERVICENAME="LISTENER";;
 
885
    *)       NETSERVICENAME="";;
 
886
  esac
 
887
else
 
888
  NETSERVICENAME="$OCF_RESKEY_NETSERVICENAME"
 
889
fi
 
890
 
 
891
if [ -z "$OCF_RESKEY_STRICT_MONITORING" ]; then
 
892
  OCF_RESKEY_STRICT_MONITORING=0
 
893
else
 
894
  case "$OCF_RESKEY_STRICT_MONITORING" in
 
895
   1|true|TRUE|yes|YES) OCF_RESKEY_STRICT_MONITORING=1;;
 
896
   0|false|FALSE|no|NO) OCF_RESKEY_STRICT_MONITORING=0;;
 
897
   *)  ocf_log err "Parsing parameter STRICT_MONITORING: '$OCF_RESKEY_STRICT_MONITORING' is not a boolean value!"
 
898
       exit $OCF_ERR_ARGS ;;
 
899
  esac
 
900
fi
 
901
 
 
902
PATHLIST="
 
903
$OCF_RESKEY_DIR_EXECUTABLE
 
904
/usr/sap/$SID/*/exe
 
905
/usr/sap/$SID/SYS/exe/run
 
906
/sapmnt/$SID/exe
 
907
"
 
908
DIR_EXECUTABLE=""
 
909
for EXEPATH in $PATHLIST
 
910
do
 
911
  if [ -x $EXEPATH/$EXESTARTDB -a -x $EXEPATH/$EXESTOPDB -a -x $EXEPATH/$EXEDBCONNECT ]
 
912
  then
 
913
    DIR_EXECUTABLE=$EXEPATH
 
914
    SAPSTARTDB=$EXEPATH/$EXESTARTDB
 
915
    SAPSTOPDB=$EXEPATH/$EXESTOPDB
 
916
    SAPDBCONNECT=$EXEPATH/$EXEDBCONNECT
 
917
    break
 
918
  fi
 
919
done
 
920
if [ -z "$DIR_EXECUTABLE" ]
 
921
then
 
922
  ocf_log warn "Cannot find $EXESTARTDB,$EXESTOPDB and $EXEDBCONNECT executable, please set DIR_EXECUTABLE parameter!"
 
923
  exit $OCF_NOT_RUNNING
 
924
fi
 
925
 
 
926
if [ $DBJ2EE_ONLY -eq 1 ]
 
927
then
 
928
  if [ -n "$OCF_RESKEY_DIR_BOOTSTRAP" ]
 
929
  then
 
930
    BOOTSTRAP="$OCF_RESKEY_DIR_BOOTSTRAP"
 
931
  else
 
932
    BOOTSTRAP=`ls -1d /usr/sap/$SID/*/j2ee/cluster/bootstrap | head -1`
 
933
  fi
 
934
 
 
935
  if [ -n "$OCF_RESKEY_DIR_SECSTORE" ]
 
936
  then
 
937
    SECSTORE="$OCF_RESKEY_DIR_SECSTORE"
 
938
  else
 
939
    SECSTORE=/usr/sap/$SID/SYS/global/security/lib/tools
 
940
  fi
 
941
 
 
942
  if [ -n "$OCF_RESKEY_JAVA_HOME" ]
 
943
  then
 
944
    JAVA_HOME="$OCF_RESKEY_JAVA_HOME"
 
945
    PATH=$JAVA_HOME/bin:$PATH
 
946
  else
 
947
    if [ -n "$JAVA_HOME" ]
 
948
    then
 
949
      PATH=$JAVA_HOME/bin:$PATH
 
950
    else
 
951
      ocf_log err "Cannot find JAVA_HOME directory, please set JAVA_HOME parameter!"
 
952
      exit $OCF_NOT_RUNNING
 
953
    fi
 
954
  fi
 
955
 
 
956
  if [ -n "$OCF_RESKEY_DB_JARS" ]
 
957
  then
 
958
    DB_JARS=$OCF_RESKEY_DB_JARS
 
959
  else
 
960
    if [ -f "$BOOTSTRAP"/bootstrap.properties ]; then
 
961
      DB_JARS=`cat $BOOTSTRAP/bootstrap.properties | grep -i rdbms.driverLocation | sed -e 's/\\\:/:/g' | awk -F= '{print $2}'`
 
962
    fi
 
963
  fi
 
964
fi
 
965
 
 
966
if [ -z "$OCF_RESKEY_AUTOMATIC_RECOVER" ]
 
967
then
 
968
  OCF_RESKEY_AUTOMATIC_RECOVER=0
 
969
else
 
970
  case "$OCF_RESKEY_AUTOMATIC_RECOVER" in
 
971
   1|true|TRUE|yes|YES) OCF_RESKEY_AUTOMATIC_RECOVER=1;;
 
972
   0|false|FALSE|no|NO) OCF_RESKEY_AUTOMATIC_RECOVER=0;;
 
973
  esac
 
974
fi
 
975
 
 
976
# as root user we need the library path to the SAP kernel to be able to call executables
 
977
if [ `echo $LD_LIBRARY_PATH | grep -c "^$DIR_EXECUTABLE\>"` -eq 0 ]; then
 
978
  LD_LIBRARY_PATH=$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH
 
979
  export LD_LIBRARY_PATH
 
980
fi
 
981
sidadm="`echo $SID | tr '[:upper:]' '[:lower:]'`adm"
 
982
 
 
983
# What kind of method was invoked?
 
984
case "$1" in
 
985
 
 
986
  start)        sapdatabase_start
 
987
                exit $?;;
 
988
 
 
989
  stop)         sapdatabase_stop
 
990
                exit $?;;
 
991
 
 
992
  monitor)
 
993
                sapdatabase_monitor $OCF_RESKEY_STRICT_MONITORING
 
994
                exit $?;;
 
995
 
 
996
  status)
 
997
                sapdatabase_status
 
998
                exit $?;;
 
999
 
 
1000
  recover)      sapdatabase_recover
 
1001
                exit $?;;
 
1002
 
 
1003
  validate-all) sapdatabase_validate
 
1004
                exit $?;;
 
1005
 
 
1006
  *)            sapdatabase_methods
 
1007
                exit $OCF_ERR_UNIMPLEMENTED;;
 
1008
esac