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