Debian Codegraph @

heartbeat/SAPDatabase

raw symbols SCIP
1 #!/bin/shscip-shell filesystem . . `/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: [email protected]
10 # License: GNU General Public License (GPL)
11 # Copyright: (c) 2006, 2007, 2010, 2012 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 (mandatory, one of the following values: ORA,ADA,DB6,SYB,HDB)
20 # OCF_RESKEY_DBINSTANCE (optional, Database instance name, if not equal to SID)
21 # OCF_RESKEY_DBOSUSER (optional, the Linux user that owns the database processes on operating system level)
22 # OCF_RESKEY_STRICT_MONITORING (optional, activate application level monitoring - with Oracle a failover will occur in case of an archiver stuck)
23 # OCF_RESKEY_AUTOMATIC_RECOVER (optional, automatic startup recovery, default is false)
24 # OCF_RESKEY_MONITOR_SERVICES (optional, default is to monitor all database services)
25 # OCF_RESKEY_PRE_START_USEREXIT (optional, lists a script which can be executed before the resource is started)
26 # OCF_RESKEY_POST_START_USEREXIT (optional, lists a script which can be executed after the resource is started)
27 # OCF_RESKEY_PRE_STOP_USEREXIT (optional, lists a script which can be executed before the resource is stopped)
28 # OCF_RESKEY_POST_STOP_USEREXIT (optional, lists a script which can be executed after the resource is stopped)
29 # Deprecated parameters:
30 # OCF_RESKEY_NETSERVICENAME
31 # OCF_RESKEY_DBJ2EE_ONLY
32 # OCF_RESKEY_JAVA_HOME
33 # OCF_RESKEY_DIR_BOOTSTRAP
34 # OCF_RESKEY_DIR_SECSTORE
35 # OCF_RESKEY_DB_JARS
36 #
37 #######################################################################
38 # Initialization:
39
40 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
41 . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
42
43 # Parameter defaults
44
45 OCF_RESKEY_SID_default=""
46 OCF_RESKEY_DIR_EXECUTABLE_default="/usr/sap/hostctrl/exescip-shell filesystem . . `/usr/sap/hostctrl/exe`."
47 OCF_RESKEY_DBTYPE_default=""
48 OCF_RESKEY_DBINSTANCE_default=""
49 OCF_RESKEY_DBOSUSER_default=""
50 OCF_RESKEY_NETSERVICENAME_default=""
51 OCF_RESKEY_DBJ2EE_ONLY_default=""
52 OCF_RESKEY_JAVA_HOME_default=""
53 OCF_RESKEY_STRICT_MONITORING_default="false"
54 OCF_RESKEY_AUTOMATIC_RECOVER_default="false"
55 OCF_RESKEY_MONITOR_SERVICES_default=""
56 OCF_RESKEY_DIR_BOOTSTRAP_default=""
57 OCF_RESKEY_DIR_SECSTORE_default=""
58 OCF_RESKEY_DB_JARS_default=""
59 OCF_RESKEY_PRE_START_USEREXIT_default=""
60 OCF_RESKEY_POST_START_USEREXIT_default=""
61 OCF_RESKEY_PRE_STOP_USEREXIT_default=""
62 OCF_RESKEY_POST_STOP_USEREXIT_default=""
63
64 : ${OCF_RESKEY_SID=${OCF_RESKEY_SID_default}}
65 : ${OCF_RESKEY_DIR_EXECUTABLE=${OCF_RESKEY_DIR_EXECUTABLE_default}}
66 : ${OCF_RESKEY_DBTYPE=${OCF_RESKEY_DBTYPE_default}}
67 : ${OCF_RESKEY_DBINSTANCE=${OCF_RESKEY_DBINSTANCE_default}}
68 : ${OCF_RESKEY_DBOSUSER=${OCF_RESKEY_DBOSUSER_default}}
69 : ${OCF_RESKEY_NETSERVICENAME=${OCF_RESKEY_NETSERVICENAME_default}}
70 : ${OCF_RESKEY_DBJ2EE_ONLY=${OCF_RESKEY_DBJ2EE_ONLY_default}}
71 : ${OCF_RESKEY_JAVA_HOME=${OCF_RESKEY_JAVA_HOME_default}}
72 : ${OCF_RESKEY_STRICT_MONITORING=${OCF_RESKEY_STRICT_MONITORING_default}}
73 : ${OCF_RESKEY_AUTOMATIC_RECOVER=${OCF_RESKEY_AUTOMATIC_RECOVER_default}}
74 : ${OCF_RESKEY_MONITOR_SERVICES=${OCF_RESKEY_MONITOR_SERVICES_default}}
75 : ${OCF_RESKEY_DIR_BOOTSTRAP=${OCF_RESKEY_DIR_BOOTSTRAP_default}}
76 : ${OCF_RESKEY_DIR_SECSTORE=${OCF_RESKEY_DIR_SECSTORE_default}}
77 : ${OCF_RESKEY_DB_JARS=${OCF_RESKEY_DB_JARS_default}}
78 : ${OCF_RESKEY_PRE_START_USEREXIT=${OCF_RESKEY_PRE_START_USEREXIT_default}}
79 : ${OCF_RESKEY_POST_START_USEREXIT=${OCF_RESKEY_POST_START_USEREXIT_default}}
80 : ${OCF_RESKEY_PRE_STOP_USEREXIT=${OCF_RESKEY_PRE_STOP_USEREXIT_default}}
81 : ${OCF_RESKEY_POST_STOP_USEREXIT=${OCF_RESKEY_POST_STOP_USEREXIT_default}}
82
83 #######################################################################
84
85 SH=/bin/shscip-shell filesystem . . `/bin/sh`.
86
87 usagescip-shell shell shell-project 0.0.0 usage().() {
88 methods=`sapdatabase_methods`
89 methods=`echoscip-shell system . . echo. $methods | trscip-shell system . . tr. ' ' '|'`
90 catscip-shell system . . cat. <<-EOF
91 usage: $0 ($methods)
92
93 $0 manages a SAP database of any type as an HA resource.
94 Currently Oracle, MaxDB, DB/2 UDB, Sybase ASE and SAP HANA Database are supported.
95 ABAP databases as well as JAVA only databases are supported.
96
97 The 'start' operation starts the instance.
98 The 'stop' operation stops the instance.
99 The 'status' operation reports whether the instance is running
100 The 'monitor' operation reports whether the instance seems to be working
101 The 'recover' operation tries to recover the instance after a crash (instance will be stopped first!)
102 The 'validate-all' operation reports whether the parameters are valid
103 The 'methods' operation reports on the methods $0 supports
104
105 EOF
106 }
107
108 meta_datascip-shell shell shell-project 0.0.0 meta_data().() {
109 catscip-shell system . . cat. <<END
110 <?xml version="1.0"?>
111 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
112 <resource-agent name="SAPDatabase" version="2.14">
113 <version>1.0</version>
114
115 <longdesc lang="en">
116 Resource script for SAP databases. It manages a SAP database of any type as an HA resource.
117
118 The purpose of the resource agent is to start, stop and monitor the database instance of a SAP system. Together with the RDBMS system it will also control the related network service for the database. Like the Oracle Listener and the xserver of MaxDB.
119 The resource agent expects a standard SAP installation of the database and therefore needs less parameters to configure.
120 The resource agent supports the following databases:
121 - Oracle 10.2, 11.2 and 12
122 - DB/2 UDB for Windows and Unix 9.x
123 - SAP-DB / MaxDB 7.x
124 - Sybase ASE 15.7
125 - SAP HANA Database since 1.00 - with SAP note 1625203 (http://sdn.sap.com)
126
127 In fact this resource agent does not run any database commands directly. It uses the SAP standard process SAPHostAgent to control the database.
128 The SAPHostAgent must be installed on each cluster node locally. It will not work, if you try to run the SAPHostAgent also as a HA resource.
129 Please follow SAP note 1031096 for the installation of SAPHostAgent.
130 The required minimum version of SAPHostAgent is:
131 Release: 7.20
132 Patch Number: 90
133 or compile time after: Dec 17 2011
134
135 To exemplify the usage, for a HANA database with SID "TST" and instance number "10", the resource configuration using crmsh syntax looks like:
136
137 primitive rsc_SAPDatabase_TST_HDB10 ocf:heartbeat:SAPDatabase \\
138 params DBTYPE="HDB" SID="TST" \\
139 op start interval="0" timeout="3600" \\
140 op monitor interval="120" timeout="700" \\
141 op stop interval="0" timeout="600"
142
143 Make sure to tune the operations timeout values accordingly with your chosen Database and available infrastructure.
144
145 Note that the same configuration can be achieved using any other CLI tool for cluster configuration available, like pcs or cibadmin.
146 </longdesc>
147 <shortdesc lang="en">Manages a SAP database instance as an HA resource.</shortdesc>
148 <parameters>
149 <parameter name="SID" unique="1" required="1">
150 <longdesc lang="en">The unique database system identifier. e.g. P01</longdesc>
151 <shortdesc lang="en">Database system ID</shortdesc>
152 <content type="string" default="${OCF_RESKEY_SID_default}" />
153 </parameter>
154 <parameter name="DIR_EXECUTABLE" unique="0" required="0">
155 <longdesc lang="en">The full qualified path where to find saphostexec and saphostctrl.
156 Usually you can leave this empty. Then the default: ${OCF_RESKEY_DIR_EXECUTABLE_default} is used.
157 </longdesc>
158 <shortdesc lang="en">path of saphostexec and saphostctrl</shortdesc>
159 <content type="string" default="${OCF_RESKEY_DIR_EXECUTABLE_default}" />
160 </parameter>
161 <parameter name="DBTYPE" unique="0" required="1">
162 <longdesc lang="en">The name of the database vendor you use. Set either: ADA, DB6, ORA, SYB, HDB</longdesc>
163 <shortdesc lang="en">database vendor</shortdesc>
164 <content type="string" default="${OCF_RESKEY_DBTYPE_default}" />
165 </parameter>
166 <parameter name="DBINSTANCE" unique="1" required="0">
167 <longdesc lang="en">Must be used for special database implementations, when database instance name is not equal to the SID (e.g. Oracle DataGuard)</longdesc>
168 <shortdesc lang="en">Database instance name, if not equal to SID</shortdesc>
169 <content type="string" default="${OCF_RESKEY_DBINSTANCE_default}" />
170 </parameter>
171 <parameter name="DBOSUSER" unique="1" required="0">
172 <longdesc lang="en">The parameter can be set, if the database processes on operating system level are not executed with the default user of the used database type. Defaults: ADA=taken from /etc/opt/sdb, DB6=db2SID, ORA=oraSID and oracle, SYB=sybSID, HDB=SIDadm</longdesc>
173 <shortdesc lang="en">the Linux user that owns the database processes on operating system level</shortdesc>
174 <content type="string" default="${OCF_RESKEY_DBOSUSER_default}" />
175 </parameter>
176 <parameter name="NETSERVICENAME" unique="0" required="0">
177 <longdesc lang="en">Deprecated - do not use anymore. This parameter will be deleted in one of the next releases.</longdesc>
178 <shortdesc lang="en">deprecated - do not use anymore</shortdesc>
179 <content type="string" default="${OCF_RESKEY_NETSERVICENAME_default}" />
180 </parameter>
181 <parameter name="DBJ2EE_ONLY" unique="0" required="0">
182 <longdesc lang="en">Deprecated - do not use anymore. This parameter will be deleted in one of the next releases.</longdesc>
183 <shortdesc lang="en">deprecated - do not use anymore</shortdesc>
184 <content type="boolean" default="${OCF_RESKEY_DBJ2EE_ONLY_default}"/>
185 </parameter>
186 <parameter name="JAVA_HOME" unique="0" required="0">
187 <longdesc lang="en">Deprecated - do not use anymore. This parameter will be deleted in one of the next releases.</longdesc>
188 <shortdesc lang="en">deprecated - do not use anymore</shortdesc>
189 <content type="string" default="${OCF_RESKEY_JAVA_HOME_default}"/>
190 </parameter>
191 <parameter name="STRICT_MONITORING" unique="0" required="0">
192 <longdesc lang="en">This controls how the resource agent monitors the database. If set to true, it will use 'saphostctrl -function GetDatabaseStatus' to test the database state. If set to false, only operating system processes are monitored.</longdesc>
193 <shortdesc lang="en">Activates application level monitoring</shortdesc>
194 <content type="boolean" default="${OCF_RESKEY_STRICT_MONITORING_default}"/>
195 </parameter>
196 <parameter name="AUTOMATIC_RECOVER" unique="0" required="0">
197 <longdesc lang="en">If you set this to true, 'saphostctrl -function StartDatabase' will always be called with the '-force' option.</longdesc>
198 <shortdesc lang="en">Enable or disable automatic startup recovery</shortdesc>
199 <content type="boolean" default="${OCF_RESKEY_AUTOMATIC_RECOVER_default}"/>
200 </parameter>
201 <parameter name="MONITOR_SERVICES" unique="0" required="0">
202 <longdesc lang="en">Defines which services are monitored by the SAPDatabase resource agent. Service names must correspond with the output of the 'saphostctrl -function GetDatabaseStatus' command.
203 The default MONITOR_SERVICES value is derived from the database type DBTYPE. For reference:
204
205 - DBTYPE "ORA" sets MONITOR_SERVICES="Instance|Database|Listener";
206 - DBTYPE "HDB" sets MONITOR_SERVICES="hdbindexserver|hdbnameserver";
207 - DBTYPE "ADA" sets MONITOR_SERVICES="Database";
208 - DBTYPE "DB6" sets MONITOR_SERVICES="{SID}|{db2sid}";
209 - DBTYPE "SYB" sets MONITOR_SERVICES="Server".
210
211 This parameter should be set ONLY if is needed to monitor different services than the ones listed above.
212 </longdesc>
213 <shortdesc lang="en">Database services to monitor</shortdesc>
214 <content type="string" default="${OCF_RESKEY_MONITOR_SERVICES_default}"/>
215 </parameter>
216 <parameter name="DIR_BOOTSTRAP" unique="0" required="0">
217 <longdesc lang="en">Deprecated - do not use anymore. This parameter will be deleted in one of the next releases.</longdesc>
218 <shortdesc lang="en">deprecated - do not use anymore</shortdesc>
219 <content type="string" default="${OCF_RESKEY_DIR_BOOTSTRAP_default}" />
220 </parameter>
221 <parameter name="DIR_SECSTORE" unique="0" required="0">
222 <longdesc lang="en">Deprecated - do not use anymore. This parameter will be deleted in one of the next releases.</longdesc>
223 <shortdesc lang="en">deprecated - do not use anymore</shortdesc>
224 <content type="string" default="${OCF_RESKEY_DIR_SECSTORE_default}" />
225 </parameter>
226 <parameter name="DB_JARS" unique="0" required="0">
227 <longdesc lang="en">Deprecated - do not use anymore. This parameter will be deleted in one of the next releases.</longdesc>
228 <shortdesc lang="en">deprecated - do not use anymore</shortdesc>
229 <content type="string" default="${OCF_RESKEY_DB_JARS_default}" />
230 </parameter>
231 <parameter name="PRE_START_USEREXIT" unique="0" required="0">
232 <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets started.</longdesc>
233 <shortdesc lang="en">path to a pre-start script</shortdesc>
234 <content type="string" default="${OCF_RESKEY_PRE_START_USEREXIT_default}" />
235 </parameter>
236 <parameter name="POST_START_USEREXIT" unique="0" required="0">
237 <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got started.</longdesc>
238 <shortdesc lang="en">path to a post-start script</shortdesc>
239 <content type="string" default="${OCF_RESKEY_POST_START_USEREXIT_default}" />
240 </parameter>
241 <parameter name="PRE_STOP_USEREXIT" unique="0" required="0">
242 <longdesc lang="en">The full qualified path where to find a script or program which should be executed before this resource gets stopped.</longdesc>
243 <shortdesc lang="en">path to a pre-start script</shortdesc>
244 <content type="string" default="${OCF_RESKEY_PRE_STOP_USEREXIT_default}" />
245 </parameter>
246 <parameter name="POST_STOP_USEREXIT" unique="0" required="0">
247 <longdesc lang="en">The full qualified path where to find a script or program which should be executed after this resource got stopped.</longdesc>
248 <shortdesc lang="en">path to a post-start script</shortdesc>
249 <content type="string" default="${OCF_RESKEY_POST_STOP_USEREXIT_default}" />
250 </parameter>
251 </parameters>
252
253 <actions>
254 <action name="start" timeout="1800s" />
255 <action name="stop" timeout="1800s" />
256 <action name="status" timeout="60s" />
257 <action name="monitor" depth="0" timeout="60s" interval="120s" />
258 <action name="validate-all" timeout="5s" />
259 <action name="meta-data" timeout="5s" />
260 <action name="methods" timeout="5s" />
261 </actions>
262 </resource-agent>
263 END
264 }
265
266
267 #
268 # methods: What methods/operations do we support?
269 #
270 sapdatabase_methodsscip-shell shell shell-project 0.0.0 sapdatabase_methods().() {
271 catscip-shell system . . cat. <<-EOF
272 start
273 stop
274 status
275 monitor
276 recover
277 validate-all
278 methods
279 meta-data
280 usage
281 EOF
282 }
283
284
285 #
286 # sapuserexit : Many SAP customers need some additional processes/tools to run their SAP systems.
287 # This specialties do not allow a totally generic SAP cluster resource agent.
288 # Someone should write a resource agent for each additional process you need, if it
289 # is required to monitor that process within the cluster manager. To enable
290 # you to extent this resource agent without developing a new one, this user exit
291 # was introduced.
292 #
293 sapuserexitscip-shell shell shell-project 0.0.0 sapuserexit().() {
294 NAME="$1"
295 VALUE="$2"
296
297 if [scip-shell system . . `[`. -n "$VALUE" ]
298 then
299 if have_binary "$VALUE"
300 then
301 ocf_log info "Calling userexit ${NAME} with customer script file ${VALUE}"
302 "$VALUE" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1
303 ocf_log info "Exiting userexit ${NAME} with customer script file ${VALUE}, returncode: $?"
304 else
305 ocf_log warn "Attribute ${NAME} is set to ${VALUE}, but this file is not executable"
306 fi
307 fi
308 return $OCF_SUCCESS
309 }
310
311
312 #
313 # saphostctrl_installed
314 #
315 saphostctrl_installedscip-shell shell shell-project 0.0.0 saphostctrl_installed().() {
316 SAPHOSTCTRL="${OCF_RESKEY_DIR_EXECUTABLE}/saphostctrl"
317 SAPHOSTEXEC="${OCF_RESKEY_DIR_EXECUTABLE}/saphostexec"
318 SAPHOSTSRV="${OCF_RESKEY_DIR_EXECUTABLE}/sapstartsrv"
319 SAPHOSTOSCOL="${OCF_RESKEY_DIR_EXECUTABLE}/saposcol"
320
321 have_binary $SAPHOSTCTRL && have_binary $SAPHOSTEXEC
322 }
323
324
325 #
326 # 'main' starts here...
327 #
328
329 if
330 ( [scip-shell system . . `[`. $# -ne 1 ] )
331 then
332 usagescip-shell shell shell-project 0.0.0 usage().
333 exit $OCF_ERR_ARGS
334 fi
335
336 # These operations don't require OCF instance parameters to be set
337 case "$1" in
338 meta-data) meta_datascip-shell shell shell-project 0.0.0 meta_data().
339 exit $OCF_SUCCESS;;
340
341 usage) usagescip-shell shell shell-project 0.0.0 usage().
342 exit $OCF_SUCCESS;;
343
344 methods) sapdatabase_methodsscip-shell shell shell-project 0.0.0 sapdatabase_methods().
345 exit $?;;
346
347 *);;
348 esac
349
350 if ! ocf_is_root
351 then
352 ocf_log err "$0 must be run as root"
353 exit $OCF_ERR_PERM
354 fi
355
356 # mandatory parameter check
357 if [scip-shell system . . `[`. -z "$OCF_RESKEY_SID" ]; then
358 ocf_log err "Please set OCF_RESKEY_SID to the SAP system id!"
359 exit $OCF_ERR_ARGS
360 fi
361 SID=`echoscip-shell system . . echo. "$OCF_RESKEY_SID"`
362
363 if [scip-shell system . . `[`. -z "$OCF_RESKEY_DBTYPE" ]; then
364 ocf_log err "Please set OCF_RESKEY_DBTYPE to the database vendor specific tag (ADA,DB6,ORA,SYB,HDB)!"
365 exit $OCF_ERR_ARGS
366 fi
367 DBTYPE=`echoscip-shell system . . echo. "$OCF_RESKEY_DBTYPE" | trscip-shell system . . tr. '[:lower:]' '[:upper:]'`
368
369
370 # source functions and initialize global variables
371 if saphostctrl_installedscip-shell shell shell-project 0.0.0 saphostctrl_installed().; then
372 . ${OCF_FUNCTIONS_DIR}/sapdb.sh
373 else
374 if [scip-shell system . . `[`. -n "${OCF_RESKEY_DBOSUSER}" ]; then
375 ocf_exit_reason "Usage of parameter OCF_RESKEY_DBOSUSER is not possible without having SAP Host-Agent installed"
376 exit $OCF_ERR_ARGS
377 fi
378 . ${OCF_FUNCTIONS_DIR}/sapdb-nosha.sh
379 fi
380 sapdatabase_init
381
382
383 # we always want to fall to the faster status method in case of a probe by the cluster
384 ACTION=$1
385 if ocf_is_probe
386 then
387 ACTION=status
388 fi
389
390 # What kind of method was invoked?
391 case "$ACTION" in
392
393 start|stop|status|recover) sapdatabase_$ACTION
394 exit $?;;
395 monitor) sapdatabase_monitor $OCF_RESKEY_STRICT_MONITORING
396 exit $?;;
397 validate-all) sapdatabase_validate
398 exit $?;;
399 *) sapdatabase_methodsscip-shell shell shell-project 0.0.0 sapdatabase_methods().
400 exit $OCF_ERR_UNIMPLEMENTED;;
401 esac