diff --git a/SOURCES/bz2043021-1-SAPHana-SAPHanaTopology-add-systemd-support.patch b/SOURCES/bz2043021-1-SAPHana-SAPHanaTopology-add-systemd-support.patch new file mode 100644 index 0000000..d46744c --- /dev/null +++ b/SOURCES/bz2043021-1-SAPHana-SAPHanaTopology-add-systemd-support.patch @@ -0,0 +1,315 @@ +From 496f6ab824c51e08c9acc0e50c79495db55f90e8 Mon Sep 17 00:00:00 2001 +From: AngelaBriel +Date: Wed, 24 Nov 2021 15:58:36 +0100 +Subject: [PATCH] add support for the new systemd unit file handling for + sapstartsrv and saphostagent (bsc#1189530, bsc#1189531) + +--- + heartbeat/SAPHana | 148 +++++++++++++++++++++++++++---------------- + heartbeat/SAPHanaTopology | 71 ++++++++++++++++++--- + 5 files changed, 173 insertions(+), 66 deletions(-) + +diff --git a/heartbeat/SAPHana b/heartbeat/SAPHana +index 5da587d..aaff777 100755 +--- a/heartbeat/SAPHana ++++ b/heartbeat/SAPHana +@@ -714,6 +714,7 @@ function saphana_init() { + super_ocf_log info "FLOW $FUNCNAME ($*)" + local rc=$OCF_SUCCESS + local clN ++ SYSTEMCTL="/usr/bin/systemctl" + # local site + # two parameter models (for transition only) + # OLD: InstanceName +@@ -944,6 +945,26 @@ function check_secstore_users() + return $rc + } + ++# chk4systemdsupport - check, if SAP systemd support is available ++# check for the existence of the SAP SID+Instance related unit file ++# rc=0 - sap instance unit file exists ++# rc=1 - sap instance unit file does NOT exist ++function chk4systemdsupport() { ++ super_ocf_log info "FLOW ${FUNCNAME[0]}" ++ local systemd_unit_name="SAP${SID}_${InstanceNr}.service" ++ local rc=1 ++ if [ -x "$SYSTEMCTL" ]; then ++ if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then ++ rc=0 ++ elif $SYSTEMCTL list-unit-files "$systemd_unit_name"; then ++ rc=0 ++ else ++ rc=1 ++ fi ++ fi ++ return $rc ++} ++ + # + # function: check_sapstartsrv - check for sapstartsrv - optional start + # params: - +@@ -956,67 +977,86 @@ function check_sapstartsrv() { + local runninginst="" + local rc=$OCF_SUCCESS + local output="" +- if [ ! -S /tmp/.sapstream5${InstanceNr}13 ]; then +- super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName (no UDS), it will be started now" +- restart=1 ++ if chk4systemdsupport; then ++ # use systemd to control sapstartsrv ++ local systemd_unit_name="SAP${SID}_${InstanceNr}.service" ++ ++ if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then ++ super_ocf_log info "ACT: systemd service $systemd_unit_name is active" ++ else ++ super_ocf_log warn "ACT: systemd service $systemd_unit_name is not active, it will be started using systemd" ++ # use start, because restart does also stop sap instance ++ $SYSTEMCTL start "$systemd_unit_name" >/dev/null 2>&1; src=$? ++ if [ $src -ne 0 ]; then ++ super_ocf_log error "ACT: error during start of systemd unit ${systemd_unit_name}!" ++ rc=$OCF_ERR_GENERIC ++ ocf_is_probe && rc=$OCF_NOT_RUNNING ++ fi ++ fi + else +- output=$($SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script) +- if [ $? -eq 0 ] +- then +- runninginst=$(echo "$output" | grep '^0 : ' | cut -d' ' -f3) +- if [ "$runninginst" != "$InstanceName" ] ++ # no SAP systemd unit available, continue with old code... ++ if [ ! -S /tmp/.sapstream5${InstanceNr}13 ]; then ++ super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName (no UDS), it will be started now" ++ restart=1 ++ else ++ output=$($SAPCONTROL -nr $InstanceNr -function ParameterValue INSTANCE_NAME -format script) ++ if [ $? -eq 0 ] + then +- super_ocf_log warn "ACT: sapstartsrv is running for instance $runninginst, that service will be killed" +- restart=1 +- else +- output=$($SAPCONTROL -nr $InstanceNr -function AccessCheck Start) +- if [ $? -ne 0 ]; then +- super_ocf_log warn "ACT: FAILED - sapcontrol -nr $InstanceNr -function AccessCheck Start ($(ls -ld1 /tmp/.sapstream5${InstanceNr}13))" +- super_ocf_log warn "ACT: sapstartsrv will be restarted to try to solve this situation, otherwise please check sapstsartsrv setup (SAP Note 927637)" ++ runninginst=$(echo "$output" | grep '^0 : ' | cut -d' ' -f3) ++ if [ "$runninginst" != "$InstanceName" ] ++ then ++ super_ocf_log warn "ACT: sapstartsrv is running for instance $runninginst, that service will be killed" + restart=1 ++ else ++ output=$($SAPCONTROL -nr $InstanceNr -function AccessCheck Start) ++ if [ $? -ne 0 ]; then ++ super_ocf_log warn "ACT: FAILED - sapcontrol -nr $InstanceNr -function AccessCheck Start ($(ls -ld1 /tmp/.sapstream5${InstanceNr}13))" ++ super_ocf_log warn "ACT: sapstartsrv will be restarted to try to solve this situation, otherwise please check sapstsartsrv setup (SAP Note 927637)" ++ restart=1 ++ fi + fi ++ else ++ super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName, it will be started now" ++ restart=1 + fi +- else +- super_ocf_log warn "ACT: sapstartsrv is not running for instance $SID-$InstanceName, it will be started now" +- restart=1 + fi +- fi +- if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi +- if [ $restart -eq 1 ] +- then +- if [ -d /usr/sap/$SID/SYS/profile/ ] ++ if [ -z "$runninginst" ]; then runninginst=$InstanceName; fi ++ if [ $restart -eq 1 ] + then +- DIR_PROFILE="/usr/sap/$SID/SYS/profile" +- else +- assert "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!" +- fi +- [ ! -r $SAPSTARTPROFILE ] && assert "Expected $SAPSTARTPROFILE to be the instance START profile, please set INSTANCE_PROFILE parameter!" +- pkill -9 -f "sapstartsrv.*$runninginst" +- # removing the unix domain socket files as they might have wrong permissions +- # or ownership - they will be recreated by sapstartsrv during next start +- rm -f /tmp/.sapstream5${InstanceNr}13 +- rm -f /tmp/.sapstream5${InstanceNr}14 +- ( +- export PATH="$DIR_EXECUTABLE${PATH:+:}$PATH" +- export LD_LIBRARY_PATH="$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" +- $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm +- ) +- # now make sure the daemon has been started and is able to respond +- local srvrc=1 +- while [ $srvrc -eq 1 -a $(pgrep -f "sapstartsrv.*$runninginst" | wc -l) -gt 0 ] +- do +- sleep 1 +- $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1 +- srvrc=$? +- done +- if [ $srvrc -ne 1 ] +- then +- super_ocf_log info "ACT: sapstartsrv for instance $SID-$InstanceName was restarted!" +- rc=$OCF_SUCCESS +- else +- super_ocf_log error "ACT: sapstartsrv for instance $SID-$InstanceName could not be started!" +- rc=$OCF_ERR_GENERIC +- ocf_is_probe && rc=$OCF_NOT_RUNNING ++ if [ -d /usr/sap/$SID/SYS/profile/ ] ++ then ++ DIR_PROFILE="/usr/sap/$SID/SYS/profile" ++ else ++ assert "Expected /usr/sap/$SID/SYS/profile/ to be a directory, please set DIR_PROFILE parameter!" ++ fi ++ [ ! -r $SAPSTARTPROFILE ] && assert "Expected $SAPSTARTPROFILE to be the instance START profile, please set INSTANCE_PROFILE parameter!" ++ pkill -9 -f "sapstartsrv.*$runninginst" ++ # removing the unix domain socket files as they might have wrong permissions ++ # or ownership - they will be recreated by sapstartsrv during next start ++ rm -f /tmp/.sapstream5${InstanceNr}13 ++ rm -f /tmp/.sapstream5${InstanceNr}14 ++ ( ++ export PATH="$DIR_EXECUTABLE${PATH:+:}$PATH" ++ export LD_LIBRARY_PATH="$DIR_EXECUTABLE${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH" ++ $SAPSTARTSRV pf=$SAPSTARTPROFILE -D -u $sidadm ++ ) ++ # now make sure the daemon has been started and is able to respond ++ local srvrc=1 ++ while [ $srvrc -eq 1 -a $(pgrep -f "sapstartsrv.*$runninginst" | wc -l) -gt 0 ] ++ do ++ sleep 1 ++ $SAPCONTROL -nr $InstanceNr -function GetProcessList > /dev/null 2>&1 ++ srvrc=$? ++ done ++ if [ $srvrc -ne 1 ] ++ then ++ super_ocf_log info "ACT: sapstartsrv for instance $SID-$InstanceName was restarted!" ++ rc=$OCF_SUCCESS ++ else ++ super_ocf_log error "ACT: sapstartsrv for instance $SID-$InstanceName could not be started!" ++ rc=$OCF_ERR_GENERIC ++ ocf_is_probe && rc=$OCF_NOT_RUNNING ++ fi + fi + fi + return $rc +diff --git a/heartbeat/SAPHanaTopology b/heartbeat/SAPHanaTopology +index 29819d7..8dd133e 100755 +--- a/heartbeat/SAPHanaTopology ++++ b/heartbeat/SAPHanaTopology +@@ -14,7 +14,7 @@ + # License: GNU General Public License (GPL) + # Copyright: (c) 2014 SUSE Linux Products GmbH + # (c) 2015-2018 SUSE Linux GmbH +-# (c) 2019 SUSE LLC ++# (c) 2019-2021 SUSE LLC + # + # An example usage: + # See usage() function below for more details... +@@ -27,7 +27,7 @@ + # + ####################################################################### + # DONE PRIO 1: AFTER(!) SAP HANA SPS12 is available we could use hdbnsutil --sr_stateConfiguration +-SAPHanaTopologyVersion="0.154.0" ++SAPHanaTopologyVersion="0.155.0" + # + # Initialization: + timeB=$(date '+%s') +@@ -458,6 +458,8 @@ function sht_init() { + local siteID + local siteNAME + local chkMethod="" ++ SYSTEMCTL="/usr/bin/systemctl" ++ systemd_unit_name="saphostagent.service" + HOSTEXECNAME=saphostexec + USRSAP=/usr/sap + SAPSERVICE_PATH=${USRSAP}/sapservices +@@ -662,6 +664,24 @@ function check_for_primary() { + return $rc + } + ++# chk4systemdsupport - check, if SAP systemd support is available ++# check for the existence of the SAP Host Agent related unit file ++# rc=0 - SAP Host Agent unit file exists ++# rc=1 - SAP Host Agent unit file does NOT exist ++function chk4systemdsupport() { ++ super_ocf_log info "FLOW ${FUNCNAME[0]}" ++ local rc=1 ++ if [ -x "$SYSTEMCTL" ]; then ++ if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then ++ rc=0 ++ elif $SYSTEMCTL list-unit-files "$systemd_unit_name"; then ++ rc=0 ++ else ++ rc=1 ++ fi ++ fi ++ return $rc ++} + + # + # function: start_saphostagent +@@ -671,8 +691,19 @@ function check_for_primary() { + function start_saphostagent() + { + ### SAP-CALL +- if [ -x "${HOSTEXEC_PATH}" ]; then +- ${HOSTEXEC_PATH} pf=${HOSTEXEC_PROFILE_PATH} ++ if chk4systemdsupport; then ++ # use systemd to control saphostagent ++ if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then ++ super_ocf_log info "ACT: systemd service $systemd_unit_name is active" ++ else ++ super_ocf_log warn "ACT: systemd service $systemd_unit_name is not active, it will be started using systemd" ++ $SYSTEMCTL start "$systemd_unit_name" >/dev/null 2>&1 ++ fi ++ else ++ # no SAP systemd unit available, continue with old code... ++ if [ -x "${HOSTEXEC_PATH}" ]; then ++ ${HOSTEXEC_PATH} pf=${HOSTEXEC_PROFILE_PATH} ++ fi + fi + return 0 + } +@@ -685,8 +716,19 @@ function start_saphostagent() + function stop_saphostagent() + { + ### SAP-CALL +- if [ -x "${HOSTEXEC_PATH}" ]; then +- ${HOSTEXEC_PATH} -stop ++ if chk4systemdsupport; then ++ # use systemd to control saphostagent ++ if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then ++ super_ocf_log warn "ACT: systemd service $systemd_unit_name is active, now stopping using systemd" ++ $SYSTEMCTL stop "$systemd_unit_name" >/dev/null 2>&1 ++ else ++ super_ocf_log info "ACT: systemd service $systemd_unit_name is not active" ++ fi ++ else ++ # no SAP systemd unit available, continue with old code... ++ if [ -x "${HOSTEXEC_PATH}" ]; then ++ ${HOSTEXEC_PATH} -stop ++ fi + fi + } + +@@ -698,9 +740,20 @@ function stop_saphostagent() + function check_saphostagent() + { + local rc=1 +- # TODO: PRIO3: should the path been removed like "saphostexec" instead of "/usr/sap/hostctrl/exe/saphostexec" +- # or should we use ${HOSTEXEC_PATH} instead? +- pgrep -f /usr/sap/hostctrl/exe/saphostexec; rc=$? ++ if chk4systemdsupport; then ++ # use systemd to control saphostagent ++ if $SYSTEMCTL is-active --quiet "$systemd_unit_name"; then ++ super_ocf_log warn "ACT: systemd service $systemd_unit_name is active" ++ rc=0 ++ else ++ super_ocf_log info "ACT: systemd service $systemd_unit_name is not active" ++ fi ++ else ++ # no SAP systemd unit available, continue with old code... ++ # TODO: PRIO3: should the path been removed like "saphostexec" instead of "/usr/sap/hostctrl/exe/saphostexec" ++ # or should we use ${HOSTEXEC_PATH} instead? ++ pgrep -f /usr/sap/hostctrl/exe/saphostexec; rc=$? ++ fi + return $rc + } + diff --git a/SOURCES/bz2043021-2-SAPHana-SAPHanaTopology-suppress-systemctl-output.patch b/SOURCES/bz2043021-2-SAPHana-SAPHanaTopology-suppress-systemctl-output.patch new file mode 100644 index 0000000..69dcd76 --- /dev/null +++ b/SOURCES/bz2043021-2-SAPHana-SAPHanaTopology-suppress-systemctl-output.patch @@ -0,0 +1,36 @@ +From 28658d187bbfdcb6a7c570f327c20be4ae253794 Mon Sep 17 00:00:00 2001 +From: AngelaBriel +Date: Thu, 25 Nov 2021 15:17:10 +0100 +Subject: [PATCH] supress output of comman 'systemctl list-unit-files' + +--- + heartbeat/SAPHana | 2 +- + heartbeat/SAPHanaTopology | 2 +- + 2 files changed, 2 insertions(+), 2 deletions(-) + +diff --git a/heartbeat/SAPHana b/heartbeat/SAPHana +index aaff777..3569b3d 100755 +--- a/heartbeat/SAPHana ++++ b/heartbeat/SAPHana +@@ -956,7 +956,7 @@ function chk4systemdsupport() { + if [ -x "$SYSTEMCTL" ]; then + if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then + rc=0 +- elif $SYSTEMCTL list-unit-files "$systemd_unit_name"; then ++ elif $SYSTEMCTL list-unit-files "$systemd_unit_name" >/dev/null 2>&1; then + rc=0 + else + rc=1 +diff --git a/heartbeat/SAPHanaTopology b/heartbeat/SAPHanaTopology +index 8dd133e..74f3e72 100755 +--- a/heartbeat/SAPHanaTopology ++++ b/heartbeat/SAPHanaTopology +@@ -674,7 +674,7 @@ function chk4systemdsupport() { + if [ -x "$SYSTEMCTL" ]; then + if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then + rc=0 +- elif $SYSTEMCTL list-unit-files "$systemd_unit_name"; then ++ elif $SYSTEMCTL list-unit-files "$systemd_unit_name" >/dev/null 2>&1; then + rc=0 + else + rc=1 diff --git a/SOURCES/bz2043021-3-SAPHana-SAPHanaTopology-fix-unit-test-issue.patch b/SOURCES/bz2043021-3-SAPHana-SAPHanaTopology-fix-unit-test-issue.patch new file mode 100644 index 0000000..975c302 --- /dev/null +++ b/SOURCES/bz2043021-3-SAPHana-SAPHanaTopology-fix-unit-test-issue.patch @@ -0,0 +1,42 @@ +From 65a7f2b88f674b680160b8015cd1ee1ad61b6293 Mon Sep 17 00:00:00 2001 +From: AngelaBriel +Date: Mon, 20 Dec 2021 10:23:24 +0100 +Subject: [PATCH] The return value of 'systemctl list-unit-files ' is + not reliable on all SLE15 codestreams, so it is not usable for our resource + agents. We need to go back to parsing the command output instead and hoping, + that the output format will not change in the future, because that will + breake the solution again as well. + +--- + heartbeat/SAPHana | 3 ++- + heartbeat/SAPHanaTopology | 3 ++- + 2 files changed, 4 insertions(+), 2 deletions(-) + +diff --git a/heartbeat/SAPHana b/heartbeat/SAPHana +index 3569b3d..ed1ca00 100755 +--- a/heartbeat/SAPHana ++++ b/heartbeat/SAPHana +@@ -956,7 +956,8 @@ function chk4systemdsupport() { + if [ -x "$SYSTEMCTL" ]; then + if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then + rc=0 +- elif $SYSTEMCTL list-unit-files "$systemd_unit_name" >/dev/null 2>&1; then ++ elif $SYSTEMCTL list-unit-files | \ ++ awk '$1 == service { found=1 } END { if (! found) {exit 1}}' service="${systemd_unit_name}.service"; then + rc=0 + else + rc=1 +diff --git a/heartbeat/SAPHanaTopology b/heartbeat/SAPHanaTopology +index 74f3e72..f5dcb30 100755 +--- a/heartbeat/SAPHanaTopology ++++ b/heartbeat/SAPHanaTopology +@@ -674,7 +674,8 @@ function chk4systemdsupport() { + if [ -x "$SYSTEMCTL" ]; then + if [ -f /etc/systemd/system/"$systemd_unit_name" ]; then + rc=0 +- elif $SYSTEMCTL list-unit-files "$systemd_unit_name" >/dev/null 2>&1; then ++ elif $SYSTEMCTL list-unit-files | \ ++ awk '$1 == service { found=1 } END { if (! found) {exit 1}}' service="${systemd_unit_name}.service"; then + rc=0 + else + rc=1 diff --git a/SPECS/resource-agents-sap-hana.spec b/SPECS/resource-agents-sap-hana.spec index bab3a89..d8ef534 100644 --- a/SPECS/resource-agents-sap-hana.spec +++ b/SPECS/resource-agents-sap-hana.spec @@ -29,7 +29,7 @@ Name: resource-agents-sap-hana Summary: SAP HANA cluster resource agents Epoch: 1 Version: 0.154.0 -Release: 3%{?rcver:%{rcver}}%{?numcomm:.%{numcomm}}%{?alphatag:.%{alphatag}}%{?dirty:.%{dirty}}%{?dist}.1 +Release: 3%{?rcver:%{rcver}}%{?numcomm:.%{numcomm}}%{?alphatag:.%{alphatag}}%{?dirty:.%{dirty}}%{?dist}.3 License: GPLv2+ URL: https://github.com/SUSE/SAPHanaSR %if 0%{?fedora} || 0%{?centos_version} || 0%{?rhel} @@ -42,6 +42,9 @@ Source1: %{saphana_prefix}-%{saphana_version}.tar.gz Patch0: bz1855885-SAPHana-use-actual-mode.patch Patch1: bz2027456-1-SAPHana-remove-HANA_CALL_TIMEOUT-parameter.patch Patch2: bz2027456-2-SAPHanaTopology-remove-HANA_CALL_TIMEOUT-parameter.patch +Patch3: bz2043021-1-SAPHana-SAPHanaTopology-add-systemd-support.patch +Patch4: bz2043021-2-SAPHana-SAPHanaTopology-suppress-systemctl-output.patch +Patch5: bz2043021-3-SAPHana-SAPHanaTopology-fix-unit-test-issue.patch BuildArch: noarch @@ -78,6 +81,9 @@ sed -i -e 's/\("provider_company": \)"SUSE"/\1"Red Hat"/g' %{saphana_prefix}-%{s %patch0 -p1 %patch1 -p1 %patch2 -p1 +%patch3 -p1 +%patch4 -p1 +%patch5 -p1 %build if [ ! -f configure ]; then @@ -134,6 +140,11 @@ rm -rf %{buildroot} %exclude /usr/src %changelog +* Thu Jan 20 2022 Oyvind Albrigtsen - 0.154.0-3.3 +- SAPHana/SAPHanaTopology: add systemd support + + Resolves: rhbz#2043021 + * Tue Nov 30 2021 Oyvind Albrigtsen - 0.154.0-3.1 - SAPHana/SAPHanaTopology: remove HANA_CALL_TIMEOUT parameter from metadata