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