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