Blame SOURCES/bz1059988-db2-support.patch

261ad6
From c954c6470fe61c73396b45ca75310d146997f81b Mon Sep 17 00:00:00 2001
261ad6
From: David Vossel <dvossel@redhat.com>
261ad6
Date: Wed, 29 Apr 2015 11:16:18 -0500
261ad6
Subject: [PATCH 5/6] db2 support
261ad6
261ad6
---
261ad6
 heartbeat/db2 | 60 +++++++++++++++++++++++++++++++++++++++++++++--------------
261ad6
 1 file changed, 46 insertions(+), 14 deletions(-)
261ad6
261ad6
diff --git a/heartbeat/db2 b/heartbeat/db2
261ad6
index f9db2f8..fed2d86 100755
261ad6
--- a/heartbeat/db2
261ad6
+++ b/heartbeat/db2
261ad6
@@ -132,6 +132,9 @@ END
261ad6
 db2_validate() {
261ad6
     local db2home db2sql db2instance
261ad6
 
261ad6
+    # db2 uses korn shell
261ad6
+    check_binary "ksh"
261ad6
+
261ad6
     # check required instance vars
261ad6
     if [ -z "$OCF_RESKEY_instance" ]
261ad6
     then
261ad6
@@ -208,6 +211,14 @@ db2_validate() {
261ad6
     return $OCF_SUCCESS
261ad6
 }
261ad6
 
261ad6
+master_score()
261ad6
+{
261ad6
+    if ! have_binary "crm_master"; then
261ad6
+        return
261ad6
+    fi
261ad6
+
261ad6
+    crm_master $*
261ad6
+}
261ad6
 
261ad6
 #
261ad6
 # Run the given command as db2 instance user
261ad6
@@ -380,8 +391,17 @@ db2_check_config_compatibility() {
261ad6
 #
261ad6
 db2_start() {
261ad6
     local output start_cmd db
261ad6
+    local start_opts="dbpartitionnum $db2node"
261ad6
+
261ad6
+    # If we detect that db partitions are not in use, and no
261ad6
+    # partition is explicitly specified, activate without
261ad6
+    # partition information. This allows db2 instances without
261ad6
+    # partition support to be managed. 
261ad6
+    if [ -z "$OCF_RESKEY_dbpartitionnum" ] && ! [ -a "$db2sql/db2nodes.cfg" ]; then
261ad6
+        start_opts=""
261ad6
+    fi
261ad6
 
261ad6
-    if output=$(runasdb2 db2start dbpartitionnum $db2node)
261ad6
+    if output=$(runasdb2 db2start $start_opts)
261ad6
     then
261ad6
         ocf_log info "DB2 instance $instance($db2node) started: $output"
261ad6
     else
261ad6
@@ -473,10 +493,15 @@ db2_start() {
261ad6
 #
261ad6
 db2_stop_bg() {
261ad6
     local rc output
261ad6
+    local stop_opts="dbpartitionnum $db2node"
261ad6
 
261ad6
     rc=$OCF_SUCCESS
261ad6
 
261ad6
-    if output=$(runasdb2 db2stop force dbpartitionnum $db2node)
261ad6
+    if [ -z "$OCF_RESKEY_dbpartitionnum" ] && ! [ -a "$db2sql/db2nodes.cfg" ]; then
261ad6
+        stop_opts=""
261ad6
+    fi
261ad6
+
261ad6
+    if output=$(runasdb2 db2stop force $stop_opts)
261ad6
     then
261ad6
         ocf_log info "DB2 instance $instance($db2node) stopped: $output"
261ad6
     else
261ad6
@@ -502,13 +527,13 @@ db2_stop() {
261ad6
     local stop_timeout grace_timeout stop_bg_pid i must_kill
261ad6
 
261ad6
     # remove master score
261ad6
-    crm_master -D -l reboot
261ad6
+    master_score -D -l reboot
261ad6
 
261ad6
     # be very early here in order to avoid stale data
261ad6
     rm -f $STATE_FILE
261ad6
 
261ad6
-    if ! db2_instance_status
261ad6
-    then
261ad6
+    db2_instance_status
261ad6
+    if [ $? -eq $OCF_NOT_RUNNING ]; then
261ad6
         ocf_log info "DB2 instance $instance already stopped"
261ad6
         return $OCF_SUCCESS
261ad6
     fi
261ad6
@@ -585,7 +610,12 @@ db2_instance_status() {
261ad6
     local pscount
261ad6
 
261ad6
     pscount=$(runasdb2 $db2bin/db2nps $db2node | cut -c9- |  grep ' db2[^ ]' | wc -l)
261ad6
-    test $pscount -ge 4
261ad6
+    if [ $pscount -ge 4 ]; then
261ad6
+        return $OCF_SUCCESS;
261ad6
+    elif [ $pscount -ge 1 ]; then
261ad6
+        return $OCF_GENERIC_ERR
261ad6
+    fi
261ad6
+    return $OCF_NOT_RUNNING
261ad6
 }
261ad6
 
261ad6
 #
261ad6
@@ -626,12 +656,14 @@ db2_hadr_status() {
261ad6
 #
261ad6
 db2_monitor() {
261ad6
     local CMD output hadr db
261ad6
+    local rc
261ad6
 
261ad6
-    if ! db2_instance_status
261ad6
-    then
261ad6
+    db2_instance_status
261ad6
+    rc=$?
261ad6
+    if [ $rc -ne $OCF_SUCCESS ]; then
261ad6
         # instance is dead remove master score
261ad6
-        crm_master -D -l reboot
261ad6
-        exit $OCF_NOT_RUNNING
261ad6
+        master_score -D -l reboot
261ad6
+        exit $rc
261ad6
     fi
261ad6
 
261ad6
     [ $db2node = 0 ] || return 0
261ad6
@@ -667,22 +699,22 @@ db2_monitor() {
261ad6
                     ocf_log err "DB2 message: $output"
261ad6
 
261ad6
                     # dead primary, remove master score
261ad6
-                    crm_master -D -l reboot
261ad6
+                    master_score -D -l reboot
261ad6
                     return $OCF_ERR_GENERIC
261ad6
                 esac
261ad6
             fi
261ad6
 
261ad6
             ocf_log debug "DB2 database $instance($db2node)/$db appears to be working"
261ad6
-            ocf_is_ms && crm_master -v 10000 -l reboot
261ad6
+            ocf_is_ms && master_score -v 10000 -l reboot
261ad6
             ;;
261ad6
 
261ad6
             Standby/*Peer)
261ad6
-            crm_master -v 8000 -l reboot
261ad6
+            master_score -v 8000 -l reboot
261ad6
             ;;
261ad6
 
261ad6
             Standby/*)
261ad6
             ocf_log warn "DB2 database $instance($db2node)/$db in status $hadr can never be promoted"
261ad6
-            crm_master -D -l reboot
261ad6
+            master_score -D -l reboot
261ad6
             ;;
261ad6
 
261ad6
             *)
261ad6
-- 
261ad6
1.8.4.2
261ad6