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