From a7f114c31d475e4f748b956d1f28da9bd47a4e0c Mon Sep 17 00:00:00 2001
From: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Date: Thu, 11 Jun 2015 16:28:06 -0400
Subject: [PATCH 73/73] common-ha: handle long node names and node names with '-' and '.' in them
sourcing the /etc/ganesha/ganesha-ha.conf file seemed like a simple and
elegant solution for reading config params, but bash variable names do
not allow '-' and '.' in them. also fix incorrect path to shared volume
Change-Id: I7d05ac04034c4d829916ff06472dbe9f86a10525
BUG: 1225507
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: https://code.engineering.redhat.com/gerrit/50591
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Tested-by: Niels de Vos <ndevos@redhat.com>
---
extras/ganesha/config/ganesha-ha.conf.sample | 26 +++++++---
extras/ganesha/ocf/ganesha_nfsd | 4 +-
extras/ganesha/scripts/ganesha-ha.sh | 70 +++++++++++++++-----------
3 files changed, 60 insertions(+), 40 deletions(-)
diff --git a/extras/ganesha/config/ganesha-ha.conf.sample b/extras/ganesha/config/ganesha-ha.conf.sample
index f8536d3..24054ab 100644
--- a/extras/ganesha/config/ganesha-ha.conf.sample
+++ b/extras/ganesha/config/ganesha-ha.conf.sample
@@ -1,12 +1,22 @@
# Name of the HA cluster created.
+# must be unique within the subnet
HA_NAME="ganesha-ha-360"
-# The server from which you intend to mount
-# the shared volume.
+#
+# The gluster server from which to mount the shared data volume.
HA_VOL_SERVER="server1"
-# The subset of nodes of the Gluster Trusted Pool
-# that forms the ganesha HA cluster. IP/Hostname
-# is specified.
+#
+# N.B. you may use short names or long names; you may not use IP addrs.
+# Once you select one, stay with it as it will be mildly unpleasant to
+# clean up if you switch later on. Ensure that all names - short and/or
+# long - are in DNS or /etc/hosts on all machines in the cluster.
+#
+# The subset of nodes of the Gluster Trusted Pool that form the ganesha
+# HA cluster. Hostname is specified.
HA_CLUSTER_NODES="server1,server2,..."
-# Virtual IPs of each of the nodes specified above.
-VIP_server1="10.x.x.x"
-VIP_server2="10.x.x.x"
+#HA_CLUSTER_NODES="server1.lab.redhat.com,server2.lab.redhat.com,..."
+#
+# Virtual IPs for each of the nodes specified above.
+VIP_server1="10.0.2.1"
+VIP_server2="10.0.2.2"
+#VIP_server1.lab.redhat.com="10.0.2.1"
+#VIP_server2.lab.redhat.com="10.0.2.2"
diff --git a/extras/ganesha/ocf/ganesha_nfsd b/extras/ganesha/ocf/ganesha_nfsd
index d69b9f4..e064183 100644
--- a/extras/ganesha/ocf/ganesha_nfsd
+++ b/extras/ganesha/ocf/ganesha_nfsd
@@ -105,9 +105,9 @@ ganesha_nfsd_stop()
if [ -d /var/lib/nfs ]; then
mv /var/lib/nfs /var/lib/nfs.backup
- ln -s $OCF_RESKEY_ha_vol_mnt/${long_host}/nfs /var/lib/nfs
+ ln -s $OCF_RESKEY_ha_vol_mnt/nfs-ganesha/${long_host}/nfs /var/lib/nfs
if [ $? -ne 0 ]; then
- logger "warning: ln -s $OCF_RESKEY_ha_vol_mnt/${long_host}/nfs /var/lib/nfs failed"
+ logger "warning: ln -s $OCF_RESKEY_ha_vol_mnt/nfs-ganesha/${long_host}/nfs /var/lib/nfs failed"
fi
fi
diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
index 79a99c4..bd344fa 100755
--- a/extras/ganesha/scripts/ganesha-ha.sh
+++ b/extras/ganesha/scripts/ganesha-ha.sh
@@ -363,10 +363,7 @@ setup_create_resources()
while [[ ${1} ]]; do
- # ipaddr=$(grep ^${1} ${HA_CONFIG_FILE} | cut -d = -f 2)
- ipaddrx="VIP_${1//-/_}"
-
- ipaddr=${!ipaddrx}
+ ipaddr=$(grep "^VIP_${1}=" ${HA_CONFDIR}/ganesha-ha.conf | cut -d = -f 2)
pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} cidr_netmask=32 op monitor interval=15s
if [ $? -ne 0 ]; then
@@ -460,9 +457,7 @@ recreate_resources()
local cibfile=${1}; shift
while [[ ${1} ]]; do
- ipaddrx="VIP_${1//-/_}"
-
- ipaddr=${!ipaddrx}
+ ipaddr=$(grep "VIP_${1}=" ${HA_CONFDIR}/ganesha-ha.conf | cut -d = -f 2)
pcs -f ${cibfile} resource create ${1}-cluster_ip-1 ocf:heartbeat:IPaddr ip=${ipaddr} cidr_netmask=32 op monitor interval=15s
if [ $? -ne 0 ]; then
@@ -679,43 +674,52 @@ setup_state_volume()
local longname=""
local shortname=""
local dname=""
+ local dirname=""
longname=$(hostname)
dname=${longname#$(hostname -s)}
while [[ ${1} ]]; do
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname} ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}
+
+ if [[ ${1} == *${dname} ]]; then
+ dirname=${1}
+ else
+ dirname=${1}${dname}
+ fi
+
+
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname} ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}
fi
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs
fi
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs/ganesha ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs/ganesha
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha
fi
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd
fi
- touch ${mnt}/nfs-ganesha/${1}${dname}/nfs/state
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs/ganesha/v4recov ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs/ganesha/v4recov
+ touch ${mnt}/nfs-ganesha/${dirname}/nfs/state
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4recov
fi
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs/ganesha/v4old ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs/ganesha/v4old
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/v4old
fi
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd/sm ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd/sm
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm
fi
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd/sm.bak ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd/sm.bak
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/sm.bak
fi
- if [ ! -d ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd/state ]; then
- mkdir ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd/state
+ if [ ! -d ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state ]; then
+ mkdir ${mnt}/nfs-ganesha/${dirname}/nfs/statd/state
fi
for server in ${HA_SERVERS} ; do
- if [ ${server} != ${1}${dname} ]; then
- ln -s ${mnt}/nfs-ganesha/${server}/nfs/ganesha ${mnt}/nfs-ganesha/${1}${dname}/nfs/ganesha/${server}
- ln -s ${mnt}/nfs-ganesha/${server}/nfs/statd ${mnt}/nfs-ganesha/${1}${dname}/nfs/statd/${server}
+ if [ ${server} != ${dirname} ]; then
+ ln -s ${mnt}/nfs-ganesha/${server}/nfs/ganesha ${mnt}/nfs-ganesha/${dirname}/nfs/ganesha/${server}
+ ln -s ${mnt}/nfs-ganesha/${server}/nfs/statd ${mnt}/nfs-ganesha/${dirname}/nfs/statd/${server}
fi
done
shift
@@ -728,10 +732,16 @@ main()
{
local cmd=${1}; shift
HA_CONFDIR=${1}; shift
+ local ha_conf=${HA_CONFDIR}/ganesha-ha.conf
local node=""
local vip=""
- . ${HA_CONFDIR}/ganesha-ha.conf
+ ha_name=$(grep ^HA_NAME= ${ha_conf} | cut -d = -f 2)
+ HA_NAME=${ha_name//\"/}
+ ha_vol_server=$(grep ^HA_VOL_SERVER= ${ha_conf} | cut -d = -f 2)
+ HA_VOL_SERVER=${ha_vol_server//\"/}
+ ha_cluster_nodes=$(grep ^HA_CLUSTER_NODES= ${ha_conf} | cut -d = -f 2)
+ HA_CLUSTER_NODES=${ha_cluster_nodes//\"/}
if [ -e /etc/os-release ]; then
RHEL6_PCS_CNAME_OPTION=""
--
1.7.1