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