From a4d7f6c1999f2c7837aaa674177edca9298d1c00 Mon Sep 17 00:00:00 2001
From: "Kaleb S. KEITHLEY" <kkeithle@redhat.com>
Date: Fri, 7 Apr 2017 09:09:29 -0400
Subject: [PATCH 52/74] common-ha: fixes for Debian-based systems
1) Debian-based systems don't have /usr/libexec/... and there is
a hard-coded invocation of /usr/libexec/ganesha/ganesha-ha.sh within
ganesha-ha.sh itself.
Fix: save $0 and use it instead for further invocations of self.
2) default shell is /bin/dash (not /bin/bash). Various runner_run()
invocations for ganesha used what amounts to
exec("sh /usr/$libexec/ganesha/ganesha-ha.sh ...);
which executes the script using the default shell, but there are
some bash-specific idioms that don't work if the shell is dash.
Fix: change to exec("/usr/$libexec/ganesha/ganesha-ha.sh ...); so that
the shebang forces the use of /bin/bash
3) Fedora and RHEL7 have merged /bin/ and /usr/bin, /bin is a symlink
to /usr/bin. Debian-based systems are not merged, and systemd systems
have /bin/systemctl. The logic to find .../bin/systemctl is backwards.
If the logic looks for /usr/bin/systemctl it will not find it on
Debian-based systems; if it looks for /bin/systemctl it will find it
on Fedora and RHEL by virtue of the symlink. (RHEL6 and others will
find their respective init regardless.)
Fix: change the logic to look for /bin/systemctl instead.
4) The logic for deciding to run systemctl (or not) is a bit silly.
Fix: simply invoke the found method via the function pointer in the
table.
Change-Id: I33681b296a73aebb078bda6ac0d3a1d3b9770a21
Signed-off-by: Kaleb S. KEITHLEY <kkeithle@redhat.com>
Reviewed-on: https://review.gluster.org/17013
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: jiffin tony Thottan <jthottan@redhat.com>
---
extras/ganesha/scripts/ganesha-ha.sh | 21 ++++++-------
xlators/mgmt/glusterd/src/glusterd-ganesha.c | 44 +++++++++++++---------------
2 files changed, 32 insertions(+), 33 deletions(-)
diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
index e4135ba..d4844e4 100644
--- a/extras/ganesha/scripts/ganesha-ha.sh
+++ b/extras/ganesha/scripts/ganesha-ha.sh
@@ -20,6 +20,7 @@
# ensure that the NFS GRACE DBUS signal is sent after the VIP moves to
# the new host.
+GANESHA_HA_SH=$(realpath $0)
HA_NUM_SERVERS=0
HA_SERVERS=""
HA_VOL_NAME="gluster_shared_storage"
@@ -68,9 +69,9 @@ function find_rhel7_conf
done
}
-if [ -z $CONFFILE ]
+if [ -z ${CONFFILE} ]
then
- find_rhel7_conf $OPTIONS
+ find_rhel7_conf ${OPTIONS}
fi
@@ -90,9 +91,9 @@ usage() {
determine_service_manager () {
- if [ -e "/usr/bin/systemctl" ];
+ if [ -e "/bin/systemctl" ];
then
- SERVICE_MAN="/usr/bin/systemctl"
+ SERVICE_MAN="/bin/systemctl"
elif [ -e "/sbin/invoke-rc.d" ];
then
SERVICE_MAN="/sbin/invoke-rc.d"
@@ -100,7 +101,7 @@ determine_service_manager () {
then
SERVICE_MAN="/sbin/service"
fi
- if [ "$SERVICE_MAN" == "DISTRO_NOT_FOUND" ]
+ if [ "${SERVICE_MAN}" == "DISTRO_NOT_FOUND" ]
then
echo "Service manager not recognized, exiting"
exit 1
@@ -113,21 +114,21 @@ manage_service ()
local new_node=${2}
local option=
- if [ "$action" == "start" ]; then
+ if [ "${action}" == "start" ]; then
option="yes"
else
option="no"
fi
ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
-${SECRET_PEM} root@${new_node} "/usr/libexec/ganesha/ganesha-ha.sh --setup-ganesha-conf-files $HA_CONFDIR $option"
+${SECRET_PEM} root@${new_node} "${GANESHA_HA_SH} --setup-ganesha-conf-files $HA_CONFDIR $option"
- if [ "$SERVICE_MAN" == "/usr/bin/systemctl" ]
+ if [ "${SERVICE_MAN}" == "/bin/systemctl" ]
then
ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
-${SECRET_PEM} root@${new_node} "$SERVICE_MAN ${action} nfs-ganesha"
+${SECRET_PEM} root@${new_node} "${SERVICE_MAN} ${action} nfs-ganesha"
else
ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no -i \
-${SECRET_PEM} root@${new_node} "$SERVICE_MAN nfs-ganesha ${action}"
+${SECRET_PEM} root@${new_node} "${SERVICE_MAN} nfs-ganesha ${action}"
fi
}
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
index 4346bad..c16dd72 100644
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
@@ -119,11 +119,10 @@ sc_service_action (struct service_command *sc, char *command)
static int
manage_service (char *action)
{
- struct stat stbuf = {0,};
int i = 0;
int ret = 0;
struct service_command sc_list[] = {
- { .binary = "/usr/bin/systemctl",
+ { .binary = "/bin/systemctl",
.service = "nfs-ganesha",
.action = sc_systemctl_action
},
@@ -140,16 +139,11 @@ manage_service (char *action)
};
while (sc_list[i].binary != NULL) {
- ret = sys_stat (sc_list[i].binary, &stbuf);
+ ret = sys_access (sc_list[i].binary, X_OK);
if (ret == 0) {
gf_msg_debug (THIS->name, 0,
- "%s found.", sc_list[i].binary);
- if (strcmp (sc_list[i].binary, "/usr/bin/systemctl") == 0)
- ret = sc_systemctl_action (&sc_list[i], action);
- else
- ret = sc_service_action (&sc_list[i], action);
-
- return ret;
+ "%s found.", sc_list[i].binary);
+ return sc_list[i].action (&sc_list[i], action);
}
i++;
}
@@ -465,9 +459,9 @@ manage_export_config (char *volname, char *value, char **op_errstr)
GF_ASSERT(volname);
runinit (&runner);
- runner_add_args (&runner, "sh",
- GANESHA_PREFIX"/create-export-ganesha.sh",
- CONFDIR, value, volname, NULL);
+ runner_add_args (&runner,
+ GANESHA_PREFIX"/create-export-ganesha.sh",
+ CONFDIR, value, volname, NULL);
ret = runner_run(&runner);
if (ret)
@@ -570,8 +564,9 @@ ganesha_manage_export (dict_t *dict, char *value, char **op_errstr)
}
if (check_host_list()) {
- runner_add_args (&runner, "sh", GANESHA_PREFIX"/dbus-send.sh",
- CONFDIR, value, volname, NULL);
+ runner_add_args (&runner,
+ GANESHA_PREFIX"/dbus-send.sh",
+ CONFDIR, value, volname, NULL);
ret = runner_run (&runner);
if (ret) {
gf_asprintf(op_errstr, "Dynamic export"
@@ -610,9 +605,9 @@ tear_down_cluster(gf_boolean_t run_teardown)
if (run_teardown) {
runinit (&runner);
- runner_add_args (&runner, "sh",
- GANESHA_PREFIX"/ganesha-ha.sh", "teardown",
- CONFDIR, NULL);
+ runner_add_args (&runner,
+ GANESHA_PREFIX"/ganesha-ha.sh", "teardown",
+ CONFDIR, NULL);
ret = runner_run(&runner);
/* *
* Remove all the entries in CONFDIR expect ganesha.conf and
@@ -675,7 +670,8 @@ setup_cluster(gf_boolean_t run_setup)
if (run_setup) {
runinit (&runner);
- runner_add_args (&runner, "sh", GANESHA_PREFIX"/ganesha-ha.sh",
+ runner_add_args (&runner,
+ GANESHA_PREFIX"/ganesha-ha.sh",
"setup", CONFDIR, NULL);
ret = runner_run (&runner);
}
@@ -702,8 +698,9 @@ teardown (gf_boolean_t run_teardown, char **op_errstr)
}
runinit (&runner);
- runner_add_args (&runner, "sh", GANESHA_PREFIX"/ganesha-ha.sh",
- "cleanup", CONFDIR, NULL);
+ runner_add_args (&runner,
+ GANESHA_PREFIX"/ganesha-ha.sh",
+ "cleanup", CONFDIR, NULL);
ret = runner_run (&runner);
if (ret)
gf_msg_debug (THIS->name, 0, "Could not clean up"
@@ -747,7 +744,8 @@ stop_ganesha (char **op_errstr) {
runner_t runner = {0,};
runinit (&runner);
- runner_add_args (&runner, "sh", GANESHA_PREFIX"/ganesha-ha.sh",
+ runner_add_args (&runner,
+ GANESHA_PREFIX"/ganesha-ha.sh",
"--setup-ganesha-conf-files", CONFDIR, "no", NULL);
ret = runner_run (&runner);
if (ret) {
@@ -810,7 +808,7 @@ start_ganesha (char **op_errstr)
if (check_host_list()) {
runinit (&runner);
- runner_add_args (&runner, "sh", GANESHA_PREFIX"/ganesha-ha.sh",
+ runner_add_args (&runner, GANESHA_PREFIX"/ganesha-ha.sh",
"--setup-ganesha-conf-files", CONFDIR, "yes",
NULL);
ret = runner_run (&runner);
--
1.8.3.1