From 1450ab47f5645c46e5a1f2fe9096c7db30961ab3 Mon Sep 17 00:00:00 2001 From: AngelaBriel Date: Wed, 24 Nov 2021 14:51:30 +0100 Subject: [PATCH] add support for the new systemd unit file handling for sapstartsrv and saphostagent (bsc#1189532, bsc#1189533) --- heartbeat/SAPHanaController | 153 ++++++++++++++++++----------- heartbeat/SAPHanaTopology | 72 ++++++++++++-- 4 files changed, 172 insertions(+), 67 deletions(-) diff --git a/heartbeat/SAPHanaController b/heartbeat/SAPHanaController index fa47ec5..a98293c 100755 --- a/heartbeat/SAPHanaController +++ b/heartbeat/SAPHanaController @@ -34,7 +34,7 @@ # systemReplicationStatus.py (>= SPS090) # ####################################################################### -SAPHanaControllerVersion="0.180.0.0628.1823" +SAPHanaControllerVersion="0.181.0.1123.1923" # Resource Agent Generation RAG="2.0" @@ -765,6 +765,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 @@ -1125,6 +1126,25 @@ function saphana_init() { return $OCF_SUCCESS } +# 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 @@ -1138,69 +1158,88 @@ 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 - # TODO: PRIO2: Check, if we need to delete the socket files - rm -f /tmp/.sapstream5${InstanceNr}13 - rm -f /tmp/.sapstream5${InstanceNr}14 - # DONE: PRI0: WE NEED LD_LIBRARY_PATH HERE!! - ( - 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 + # TODO: PRIO2: Check, if we need to delete the socket files + rm -f /tmp/.sapstream5${InstanceNr}13 + rm -f /tmp/.sapstream5${InstanceNr}14 + # DONE: PRI0: WE NEED LD_LIBRARY_PATH HERE!! + ( + 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 a9cbbf5..b025b5b 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-2016 SUSE Linux GmbH -# (c) 2017-2019 SUSE LLC +# (c) 2017-2021 SUSE LLC # # An example usage: # See usage() function below for more details... @@ -26,7 +26,7 @@ # ####################################################################### # DONE PRIO 1: AFTER(!) SAP HANA SPS12 is available we could use hdbnsutil --sr_stateConfiguration -SAPHanaTopologyVersion="0.180.0.0628.1824" +SAPHanaTopologyVersion="0.181.0.1123.2015" # # Initialization: timeB=$(date '+%s') @@ -409,6 +409,8 @@ function sht_init() { local hdbANSWER="" local siteID local siteNAME + SYSTEMCTL="/usr/bin/systemctl" + systemd_unit_name="saphostagent.service" HOSTEXECNAME=saphostexec USRSAP=/usr/sap SAPSERVICE_PATH=${USRSAP}/sapservices @@ -562,6 +564,25 @@ function check_for_primary() { } +# 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 # params: - @@ -570,8 +591,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 } @@ -584,8 +616,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 } @@ -597,9 +640,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 }