74b1de
From 2c1a83920b959a1ec170243d1eec71b1e2c074b0 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
74b1de
Subject: [PATCH 056/124] 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
74b1de
Label: DOWNSTREAM ONLY
74b1de
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>
74b1de
Signed-off-by: Jiffin Tony Thottan <jthottan@redhat.com>
74b1de
Reviewed-on: https://code.engineering.redhat.com/gerrit/167141
74b1de
Reviewed-by: Soumya Koduri <skoduri@redhat.com>
74b1de
Tested-by: RHGS Build Bot <nigelb@redhat.com>
74b1de
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
d1681e
---
74b1de
 extras/ganesha/scripts/ganesha-ha.sh         | 21 +++++++++---------
74b1de
 xlators/mgmt/glusterd/src/glusterd-ganesha.c | 32 +++++++++++-----------------
74b1de
 2 files changed, 23 insertions(+), 30 deletions(-)
d1681e
d1681e
diff --git a/extras/ganesha/scripts/ganesha-ha.sh b/extras/ganesha/scripts/ganesha-ha.sh
74b1de
index 6b011be..4b93f95 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
74b1de
index fac16e6..81f794d 100644
d1681e
--- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c
d1681e
+++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c
74b1de
@@ -122,12 +122,9 @@ sc_service_action(struct service_command *sc, char *command)
d1681e
 static int
74b1de
 manage_service(char *action)
d1681e
 {
74b1de
-    struct stat stbuf = {
74b1de
-        0,
74b1de
-    };
74b1de
     int i = 0;
74b1de
     int ret = 0;
74b1de
-    struct service_command sc_list[] = {{.binary = "/usr/bin/systemctl",
74b1de
+    struct service_command sc_list[] = {{.binary = "/bin/systemctl",
74b1de
                                          .service = "nfs-ganesha",
74b1de
                                          .action = sc_systemctl_action},
74b1de
                                         {.binary = "/sbin/invoke-rc.d",
74b1de
@@ -139,15 +136,10 @@ manage_service(char *action)
74b1de
                                         {.binary = NULL}};
74b1de
 
74b1de
     while (sc_list[i].binary != NULL) {
74b1de
-        ret = sys_stat(sc_list[i].binary, &stbuf);
74b1de
+        ret = sys_access(sc_list[i].binary, X_OK);
74b1de
         if (ret == 0) {
74b1de
             gf_msg_debug(THIS->name, 0, "%s found.", sc_list[i].binary);
74b1de
-            if (strcmp(sc_list[i].binary, "/usr/bin/systemctl") == 0)
74b1de
-                ret = sc_systemctl_action(&sc_list[i], action);
74b1de
-            else
74b1de
-                ret = sc_service_action(&sc_list[i], action);
d1681e
-
74b1de
-            return ret;
74b1de
+            return sc_list[i].action(&sc_list[i], action);
d1681e
         }
74b1de
         i++;
74b1de
     }
74b1de
@@ -449,7 +441,7 @@ manage_export_config(char *volname, char *value, char **op_errstr)
74b1de
 
74b1de
     GF_ASSERT(volname);
74b1de
     runinit(&runner);
74b1de
-    runner_add_args(&runner, "sh", GANESHA_PREFIX "/create-export-ganesha.sh",
74b1de
+    runner_add_args(&runner, GANESHA_PREFIX "/create-export-ganesha.sh",
74b1de
                     CONFDIR, value, volname, NULL);
74b1de
     ret = runner_run(&runner);
74b1de
 
74b1de
@@ -558,8 +550,8 @@ ganesha_manage_export(dict_t *dict, char *value, char **op_errstr)
74b1de
     }
74b1de
 
74b1de
     if (check_host_list()) {
74b1de
-        runner_add_args(&runner, "sh", GANESHA_PREFIX "/dbus-send.sh", CONFDIR,
74b1de
-                        value, volname, NULL);
74b1de
+        runner_add_args(&runner, GANESHA_PREFIX "/dbus-send.sh", CONFDIR, value,
74b1de
+                        volname, NULL);
74b1de
         ret = runner_run(&runner);
74b1de
         if (ret) {
74b1de
             gf_asprintf(op_errstr,
74b1de
@@ -610,8 +602,8 @@ tear_down_cluster(gf_boolean_t run_teardown)
74b1de
 
74b1de
     if (run_teardown) {
74b1de
         runinit(&runner);
74b1de
-        runner_add_args(&runner, "sh", GANESHA_PREFIX "/ganesha-ha.sh",
74b1de
-                        "teardown", CONFDIR, NULL);
74b1de
+        runner_add_args(&runner, GANESHA_PREFIX "/ganesha-ha.sh", "teardown",
74b1de
+                        CONFDIR, NULL);
74b1de
         ret = runner_run(&runner);
74b1de
         /* *
74b1de
          * Remove all the entries in CONFDIR expect ganesha.conf and
74b1de
@@ -685,7 +677,7 @@ setup_cluster(gf_boolean_t run_setup)
74b1de
 
74b1de
     if (run_setup) {
74b1de
         runinit(&runner);
74b1de
-        runner_add_args(&runner, "sh", GANESHA_PREFIX "/ganesha-ha.sh", "setup",
74b1de
+        runner_add_args(&runner, GANESHA_PREFIX "/ganesha-ha.sh", "setup",
74b1de
                         CONFDIR, NULL);
74b1de
         ret = runner_run(&runner);
74b1de
     }
74b1de
@@ -714,7 +706,7 @@ teardown(gf_boolean_t run_teardown, char **op_errstr)
74b1de
     }
74b1de
 
74b1de
     runinit(&runner);
74b1de
-    runner_add_args(&runner, "sh", GANESHA_PREFIX "/ganesha-ha.sh", "cleanup",
74b1de
+    runner_add_args(&runner, GANESHA_PREFIX "/ganesha-ha.sh", "cleanup",
74b1de
                     CONFDIR, NULL);
74b1de
     ret = runner_run(&runner);
74b1de
     if (ret)
74b1de
@@ -759,7 +751,7 @@ stop_ganesha(char **op_errstr)
74b1de
     };
74b1de
 
74b1de
     runinit(&runner);
74b1de
-    runner_add_args(&runner, "sh", GANESHA_PREFIX "/ganesha-ha.sh",
74b1de
+    runner_add_args(&runner, GANESHA_PREFIX "/ganesha-ha.sh",
74b1de
                     "--setup-ganesha-conf-files", CONFDIR, "no", NULL);
74b1de
     ret = runner_run(&runner);
74b1de
     if (ret) {
74b1de
@@ -828,7 +820,7 @@ start_ganesha(char **op_errstr)
74b1de
 
74b1de
     if (check_host_list()) {
74b1de
         runinit(&runner);
74b1de
-        runner_add_args(&runner, "sh", GANESHA_PREFIX "/ganesha-ha.sh",
74b1de
+        runner_add_args(&runner, GANESHA_PREFIX "/ganesha-ha.sh",
74b1de
                         "--setup-ganesha-conf-files", CONFDIR, "yes", NULL);
d1681e
         ret = runner_run(&runner);
d1681e
         if (ret) {
d1681e
-- 
d1681e
1.8.3.1
d1681e