|
|
fa612c |
From 2d50c76c366df4e6021c2992e085bbc48fa112b0 Mon Sep 17 00:00:00 2001
|
|
|
fa612c |
From: fmherschel <fh-github@herschel-mainz.org>
|
|
|
fa612c |
Date: Fri, 25 Jun 2021 16:16:51 +0200
|
|
|
fa612c |
Subject: [PATCH] SAPInstance: add systemd compatability (#1662)
|
|
|
fa612c |
|
|
|
fa612c |
* SAPInstance: for systemd integrated sapstartsrv instances use systemd to check/start the service
|
|
|
fa612c |
---
|
|
|
fa612c |
heartbeat/SAPInstance | 146 ++++++++++++++++++++++++++----------------
|
|
|
fa612c |
1 file changed, 91 insertions(+), 55 deletions(-)
|
|
|
fa612c |
|
|
|
fa612c |
diff --git a/heartbeat/SAPInstance b/heartbeat/SAPInstance
|
|
|
fa612c |
index 8c404d4376..15b24024e0 100755
|
|
|
fa612c |
--- a/heartbeat/SAPInstance
|
|
|
fa612c |
+++ b/heartbeat/SAPInstance
|
|
|
fa612c |
@@ -369,6 +369,7 @@ sapinstance_init() {
|
|
|
fa612c |
InstanceName=`echo "$myInstanceName" | cut -d_ -f2`
|
|
|
fa612c |
InstanceNr=`echo "$InstanceName" | sed 's/.*\([0-9][0-9]\)$/\1/'`
|
|
|
fa612c |
SAPVIRHOST=`echo "$myInstanceName" | cut -d_ -f3`
|
|
|
fa612c |
+ SYSTEMCTL="systemctl"
|
|
|
fa612c |
|
|
|
fa612c |
# optional OCF parameters, we try to guess which directories are correct
|
|
|
fa612c |
if [ -z "$OCF_RESKEY_DIR_EXECUTABLE" ]
|
|
|
fa612c |
@@ -446,6 +447,25 @@ sapinstance_init() {
|
|
|
fa612c |
return $OCF_SUCCESS
|
|
|
fa612c |
}
|
|
|
fa612c |
|
|
|
fa612c |
+#
|
|
|
fa612c |
+# check_systemd_integration : Check, if SAP instance is controlled by systemd unit file SAP<SID>_<InstanceNr>.service
|
|
|
fa612c |
+# rc == 0 : sap instance is controlled by the unit file (file at least exists)
|
|
|
fa612c |
+# rc == 1 : sap instance is NOT controlled by the unit file (file does not exist)
|
|
|
fa612c |
+#
|
|
|
fa612c |
+check_systemd_integration() {
|
|
|
fa612c |
+ local systemd_unit_name="SAP${SID}_${InstanceNr}"
|
|
|
fa612c |
+ local rc=1
|
|
|
fa612c |
+
|
|
|
fa612c |
+ if [ -x "$SYSTEMCTL" ]; then
|
|
|
fa612c |
+ if $SYSTEMCTL list-unit-files | \
|
|
|
fa612c |
+ awk '$1 == service { found=1 } END { if (! found) {exit 1}}' service="${systemd_unit_name}.service"; then
|
|
|
fa612c |
+ rc=0
|
|
|
fa612c |
+ else
|
|
|
fa612c |
+ rc=1
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
+ return "$rc"
|
|
|
fa612c |
+}
|
|
|
fa612c |
|
|
|
fa612c |
#
|
|
|
fa612c |
# check_sapstartsrv : Before using sapcontrol we make sure that the sapstartsrv is running for the correct instance.
|
|
|
fa612c |
@@ -458,76 +478,92 @@ check_sapstartsrv() {
|
|
|
fa612c |
local chkrc=$OCF_SUCCESS
|
|
|
fa612c |
local output=""
|
|
|
fa612c |
|
|
|
fa612c |
- if [ ! -S /tmp/.sapstream5${InstanceNr}13 ]; then
|
|
|
fa612c |
- ocf_log warn "sapstartsrv is not running for instance $SID-$InstanceName (no UDS), it will be started now"
|
|
|
fa612c |
- restart=1
|
|
|
fa612c |
- else
|
|
|
fa612c |
- output=`$SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script`
|
|
|
fa612c |
- if [ $? -eq 0 ]
|
|
|
fa612c |
- then
|
|
|
fa612c |
- runninginst=`echo "$output" | grep '^0 : ' | cut -d' ' -f3`
|
|
|
fa612c |
- if [ "$runninginst" != "$InstanceName" ]
|
|
|
fa612c |
- then
|
|
|
fa612c |
- ocf_log warn "sapstartsrv is running for instance $runninginst, that service will be killed"
|
|
|
fa612c |
+ # check for sapstartsrv/systemd integration
|
|
|
fa612c |
+
|
|
|
fa612c |
+ if check_systemd_integration; then
|
|
|
fa612c |
+ # do it the systemd way
|
|
|
fa612c |
+ local systemd_unit_name="SAP${SID}_${InstanceNr}"
|
|
|
fa612c |
+
|
|
|
fa612c |
+ if $SYSTEMCTL status "$systemd_unit_name" 1>/dev/null 2>/dev/null; then
|
|
|
fa612c |
+ ocf_log info "systemd service $systemd_unit_name is active"
|
|
|
fa612c |
+ else
|
|
|
fa612c |
+ ocf_log warn "systemd service $systemd_unit_name is not active, it will be started using systemd"
|
|
|
fa612c |
+ $SYSTEMCTL start "$systemd_unit_name" 1>/dev/null 2>/dev/null
|
|
|
fa612c |
+ # use start, because restart does also stop sap instance
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
+
|
|
|
fa612c |
+ return 0
|
|
|
fa612c |
+ else # otherwise continue with old code...
|
|
|
fa612c |
+ if [ ! -S /tmp/.sapstream5${InstanceNr}13 ]; then
|
|
|
fa612c |
+ ocf_log warn "sapstartsrv is not running for instance $SID-$InstanceName (no UDS), it will be started now"
|
|
|
fa612c |
restart=1
|
|
|
fa612c |
else
|
|
|
fa612c |
- output=`$SAPCONTROL -nr $InstanceNr -function AccessCheck Start`
|
|
|
fa612c |
- if [ $? -ne 0 ]; then
|
|
|
fa612c |
- ocf_log warn "FAILED : sapcontrol -nr $InstanceNr -function AccessCheck Start (`ls -ld1 /tmp/.sapstream5${InstanceNr}13`)"
|
|
|
fa612c |
- ocf_log warn "sapstartsrv will be restarted to try to solve this situation, otherwise please check sapstsartsrv setup (SAP Note 927637)"
|
|
|
fa612c |
+ output=`$SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script`
|
|
|
fa612c |
+ if [ $? -eq 0 ]
|
|
|
fa612c |
+ then
|
|
|
fa612c |
+ runninginst=`echo "$output" | grep '^0 : ' | cut -d' ' -f3`
|
|
|
fa612c |
+ if [ "$runninginst" != "$InstanceName" ]
|
|
|
fa612c |
+ then
|
|
|
fa612c |
+ ocf_log warn "sapstartsrv is running for instance $runninginst, that service will be killed"
|
|
|
fa612c |
+ restart=1
|
|
|
fa612c |
+ else
|
|
|
fa612c |
+ output=`$SAPCONTROL -nr $InstanceNr -function AccessCheck Start`
|
|
|
fa612c |
+ if [ $? -ne 0 ]; then
|
|
|
fa612c |
+ ocf_log warn "FAILED : sapcontrol -nr $InstanceNr -function AccessCheck Start (`ls -ld1 /tmp/.sapstream5${InstanceNr}13`)"
|
|
|
fa612c |
+ ocf_log warn "sapstartsrv will be restarted to try to solve this situation, otherwise please check sapstsartsrv setup (SAP Note 927637)"
|
|
|
fa612c |
+ restart=1
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
+ else
|
|
|
fa612c |
+ ocf_log warn "sapstartsrv is not running for instance $SID-$InstanceName, it will be started now"
|
|
|
fa612c |
restart=1
|
|
|
fa612c |
fi
|
|
|
fa612c |
fi
|
|
|
fa612c |
- else
|
|
|
fa612c |
- ocf_log warn "sapstartsrv is not running for instance $SID-$InstanceName, it will be started now"
|
|
|
fa612c |
- restart=1
|
|
|
fa612c |
- fi
|
|
|
fa612c |
- fi
|
|
|
fa612c |
|
|
|
fa612c |
- if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi
|
|
|
fa612c |
+ if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi
|
|
|
fa612c |
|
|
|
fa612c |
- if [ $restart -eq 1 ]
|
|
|
fa612c |
- then
|
|
|
fa612c |
+ if [ $restart -eq 1 ]
|
|
|
fa612c |
+ then
|
|
|
fa612c |
+ if [ -d /usr/sap/$SID/SYS/profile/ ]
|
|
|
fa612c |
+ then
|
|
|
fa612c |
+ DIR_PROFILE="/usr/sap/$SID/SYS/profile"
|
|
|
fa612c |
+ else
|
|
|
fa612c |
+ abnormal_end "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!"
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
|
|
|
fa612c |
- if [ -d /usr/sap/$SID/SYS/profile/ ]
|
|
|
fa612c |
- then
|
|
|
fa612c |
- DIR_PROFILE="/usr/sap/$SID/SYS/profile"
|
|
|
fa612c |
- else
|
|
|
fa612c |
- abnormal_end "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!"
|
|
|
fa612c |
- fi
|
|
|
fa612c |
+ [ ! -r $SAPSTARTPROFILE ] && abnormal_end "Expected $SAPSTARTPROFILE to be the instance START profile, please set START_PROFILE parameter!"
|
|
|
fa612c |
|
|
|
fa612c |
- [ ! -r $SAPSTARTPROFILE ] && abnormal_end "Expected $SAPSTARTPROFILE to be the instance START profile, please set START_PROFILE parameter!"
|
|
|
fa612c |
+ pkill -9 -f "sapstartsrv.*$runninginst"
|
|
|
fa612c |
|
|
|
fa612c |
- pkill -9 -f "sapstartsrv.*$runninginst"
|
|
|
fa612c |
+ # removing the unix domain socket files as they might have wrong permissions
|
|
|
fa612c |
+ # or ownership - they will be recreated by sapstartsrv during next start
|
|
|
fa612c |
+ rm -f /tmp/.sapstream5${InstanceNr}13
|
|
|
fa612c |
+ rm -f /tmp/.sapstream5${InstanceNr}14
|
|
|
fa612c |
|
|
|
fa612c |
- # removing the unix domain socket files as they might have wrong permissions
|
|
|
fa612c |
- # or ownership - they will be recreated by sapstartsrv during next start
|
|
|
fa612c |
- rm -f /tmp/.sapstream5${InstanceNr}13
|
|
|
fa612c |
- rm -f /tmp/.sapstream5${InstanceNr}14
|
|
|
fa612c |
+ $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
|
|
|
fa612c |
|
|
|
fa612c |
- $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm
|
|
|
fa612c |
+ # now make sure the daemon has been started and is able to respond
|
|
|
fa612c |
+ local srvrc=1
|
|
|
fa612c |
+ while [ $srvrc -eq 1 -a `pgrep -f "sapstartsrv.*$runninginst" | wc -l` -gt 0 ]
|
|
|
fa612c |
+ do
|
|
|
fa612c |
+ sleep 1
|
|
|
fa612c |
+ $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1
|
|
|
fa612c |
+ srvrc=$?
|
|
|
fa612c |
+ done
|
|
|
fa612c |
|
|
|
fa612c |
- # now make sure the daemon has been started and is able to respond
|
|
|
fa612c |
- local srvrc=1
|
|
|
fa612c |
- while [ $srvrc -eq 1 -a `pgrep -f "sapstartsrv.*$runninginst" | wc -l` -gt 0 ]
|
|
|
fa612c |
- do
|
|
|
fa612c |
- sleep 1
|
|
|
fa612c |
- $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1
|
|
|
fa612c |
- srvrc=$?
|
|
|
fa612c |
- done
|
|
|
fa612c |
+ if [ $srvrc -ne 1 ]
|
|
|
fa612c |
+ then
|
|
|
fa612c |
+ ocf_log info "sapstartsrv for instance $SID-$InstanceName was restarted !"
|
|
|
fa612c |
+ chkrc=$OCF_SUCCESS
|
|
|
fa612c |
+ else
|
|
|
fa612c |
+ ocf_log error "sapstartsrv for instance $SID-$InstanceName could not be started!"
|
|
|
fa612c |
+ chkrc=$OCF_ERR_GENERIC
|
|
|
fa612c |
+ ocf_is_probe && chkrc=$OCF_NOT_RUNNING
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
+ fi
|
|
|
fa612c |
|
|
|
fa612c |
- if [ $srvrc -ne 1 ]
|
|
|
fa612c |
- then
|
|
|
fa612c |
- ocf_log info "sapstartsrv for instance $SID-$InstanceName was restarted !"
|
|
|
fa612c |
- chkrc=$OCF_SUCCESS
|
|
|
fa612c |
- else
|
|
|
fa612c |
- ocf_log error "sapstartsrv for instance $SID-$InstanceName could not be started!"
|
|
|
fa612c |
- chkrc=$OCF_ERR_GENERIC
|
|
|
fa612c |
- ocf_is_probe && chkrc=$OCF_NOT_RUNNING
|
|
|
fa612c |
- fi
|
|
|
fa612c |
+ return $chkrc
|
|
|
fa612c |
fi
|
|
|
fa612c |
-
|
|
|
fa612c |
- return $chkrc
|
|
|
fa612c |
}
|
|
|
fa612c |
|
|
|
fa612c |
|