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