Blame SOURCES/bz2026278-1-SAPHanaController-SAPHanaTopology-add-systemd-support.patch

1ed92e
From 1450ab47f5645c46e5a1f2fe9096c7db30961ab3 Mon Sep 17 00:00:00 2001
1ed92e
From: AngelaBriel <abriel@suse.com>
1ed92e
Date: Wed, 24 Nov 2021 14:51:30 +0100
1ed92e
Subject: [PATCH] add support for the new systemd unit file handling for
1ed92e
 sapstartsrv and saphostagent (bsc#1189532, bsc#1189533)
1ed92e
1ed92e
---
1ed92e
 heartbeat/SAPHanaController       | 153 ++++++++++++++++++-----------
1ed92e
 heartbeat/SAPHanaTopology         |  72 ++++++++++++--
1ed92e
 4 files changed, 172 insertions(+), 67 deletions(-)
1ed92e
1ed92e
diff --git a/heartbeat/SAPHanaController b/heartbeat/SAPHanaController
1ed92e
index fa47ec5..a98293c 100755
1ed92e
--- a/heartbeat/SAPHanaController
1ed92e
+++ b/heartbeat/SAPHanaController
1ed92e
@@ -34,7 +34,7 @@
1ed92e
 #     systemReplicationStatus.py (>= SPS090)
1ed92e
 #
1ed92e
 #######################################################################
1ed92e
-SAPHanaControllerVersion="0.180.0.0628.1823"
1ed92e
+SAPHanaControllerVersion="0.181.0.1123.1923"
1ed92e
 # Resource Agent Generation
1ed92e
 RAG="2.0"
1ed92e
 
1ed92e
@@ -765,6 +765,7 @@ function saphana_init() {
1ed92e
     super_ocf_log info "FLOW $FUNCNAME ($*)"
1ed92e
     local rc=$OCF_SUCCESS
1ed92e
     local clN
1ed92e
+    SYSTEMCTL="/usr/bin/systemctl"
1ed92e
     # local site
1ed92e
     # two parameter models (for transition only)
1ed92e
     # OLD: InstanceName
1ed92e
@@ -1125,6 +1126,25 @@ function saphana_init() {
1ed92e
     return $OCF_SUCCESS
1ed92e
 }
1ed92e
 
1ed92e
+# chk4systemdsupport - check, if SAP systemd support is available
1ed92e
+# check for the existence of the SAP SID+Instance related unit file
1ed92e
+# rc=0 - sap instance unit file exists
1ed92e
+# rc=1 - sap instance unit file does NOT exist
1ed92e
+function chk4systemdsupport() {
1ed92e
+    super_ocf_log info "FLOW ${FUNCNAME[0]}"
1ed92e
+    local systemd_unit_name="SAP${SID}_${InstanceNr}.service"
1ed92e
+    local rc=1
1ed92e
+    if [ -x "$SYSTEMCTL" ]; then
1ed92e
+        if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then
1ed92e
+            rc=0
1ed92e
+        elif $SYSTEMCTL list-unit-files "$systemd_unit_name"; then
1ed92e
+            rc=0
1ed92e
+        else
1ed92e
+            rc=1
1ed92e
+        fi
1ed92e
+    fi
1ed92e
+    return $rc
1ed92e
+}
1ed92e
 
1ed92e
 #
1ed92e
 # function: check_sapstartsrv - check for sapstartsrv - optional start
1ed92e
@@ -1138,69 +1158,88 @@ function check_sapstartsrv() {
1ed92e
     local runninginst=""
1ed92e
     local rc=$OCF_SUCCESS
1ed92e
     local output=""
1ed92e
-    if [ ! -S /tmp/.sapstream5${InstanceNr}13 ]; then
1ed92e
-        super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName (no UDS), it will be started now"
1ed92e
-        restart=1
1ed92e
+    if chk4systemdsupport; then
1ed92e
+        # use systemd to control sapstartsrv
1ed92e
+        local systemd_unit_name="SAP${SID}_${InstanceNr}.service"
1ed92e
+
1ed92e
+        if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then
1ed92e
+            super_ocf_log info "ACT: systemd service $systemd_unit_name is active"
1ed92e
+        else
1ed92e
+            super_ocf_log warn "ACT: systemd service $systemd_unit_name is not active, it will be started using systemd"
1ed92e
+            # use start, because restart does also stop sap instance
1ed92e
+            $SYSTEMCTL start "$systemd_unit_name" >/dev/null 2>&1; src=$?
1ed92e
+            if [ $src -ne 0 ]; then
1ed92e
+                super_ocf_log error "ACT: error during start of systemd unit ${systemd_unit_name}!"
1ed92e
+                rc=$OCF_ERR_GENERIC
1ed92e
+                ocf_is_probe && rc=$OCF_NOT_RUNNING
1ed92e
+            fi
1ed92e
+        fi
1ed92e
     else
1ed92e
-        output=$($SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script)
1ed92e
-        if [ $? -eq 0 ]
1ed92e
-        then
1ed92e
-            runninginst=$(echo "$output" | grep '^0 : ' | cut -d' ' -f3)
1ed92e
-            if [ "$runninginst" != "$InstanceName" ]
1ed92e
+        # no SAP systemd unit available, continue with old code...
1ed92e
+        if [ ! -S /tmp/.sapstream5${InstanceNr}13 ]; then
1ed92e
+            super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName (no UDS), it will be started now"
1ed92e
+            restart=1
1ed92e
+        else
1ed92e
+            output=$($SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script)
1ed92e
+            if [ $? -eq 0 ]
1ed92e
             then
1ed92e
-                super_ocf_log warn "ACT: sapstartsrv is running for instance $runninginst, that service will be killed"
1ed92e
-                restart=1
1ed92e
-            else
1ed92e
-                output=$($SAPCONTROL -nr $InstanceNr -function AccessCheck Start)
1ed92e
-                if [ $? -ne 0 ]; then
1ed92e
-                    super_ocf_log warn "ACT: FAILED - sapcontrol -nr $InstanceNr -function AccessCheck Start ($(ls -ld1 /tmp/.sapstream5${InstanceNr}13))"
1ed92e
-                    super_ocf_log warn "ACT: sapstartsrv will be restarted to try to solve this situation, otherwise please check sapstsartsrv setup (SAP Note 927637)"
1ed92e
+                runninginst=$(echo "$output" | grep '^0 : ' | cut -d' ' -f3)
1ed92e
+                if [ "$runninginst" != "$InstanceName" ]
1ed92e
+                then
1ed92e
+                    super_ocf_log warn "ACT: sapstartsrv is running for instance $runninginst, that service will be killed"
1ed92e
                     restart=1
1ed92e
+                else
1ed92e
+                    output=$($SAPCONTROL -nr $InstanceNr -function AccessCheck Start)
1ed92e
+                    if [ $? -ne 0 ]; then
1ed92e
+                        super_ocf_log warn "ACT: FAILED - sapcontrol -nr $InstanceNr -function AccessCheck Start ($(ls -ld1 /tmp/.sapstream5${InstanceNr}13))"
1ed92e
+                        super_ocf_log warn "ACT: sapstartsrv will be restarted to try to solve this situation, otherwise please check sapstsartsrv setup (SAP Note 927637)"
1ed92e
+                        restart=1
1ed92e
+                    fi
1ed92e
                 fi
1ed92e
+            else
1ed92e
+                super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName, it will be started now"
1ed92e
+                restart=1
1ed92e
             fi
1ed92e
-        else
1ed92e
-            super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName, it will be started now"
1ed92e
-            restart=1
1ed92e
         fi
1ed92e
-    fi
1ed92e
-    if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi
1ed92e
-    if [ $restart -eq 1 ]
1ed92e
-    then
1ed92e
-        if [ -d /usr/sap/$SID/SYS/profile/ ]
1ed92e
+        if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi
1ed92e
+        if [ $restart -eq 1 ]
1ed92e
         then
1ed92e
-            DIR_PROFILE="/usr/sap/$SID/SYS/profile"
1ed92e
-        else
1ed92e
-            assert "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!"
1ed92e
-        fi
1ed92e
-        [ ! -r $SAPSTARTPROFILE ] && assert "Expected $SAPSTARTPROFILE to be the instance START profile, please set INSTANCE_PROFILE parameter!"
1ed92e
-        pkill -9 -f "sapstartsrv.*$runninginst"
1ed92e
-        # removing the unix domain socket files as they might have wrong permissions
1ed92e
-        # or ownership - they will be recreated by sapstartsrv during next start
1ed92e
-	# TODO: PRIO2: Check, if we need to delete the socket files
1ed92e
-        rm -f /tmp/.sapstream5${InstanceNr}13
1ed92e
-        rm -f /tmp/.sapstream5${InstanceNr}14
1ed92e
-        # DONE: PRI0: WE NEED LD_LIBRARY_PATH HERE!!
1ed92e
-        (
1ed92e
-          export PATH="$DIR_EXECUTABLE${PATH:+:}$PATH"
1ed92e
-          export LD_LIBRARY_PATH="$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
1ed92e
-          $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
1ed92e
-        )
1ed92e
-        # now make sure the daemon has been started and is able to respond
1ed92e
-        local srvrc=1
1ed92e
-        while [ $srvrc -eq 1 -a $(pgrep -f "sapstartsrv.*$runninginst" | wc -l) -gt 0 ]
1ed92e
-        do
1ed92e
-            sleep 1
1ed92e
-            $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1
1ed92e
-            srvrc=$?
1ed92e
-        done
1ed92e
-        if [ $srvrc -ne 1 ]
1ed92e
-        then
1ed92e
-            super_ocf_log info "ACT: sapstartsrv for instance $SID-$InstanceName was restarted!"
1ed92e
-            rc=$OCF_SUCCESS
1ed92e
-        else
1ed92e
-            super_ocf_log error "ACT: sapstartsrv for instance $SID-$InstanceName could not be started!"
1ed92e
-            rc=$OCF_ERR_GENERIC
1ed92e
-            ocf_is_probe && rc=$OCF_NOT_RUNNING
1ed92e
+            if [ -d /usr/sap/$SID/SYS/profile/ ]
1ed92e
+            then
1ed92e
+                DIR_PROFILE="/usr/sap/$SID/SYS/profile"
1ed92e
+            else
1ed92e
+                assert "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!"
1ed92e
+            fi
1ed92e
+            [ ! -r $SAPSTARTPROFILE ] && assert "Expected $SAPSTARTPROFILE to be the instance START profile, please set INSTANCE_PROFILE parameter!"
1ed92e
+            pkill -9 -f "sapstartsrv.*$runninginst"
1ed92e
+            # removing the unix domain socket files as they might have wrong permissions
1ed92e
+            # or ownership - they will be recreated by sapstartsrv during next start
1ed92e
+            # TODO: PRIO2: Check, if we need to delete the socket files
1ed92e
+            rm -f /tmp/.sapstream5${InstanceNr}13
1ed92e
+            rm -f /tmp/.sapstream5${InstanceNr}14
1ed92e
+            # DONE: PRI0: WE NEED LD_LIBRARY_PATH HERE!!
1ed92e
+            (
1ed92e
+              export PATH="$DIR_EXECUTABLE${PATH:+:}$PATH"
1ed92e
+              export LD_LIBRARY_PATH="$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
1ed92e
+              $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
1ed92e
+            )
1ed92e
+            # now make sure the daemon has been started and is able to respond
1ed92e
+            local srvrc=1
1ed92e
+            while [ $srvrc -eq 1 -a $(pgrep -f "sapstartsrv.*$runninginst" | wc -l) -gt 0 ]
1ed92e
+            do
1ed92e
+                sleep 1
1ed92e
+                $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1
1ed92e
+                srvrc=$?
1ed92e
+            done
1ed92e
+            if [ $srvrc -ne 1 ]
1ed92e
+            then
1ed92e
+                super_ocf_log info "ACT: sapstartsrv for instance $SID-$InstanceName was restarted!"
1ed92e
+                rc=$OCF_SUCCESS
1ed92e
+            else
1ed92e
+                super_ocf_log error "ACT: sapstartsrv for instance $SID-$InstanceName could not be started!"
1ed92e
+                rc=$OCF_ERR_GENERIC
1ed92e
+                ocf_is_probe && rc=$OCF_NOT_RUNNING
1ed92e
+            fi
1ed92e
         fi
1ed92e
     fi
1ed92e
     return $rc
1ed92e
diff --git a/heartbeat/SAPHanaTopology b/heartbeat/SAPHanaTopology
1ed92e
index a9cbbf5..b025b5b 100755
1ed92e
--- a/heartbeat/SAPHanaTopology
1ed92e
+++ b/heartbeat/SAPHanaTopology
1ed92e
@@ -14,7 +14,7 @@
1ed92e
 # License:      GNU General Public License (GPL)
1ed92e
 # Copyright:    (c) 2014 SUSE Linux Products GmbH
1ed92e
 #               (c) 2015-2016 SUSE Linux GmbH
1ed92e
-#               (c) 2017-2019 SUSE LLC
1ed92e
+#               (c) 2017-2021 SUSE LLC
1ed92e
 #
1ed92e
 # An example usage:
1ed92e
 #      See usage() function below for more details...
1ed92e
@@ -26,7 +26,7 @@
1ed92e
 #
1ed92e
 #######################################################################
1ed92e
 # DONE PRIO 1: AFTER(!) SAP HANA SPS12 is available we could use hdbnsutil --sr_stateConfiguration
1ed92e
-SAPHanaTopologyVersion="0.180.0.0628.1824"
1ed92e
+SAPHanaTopologyVersion="0.181.0.1123.2015"
1ed92e
 #
1ed92e
 # Initialization:
1ed92e
 timeB=$(date '+%s')
1ed92e
@@ -409,6 +409,8 @@ function sht_init() {
1ed92e
     local hdbANSWER=""
1ed92e
     local siteID
1ed92e
     local siteNAME
1ed92e
+    SYSTEMCTL="/usr/bin/systemctl"
1ed92e
+    systemd_unit_name="saphostagent.service"
1ed92e
     HOSTEXECNAME=saphostexec
1ed92e
     USRSAP=/usr/sap
1ed92e
     SAPSERVICE_PATH=${USRSAP}/sapservices
1ed92e
@@ -562,6 +564,25 @@ function check_for_primary() {
1ed92e
 }
1ed92e
 
1ed92e
 
1ed92e
+# chk4systemdsupport - check, if SAP systemd support is available
1ed92e
+# check for the existence of the SAP Host Agent related unit file
1ed92e
+# rc=0 - SAP Host Agent unit file exists
1ed92e
+# rc=1 - SAP Host Agent unit file does NOT exist
1ed92e
+function chk4systemdsupport() {
1ed92e
+    super_ocf_log info "FLOW ${FUNCNAME[0]}"
1ed92e
+    local rc=1
1ed92e
+    if [ -x "$SYSTEMCTL" ]; then
1ed92e
+        if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then
1ed92e
+            rc=0
1ed92e
+        elif $SYSTEMCTL list-unit-files "$systemd_unit_name"; then
1ed92e
+            rc=0
1ed92e
+        else
1ed92e
+            rc=1
1ed92e
+        fi
1ed92e
+    fi
1ed92e
+    return $rc
1ed92e
+}
1ed92e
+
1ed92e
 #
1ed92e
 # function: start_saphostagent
1ed92e
 # params:   -
1ed92e
@@ -570,8 +591,19 @@ function check_for_primary() {
1ed92e
 function start_saphostagent()
1ed92e
 {
1ed92e
     ### SAP-CALL
1ed92e
-    if [ -x "${HOSTEXEC_PATH}" ]; then
1ed92e
-        ${HOSTEXEC_PATH} pf=${HOSTEXEC_PROFILE_PATH}
1ed92e
+    if chk4systemdsupport; then
1ed92e
+        # use systemd to control saphostagent
1ed92e
+        if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then
1ed92e
+            super_ocf_log info "ACT: systemd service $systemd_unit_name is active"
1ed92e
+        else
1ed92e
+            super_ocf_log warn "ACT: systemd service $systemd_unit_name is not active, it will be started using systemd"
1ed92e
+            $SYSTEMCTL start "$systemd_unit_name" >/dev/null 2>&1
1ed92e
+        fi
1ed92e
+    else
1ed92e
+        # no SAP systemd unit available, continue with old code...
1ed92e
+        if [ -x "${HOSTEXEC_PATH}" ]; then
1ed92e
+            ${HOSTEXEC_PATH} pf=${HOSTEXEC_PROFILE_PATH}
1ed92e
+        fi
1ed92e
     fi
1ed92e
     return 0
1ed92e
 }
1ed92e
@@ -584,8 +616,19 @@ function start_saphostagent()
1ed92e
 function stop_saphostagent()
1ed92e
 {
1ed92e
     ### SAP-CALL
1ed92e
-    if [ -x "${HOSTEXEC_PATH}" ]; then
1ed92e
-        ${HOSTEXEC_PATH} -stop
1ed92e
+    if chk4systemdsupport; then
1ed92e
+        # use systemd to control saphostagent
1ed92e
+        if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then
1ed92e
+            super_ocf_log warn "ACT: systemd service $systemd_unit_name is active, now stopping using systemd"
1ed92e
+            $SYSTEMCTL stop "$systemd_unit_name" >/dev/null 2>&1
1ed92e
+        else
1ed92e
+            super_ocf_log info "ACT: systemd service $systemd_unit_name is not active"
1ed92e
+        fi
1ed92e
+    else
1ed92e
+        # no SAP systemd unit available, continue with old code...
1ed92e
+        if [ -x "${HOSTEXEC_PATH}" ]; then
1ed92e
+            ${HOSTEXEC_PATH} -stop
1ed92e
+        fi
1ed92e
     fi
1ed92e
 }
1ed92e
 
1ed92e
@@ -597,9 +640,20 @@ function stop_saphostagent()
1ed92e
 function check_saphostagent()
1ed92e
 {
1ed92e
     local rc=1
1ed92e
-    # TODO: PRIO3: should the path been removed like "saphostexec" instead of "/usr/sap/hostctrl/exe/saphostexec"
1ed92e
-    #       or should we use ${HOSTEXEC_PATH} instead?
1ed92e
-    pgrep -f /usr/sap/hostctrl/exe/saphostexec; rc=$?
1ed92e
+    if chk4systemdsupport; then
1ed92e
+        # use systemd to control saphostagent
1ed92e
+        if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then
1ed92e
+            super_ocf_log warn "ACT: systemd service $systemd_unit_name is active"
1ed92e
+            rc=0
1ed92e
+        else
1ed92e
+            super_ocf_log info "ACT: systemd service $systemd_unit_name is not active"
1ed92e
+        fi
1ed92e
+    else
1ed92e
+        # no SAP systemd unit available, continue with old code...
1ed92e
+        # TODO: PRIO3: should the path been removed like "saphostexec" instead of "/usr/sap/hostctrl/exe/saphostexec"
1ed92e
+        #       or should we use ${HOSTEXEC_PATH} instead?
1ed92e
+        pgrep -f /usr/sap/hostctrl/exe/saphostexec; rc=$?
1ed92e
+    fi
1ed92e
     return $rc
1ed92e
 }
1ed92e