glusterfs

Форк
0
/
glusterd-proc-mgmt.c 
154 строки · 4.0 Кб
1
/*
2
   Copyright (c) 2014 Red Hat, Inc. <http://www.redhat.com>
3
   This file is part of GlusterFS.
4

5
   This file is licensed to you under your choice of the GNU Lesser
6
   General Public License, version 3 or any later version (LGPLv3 or
7
   later), or the GNU General Public License, version 2 (GPLv2), in all
8
   cases as published by the Free Software Foundation.
9
*/
10

11
#include <stdio.h>
12
#include <limits.h>
13
#include <signal.h>
14

15
#include "glusterd-utils.h"
16
#include <glusterfs/common-utils.h>
17
#include <glusterfs/logging.h>
18
#include "glusterd-messages.h"
19
#include "glusterd-proc-mgmt.h"
20

21
int
22
glusterd_proc_init(glusterd_proc_t *proc, char *name, char *pidfile,
23
                   char *logdir, char *logfile, char *volfile, char *volfileid,
24
                   char *volfileserver)
25
{
26
    int ret = -1;
27

28
    ret = snprintf(proc->name, sizeof(proc->name), "%s", name);
29
    if (ret < 0)
30
        goto out;
31

32
    ret = snprintf(proc->pidfile, sizeof(proc->pidfile), "%s", pidfile);
33
    if (ret < 0)
34
        goto out;
35

36
    ret = snprintf(proc->logdir, sizeof(proc->logdir), "%s", logdir);
37
    if (ret < 0)
38
        goto out;
39

40
    ret = snprintf(proc->logfile, sizeof(proc->logfile), "%s", logfile);
41
    if (ret < 0)
42
        goto out;
43

44
    ret = snprintf(proc->volfile, sizeof(proc->volfile), "%s", volfile);
45
    if (ret < 0)
46
        goto out;
47

48
    ret = snprintf(proc->volfileid, sizeof(proc->volfileid), "%s", volfileid);
49
    if (ret < 0)
50
        goto out;
51

52
    ret = snprintf(proc->volfileserver, sizeof(proc->volfileserver), "%s",
53
                   volfileserver);
54
    if (ret < 0)
55
        goto out;
56

57
out:
58
    if (ret > 0)
59
        ret = 0;
60

61
    return ret;
62
}
63

64
int
65
glusterd_proc_stop(glusterd_proc_t *proc, int sig, int flags)
66
{
67
    /* NB: Copy-paste code from glusterd_service_stop, the source may be
68
     * removed once all daemon management use proc */
69

70
    int32_t ret = -1;
71
    pid_t pid = -1;
72
    xlator_t *this = THIS;
73
    glusterd_conf_t *conf = NULL;
74
    int tries;
75

76
    conf = this->private;
77
    GF_ASSERT(conf);
78

79
    if (!gf_is_service_running(proc->pidfile, &pid)) {
80
        ret = 0;
81
        gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_ALREADY_STOPPED,
82
               "%s already stopped", proc->name);
83
        goto out;
84
    }
85
    gf_msg(this->name, GF_LOG_INFO, 0, GD_MSG_SVC_STOP_SUCCESS,
86
           "Stopping %s daemon running in pid: "
87
           "%d",
88
           proc->name, pid);
89

90
    ret = kill(pid, sig);
91
    if (ret) {
92
        switch (errno) {
93
            case ESRCH:
94
                gf_msg_debug(this->name, 0,
95
                             "%s is already "
96
                             "stopped",
97
                             proc->name);
98
                ret = 0;
99
                goto out;
100
            default:
101
                gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_SVC_KILL_FAIL,
102
                       "Unable to kill %s "
103
                       "service, reason:%s",
104
                       proc->name, strerror(errno));
105
        }
106
    } else {
107
        gf_unlink(proc->pidfile);
108
    }
109
    if (flags != PROC_STOP_FORCE)
110
        goto out;
111

112
    for (tries = 10; tries > 0; --tries) {
113
        if (gf_is_service_running(proc->pidfile, &pid)) {
114
            synclock_unlock(&conf->big_lock);
115
            synctask_usleep(100000);
116
            synclock_lock(&conf->big_lock);
117
        } else {
118
            ret = 0;
119
            goto out;
120
        }
121
    }
122

123
    if (gf_is_service_running(proc->pidfile, &pid)) {
124
        ret = kill(pid, SIGKILL);
125
        if (ret) {
126
            gf_msg(this->name, GF_LOG_ERROR, errno, GD_MSG_PID_KILL_FAIL,
127
                   "Unable to kill pid:%d, "
128
                   "reason:%s",
129
                   pid, strerror(errno));
130
            goto out;
131
        }
132
        gf_unlink(proc->pidfile);
133
    }
134

135
    ret = 0;
136
out:
137
    return ret;
138
}
139

140
int
141
glusterd_proc_get_pid(glusterd_proc_t *proc)
142
{
143
    int pid = -1;
144
    (void)gf_is_service_running(proc->pidfile, &pid);
145
    return pid;
146
}
147

148
int
149
glusterd_proc_is_running(glusterd_proc_t *proc)
150
{
151
    int pid = -1;
152

153
    return gf_is_service_running(proc->pidfile, &pid);
154
}
155

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.