9f5ccc
From 2d5e678f8331d4d99ee4dff6e166cbf01c83ab36 Mon Sep 17 00:00:00 2001
9f5ccc
From: "Kaleb S. KEITHLEY" <kkeithle@redhat.com>
9f5ccc
Date: Wed, 12 Feb 2020 12:47:57 -0500
9f5ccc
Subject: [PATCH 357/357] ganesha-ha: updates for pcs-0.10.x (i.e. in Fedora-29
9f5ccc
 and RHEL-8)
9f5ccc
9f5ccc
pcs-0.10 has introduced changes options to pcs commands
9f5ccc
9f5ccc
pcs-0.10.x is in Fedora-29 and later and RHEL-8.
9f5ccc
9f5ccc
Also some minor cleanup. Namely use bash built-in [[...]] in a few
9f5ccc
more places instead of test(1), i.e. [...], and use correct "==" for
9f5ccc
comparison.
9f5ccc
9f5ccc
master: https://review.gluster.org/24115
9f5ccc
9f5ccc
Change-Id: I3fb2fcd71406964c77fdc4f18580ca133f365fd6
9f5ccc
BUG: 1802727
9f5ccc
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
9f5ccc
Reviewed-on: https://code.engineering.redhat.com/gerrit/194467
9f5ccc
Tested-by: RHGS Build Bot <nigelb@redhat.com>
9f5ccc
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
9f5ccc
---
9f5ccc
 extras/ganesha/scripts/ganesha-ha.sh | 84 ++++++++++++++++++++++++------------
9f5ccc
 1 file changed, 56 insertions(+), 28 deletions(-)
9f5ccc
9f5ccc
diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
9f5ccc
index 32af1ca..0b0050a 100644
9f5ccc
--- a/extras/ganesha/scripts/ganesha-ha.sh
9f5ccc
+++ b/extras/ganesha/scripts/ganesha-ha.sh
9f5ccc
@@ -28,7 +28,12 @@ HA_VOL_MNT="/var/run/gluster/shared_storage"
9f5ccc
 HA_CONFDIR=$HA_VOL_MNT"/nfs-ganesha"
9f5ccc
 SERVICE_MAN="DISTRO_NOT_FOUND"
9f5ccc
 
9f5ccc
-RHEL6_PCS_CNAME_OPTION="--name"
9f5ccc
+# rhel, fedora id, version
9f5ccc
+ID=""
9f5ccc
+VERSION_ID=""
9f5ccc
+
9f5ccc
+PCS9OR10_PCS_CNAME_OPTION=""
9f5ccc
+PCS9OR10_PCS_CLONE_OPTION="clone"
9f5ccc
 SECRET_PEM="/var/lib/glusterd/nfs/secret.pem"
9f5ccc
 
9f5ccc
 # UNBLOCK RA uses shared_storage which may become unavailable
9f5ccc
@@ -101,9 +106,9 @@ determine_service_manager () {
9f5ccc
         then
9f5ccc
                 SERVICE_MAN="/sbin/service"
9f5ccc
         fi
9f5ccc
-        if [ "${SERVICE_MAN}" == "DISTRO_NOT_FOUND" ]
9f5ccc
+        if [[ "${SERVICE_MAN}X" == "DISTRO_NOT_FOUNDX" ]]
9f5ccc
         then
9f5ccc
-                echo "Service manager not recognized, exiting"
9f5ccc
+                logger "Service manager not recognized, exiting"
9f5ccc
                 exit 1
9f5ccc
         fi
9f5ccc
 }
9f5ccc
@@ -114,7 +119,7 @@ manage_service ()
9f5ccc
         local new_node=${2}
9f5ccc
         local option=
9f5ccc
 
9f5ccc
-        if [ "${action}" == "start" ]; then
9f5ccc
+        if [[ "${action}" == "start" ]]; then
9f5ccc
                 option="yes"
9f5ccc
         else
9f5ccc
                 option="no"
9f5ccc
@@ -122,7 +127,7 @@ manage_service ()
9f5ccc
         ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
9f5ccc
 ${SECRET_PEM} root@${new_node} "${GANESHA_HA_SH} --setup-ganesha-conf-files $HA_CONFDIR $option"
9f5ccc
 
9f5ccc
-        if [ "${SERVICE_MAN}" == "/bin/systemctl" ]
9f5ccc
+        if [[ "${SERVICE_MAN}" == "/bin/systemctl" ]]
9f5ccc
         then
9f5ccc
                 ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
9f5ccc
 ${SECRET_PEM} root@${new_node} "${SERVICE_MAN}  ${action} nfs-ganesha"
9f5ccc
@@ -140,7 +145,7 @@ check_cluster_exists()
9f5ccc
 
9f5ccc
     if [ -e /var/run/corosync.pid ]; then
9f5ccc
         cluster_name=$(pcs status | grep "Cluster name:" | cut -d ' ' -f 3)
9f5ccc
-        if [ ${cluster_name} -a ${cluster_name} = ${name} ]; then
9f5ccc
+        if [[ "${cluster_name}X" == "${name}X" ]]; then
9f5ccc
             logger "$name already exists, exiting"
9f5ccc
             exit 0
9f5ccc
         fi
9f5ccc
@@ -155,7 +160,7 @@ determine_servers()
9f5ccc
     local tmp_ifs=${IFS}
9f5ccc
     local ha_servers=""
9f5ccc
 
9f5ccc
-    if [ "X${cmd}X" != "XsetupX" -a "X${cmd}X" != "XstatusX" ]; then
9f5ccc
+    if [ "${cmd}X" != "setupX" -a "${cmd}X" != "statusX" ]; then
9f5ccc
         ha_servers=$(pcs status | grep "Online:" | grep -o '\[.*\]' | sed -e 's/\[//' | sed -e 's/\]//')
9f5ccc
         IFS=$' '
9f5ccc
         for server in ${ha_servers} ; do
9f5ccc
@@ -193,15 +198,21 @@ setup_cluster()
9f5ccc
 
9f5ccc
     logger "setting up cluster ${name} with the following ${servers}"
9f5ccc
 
9f5ccc
-    pcs cluster auth ${servers}
9f5ccc
-    # pcs cluster setup --name ${name} ${servers}
9f5ccc
-    pcs cluster setup ${RHEL6_PCS_CNAME_OPTION} ${name} --enable --transport udpu ${servers}
9f5ccc
+    # pcs cluster setup --force ${PCS9OR10_PCS_CNAME_OPTION} ${name} ${servers}
9f5ccc
+    pcs cluster setup --force ${PCS9OR10_PCS_CNAME_OPTION} ${name} --enable ${servers}
9f5ccc
     if [ $? -ne 0 ]; then
9f5ccc
-        logger "pcs cluster setup ${RHEL6_PCS_CNAME_OPTION} ${name} --enable --transport udpu ${servers} failed"
9f5ccc
+        logger "pcs cluster setup ${PCS9OR10_PCS_CNAME_OPTION} ${name} --enable ${servers} failed, shutting down ganesha and bailing out"
9f5ccc
         #set up failed stop all ganesha process and clean up symlinks in cluster
9f5ccc
         stop_ganesha_all "${servers}"
9f5ccc
         exit 1;
9f5ccc
     fi
9f5ccc
+
9f5ccc
+    # pcs cluster auth ${servers}
9f5ccc
+    pcs cluster auth
9f5ccc
+    if [ $? -ne 0 ]; then
9f5ccc
+        logger "pcs cluster auth failed"
9f5ccc
+    fi
9f5ccc
+
9f5ccc
     pcs cluster start --all
9f5ccc
     if [ $? -ne 0 ]; then
9f5ccc
         logger "pcs cluster start failed"
9f5ccc
@@ -217,7 +228,7 @@ setup_cluster()
9f5ccc
     done
9f5ccc
 
9f5ccc
     unclean=$(pcs status | grep -u "UNCLEAN")
9f5ccc
-    while [[ "${unclean}X" = "UNCLEANX" ]]; do
9f5ccc
+    while [[ "${unclean}X" == "UNCLEANX" ]]; do
9f5ccc
          sleep 1
9f5ccc
          unclean=$(pcs status | grep -u "UNCLEAN")
9f5ccc
     done
9f5ccc
@@ -244,7 +255,7 @@ setup_finalize_ha()
9f5ccc
     local stopped=""
9f5ccc
 
9f5ccc
     stopped=$(pcs status | grep -u "Stopped")
9f5ccc
-    while [[ "${stopped}X" = "StoppedX" ]]; do
9f5ccc
+    while [[ "${stopped}X" == "StoppedX" ]]; do
9f5ccc
          sleep 1
9f5ccc
          stopped=$(pcs status | grep -u "Stopped")
9f5ccc
     done
9f5ccc
@@ -265,7 +276,7 @@ refresh_config ()
9f5ccc
         if [ -e ${SECRET_PEM} ]; then
9f5ccc
         while [[ ${3} ]]; do
9f5ccc
             current_host=`echo ${3} | cut -d "." -f 1`
9f5ccc
-            if [ ${short_host} != ${current_host} ]; then
9f5ccc
+            if [[ ${short_host} != ${current_host} ]]; then
9f5ccc
                 output=$(ssh -oPasswordAuthentication=no \
9f5ccc
 -oStrictHostKeyChecking=no -i ${SECRET_PEM} root@${current_host} \
9f5ccc
 "dbus-send --print-reply --system --dest=org.ganesha.nfsd \
9f5ccc
@@ -398,7 +409,7 @@ wrap_create_virt_ip_constraints()
9f5ccc
     # the result is "node2 node3 node4"; for node2, "node3 node4 node1"
9f5ccc
     # and so on.
9f5ccc
     while [[ ${1} ]]; do
9f5ccc
-        if [ "${1}" = "${primary}" ]; then
9f5ccc
+        if [[ ${1} == ${primary} ]]; then
9f5ccc
             shift
9f5ccc
             while [[ ${1} ]]; do
9f5ccc
                 tail=${tail}" "${1}
9f5ccc
@@ -429,15 +440,15 @@ setup_create_resources()
9f5ccc
     local cibfile=$(mktemp -u)
9f5ccc
 
9f5ccc
     # fixup /var/lib/nfs
9f5ccc
-    logger "pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone"
9f5ccc
-    pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone
9f5ccc
+    logger "pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} ${PCS9OR10_PCS_CLONE_OPTION}"
9f5ccc
+    pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} ${PCS9OR10_PCS_CLONE_OPTION}
9f5ccc
     if [ $? -ne 0 ]; then
9f5ccc
-        logger "warning: pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} --clone failed"
9f5ccc
+        logger "warning: pcs resource create nfs_setup ocf:heartbeat:ganesha_nfsd ha_vol_mnt=${HA_VOL_MNT} ${PCS9OR10_PCS_CLONE_OPTION} failed"
9f5ccc
     fi
9f5ccc
 
9f5ccc
-    pcs resource create nfs-mon ocf:heartbeat:ganesha_mon --clone
9f5ccc
+    pcs resource create nfs-mon ocf:heartbeat:ganesha_mon ${PCS9OR10_PCS_CLONE_OPTION}
9f5ccc
     if [ $? -ne 0 ]; then
9f5ccc
-        logger "warning: pcs resource create nfs-mon ocf:heartbeat:ganesha_mon --clone failed"
9f5ccc
+        logger "warning: pcs resource create nfs-mon ocf:heartbeat:ganesha_mon ${PCS9OR10_PCS_CLONE_OPTION} failed"
9f5ccc
     fi
9f5ccc
 
9f5ccc
     # see comment in (/usr/lib/ocf/resource.d/heartbeat/ganesha_grace
9f5ccc
@@ -445,9 +456,9 @@ setup_create_resources()
9f5ccc
     # ganesha-active crm_attribute
9f5ccc
     sleep 5
9f5ccc
 
9f5ccc
-    pcs resource create nfs-grace ocf:heartbeat:ganesha_grace --clone notify=true
9f5ccc
+    pcs resource create nfs-grace ocf:heartbeat:ganesha_grace ${PCS9OR10_PCS_CLONE_OPTION} notify=true
9f5ccc
     if [ $? -ne 0 ]; then
9f5ccc
-        logger "warning: pcs resource create nfs-grace ocf:heartbeat:ganesha_grace --clone failed"
9f5ccc
+        logger "warning: pcs resource create nfs-grace ocf:heartbeat:ganesha_grace ${PCS9OR10_PCS_CLONE_OPTION} failed"
9f5ccc
     fi
9f5ccc
 
9f5ccc
     pcs constraint location nfs-grace-clone rule score=-INFINITY grace-active ne 1
9f5ccc
@@ -616,7 +627,7 @@ addnode_recreate_resources()
9f5ccc
     --after ${add_node}-nfs_block
9f5ccc
     if [ $? -ne 0 ]; then
9f5ccc
         logger "warning pcs resource create ${add_node}-cluster_ip-1 ocf:heartbeat:IPaddr \
9f5ccc
-	ip=${add_vip} cidr_netmask=32 op monitor interval=15s failed"
9f5ccc
+        ip=${add_vip} cidr_netmask=32 op monitor interval=15s failed"
9f5ccc
     fi
9f5ccc
 
9f5ccc
     pcs -f ${cibfile} constraint order nfs-grace-clone then ${add_node}-cluster_ip-1
9f5ccc
@@ -780,7 +791,7 @@ setup_state_volume()
9f5ccc
             touch ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state
9f5ccc
         fi
9f5ccc
         for server in ${HA_SERVERS} ; do
9f5ccc
-            if [ ${server} != ${dirname} ]; then
9f5ccc
+            if [[ ${server} != ${dirname} ]]; then
9f5ccc
                 ln -s ${mnt}/nfs-ganesha/${server}/nfs/ganesha ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/${server}
9f5ccc
                 ln -s ${mnt}/nfs-ganesha/${server}/nfs/statd ${mnt}/nfs-ganesha/${dirname}/nfs/statd/${server}
9f5ccc
             fi
9f5ccc
@@ -794,7 +805,7 @@ setup_state_volume()
9f5ccc
 enable_pacemaker()
9f5ccc
 {
9f5ccc
     while [[ ${1} ]]; do
9f5ccc
-        if [ "${SERVICE_MAN}" == "/usr/bin/systemctl" ]; then
9f5ccc
+        if [[ "${SERVICE_MAN}" == "/bin/systemctl" ]]; then
9f5ccc
             ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
9f5ccc
 ${SECRET_PEM} root@${1} "${SERVICE_MAN} enable pacemaker"
9f5ccc
         else
9f5ccc
@@ -892,7 +903,7 @@ delnode_state_volume()
9f5ccc
     rm -rf ${mnt}/nfs-ganesha/${dirname}
9f5ccc
 
9f5ccc
     for server in ${HA_SERVERS} ; do
9f5ccc
-        if [[ "${server}" != "${dirname}" ]]; then
9f5ccc
+        if [[ ${server} != ${dirname} ]]; then
9f5ccc
             rm -f ${mnt}/nfs-ganesha/${server}/nfs/ganesha/${dirname}
9f5ccc
             rm -f ${mnt}/nfs-ganesha/${server}/nfs/statd/${dirname}
9f5ccc
         fi
9f5ccc
@@ -963,7 +974,7 @@ status()
9f5ccc
 
9f5ccc
 create_ganesha_conf_file()
9f5ccc
 {
9f5ccc
-        if [ $1 == "yes" ];
9f5ccc
+        if [[ "$1" == "yes" ]];
9f5ccc
         then
9f5ccc
                 if [  -e $GANESHA_CONF ];
9f5ccc
                 then
9f5ccc
@@ -1012,6 +1023,13 @@ main()
9f5ccc
      semanage boolean -m gluster_use_execmem --on
9f5ccc
     fi
9f5ccc
 
9f5ccc
+    local osid=""
9f5ccc
+
9f5ccc
+    osid=$(grep ^ID= /etc/os-release)
9f5ccc
+    eval $(echo ${osid} | grep -F ID=)
9f5ccc
+    osid=$(grep ^VERSION_ID= /etc/os-release)
9f5ccc
+    eval $(echo ${osid} | grep -F VERSION_ID=)
9f5ccc
+
9f5ccc
     HA_CONFDIR=${1%/}; shift
9f5ccc
     local ha_conf=${HA_CONFDIR}/ganesha-ha.conf
9f5ccc
     local node=""
9f5ccc
@@ -1032,7 +1050,17 @@ main()
9f5ccc
 
9f5ccc
         determine_servers "setup"
9f5ccc
 
9f5ccc
-        if [ "X${HA_NUM_SERVERS}X" != "X1X" ]; then
9f5ccc
+        # Fedora 29+ and rhel/centos 8 has PCS-0.10.x
9f5ccc
+        # default is pcs-0.10.x options but check for
9f5ccc
+        # rhel/centos 7 (pcs-0.9.x) and adjust accordingly
9f5ccc
+        if [[ ${ID} =~ {rhel,centos} ]]; then
9f5ccc
+            if [[ ${VERSION_ID} == 7.* ]]; then
9f5ccc
+                PCS9OR10_PCS_CNAME_OPTION="--name"
9f5ccc
+                PCS9OR10_PCS_CLONE_OPTION="--clone"
9f5ccc
+            fi
9f5ccc
+        fi
9f5ccc
+
9f5ccc
+        if [[ "${HA_NUM_SERVERS}X" != "1X" ]]; then
9f5ccc
 
9f5ccc
             determine_service_manager
9f5ccc
 
9f5ccc
-- 
9f5ccc
1.8.3.1
9f5ccc