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