diff options
| author | Meghana Madhusudhan <mmadhusu@redhat.com> | 2015-03-25 15:11:57 +0530 | 
|---|---|---|
| committer | Kaleb KEITHLEY <kkeithle@redhat.com> | 2015-03-31 07:08:06 -0700 | 
| commit | e6f5ace08ad0a068cb49d3ca1274a27aa031992b (patch) | |
| tree | 140d1df1abc0ddec9251401b9e098c197bb8dcaf | |
| parent | 9c37b68bc15c503a0ad5cc2fb04be7b917496d90 (diff) | |
NFS-Ganesha: Start and stop NFS-Ganesha service in a platform independent way
Check for what binaries are installed at run time,
pick appropriate command and perform the required
action. The service managers supported are systemctl,service
and invoke-rc.d.
Change-Id: I8deef2bfe5a09da5b055fe6176a58452a882fa76
BUG: 1202316
Signed-off-by: Meghana Madhusudhan <mmadhusu@redhat.com>
Reviewed-on: http://review.gluster.org/9991
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: soumya k <skoduri@redhat.com>
Reviewed-by: Kaleb KEITHLEY <kkeithle@redhat.com>
| -rw-r--r-- | xlators/mgmt/glusterd/src/glusterd-ganesha.c | 85 | 
1 files changed, 74 insertions, 11 deletions
diff --git a/xlators/mgmt/glusterd/src/glusterd-ganesha.c b/xlators/mgmt/glusterd/src/glusterd-ganesha.c index d8111afa423..534e332cdee 100644 --- a/xlators/mgmt/glusterd/src/glusterd-ganesha.c +++ b/xlators/mgmt/glusterd/src/glusterd-ganesha.c @@ -9,7 +9,6 @@  */ -  #ifndef _CONFIG_H  #define _CONFIG_H  #include "config.h" @@ -24,6 +23,75 @@  #define MAXBUF 1024  #define DELIM "=\"" +typedef struct service_command { +        char *binary; +        char *service; +        int (*action) (struct service_command *, char *); +} service_command; + +static int +sc_systemctl_action (struct service_command *sc, char *command) +{ +        runner_t        runner   = {0,}; + +        runinit (&runner); +        runner_add_args (&runner, sc->binary, command, sc->service, NULL); +        return runner_run (&runner); +} + +static int +sc_service_action (struct service_command *sc, char *command) +{ +        runner_t      runner = {0,}; + +        runinit (&runner); +        runner_add_args (&runner, sc->binary, sc->service, command, NULL); +        return runner_run (&runner); +} + +static int +manage_service (char *action) +{ +        struct stat stbuf       = {0,}; +        int     i               = 0; +        int     ret             = 0; +        struct service_command sc_list[] = { +                { .binary  = "/usr/bin/systemctl", +                  .service = "nfs-ganesha", +                  .action  = sc_systemctl_action +                }, +                { .binary  = "/sbin/invoke-rc.d", +                  .service = "nfs-ganesha", +                  .action  = sc_service_action +                }, +                { .binary  = "/sbin/service", +                  .service = "nfs-ganesha", +                  .action  = sc_service_action +                }, +                { .binary  = NULL +                } +        }; + +        while (sc_list[i].binary != NULL) { +                ret = stat (sc_list[i].binary, &stbuf); +                if (ret == 0) { +                        gf_log (THIS->name, GF_LOG_DEBUG, +                                "%s found.", sc_list[i].binary); +                        if (strcmp (sc_list[i].binary, "/usr/bin/systemctl") == 0) +                                ret = sc_systemctl_action (&sc_list[i], action); +                        else +                                ret = sc_service_action (&sc_list[i], action); + +                        return ret; +                } +                i++; +        } +        gf_log (THIS->name, GF_LOG_ERROR, +                "Could not %s NFS-Ganesha.Service manager for distro" +                " not recognized.", action); +        return ret; +} +  int  glusterd_check_ganesha_cmd (char *key, char *value, char **errstr, dict_t *dict)  { @@ -407,9 +475,10 @@ stop_ganesha (char **op_errstr)          }          if (check_host_list ()) { -                runinit (&runner); -                runner_add_args (&runner, "service", " nfs-ganesha", "stop", NULL); -                ret =  runner_run (&runner); +                ret = manage_service ("stop"); +                if (ret) +                        gf_asprintf (op_errstr, "NFS-Ganesha service could not" +                                     "be stopped.");          }  out:          return ret; @@ -418,8 +487,6 @@ out:  int  start_ganesha (char **op_errstr)  { - -        runner_t                runner                     = {0,};          int                     ret                        = -1;          char                    key[1024]                  = {0,};          char                    *hostname                  = NULL; @@ -450,11 +517,7 @@ start_ganesha (char **op_errstr)          }          if (check_host_list()) { -                runinit(&runner); -                runner_add_args (&runner, "service", -                                 "nfs-ganesha", "start", NULL); - -                ret =  runner_run (&runner); +                ret = manage_service ("start");                  if (ret) {                          gf_asprintf (op_errstr, "NFS-Ganesha failed to start."                          "Please see log file for details");  | 
