glusterfs

Форк
0
/
cluster.rc 
227 строк · 5.8 Кб
1
#!/bin/bash
2

3
CLUSTER_PFX="127.1.1"; # ".x" for each glusterd
4
CLUSTER_COUNT=1; # Just initial definition
5

6
function launch_cluster() {
7
    local count=$1;
8

9
    CLUSTER_COUNT=$count;
10

11
    define_backends $count;
12
    define_hosts $count;
13
    define_glusterds $count $2;
14
    define_clis $count $3;
15

16
    start_glusterds;
17
}
18

19

20
function define_backends() {
21
    local b;
22

23
    for i in `seq 1 $count`; do
24
        eval "B$i=$B0/$i";
25
    done
26

27
    for i in `seq 1 $count`; do
28
        b="B$i";
29
        mkdir -p ${!b}/glusterd;
30
        mkdir -p ${!b}/run;
31
    done
32
}
33

34

35
function define_glusterds() {
36
    local count=$1;
37
    local h;
38
    local b;
39
    local wopt;
40
    local bopt;
41
    local popt;
42

43
    for i in `seq 1 $count`; do
44
        b="B$i";
45
        h="H$i";
46
        wopt="management.working-directory=${!b}/glusterd";
47
        ropt="management.run-directory=${!b}/run/gluster";
48
        bopt="management.transport.socket.bind-address=${!h}";
49
        popt="--pid-file=${!b}/glusterd.pid";
50
        sopt="management.glusterd-sockfile=${!b}/glusterd/gd.sock"
51
        #Get the logdir
52
        logdir=`gluster --print-logdir`
53
        clopt="management.logging-directory=${logdir}/$i";
54
        #Fetch the testcases name and prefix the glusterd log with it
55
        logfile=`echo ${0##*/}`_glusterd$i.log
56
        lopt="--log-file=$logdir/$i/$logfile"
57
        if [ "$2" == "-LDEBUG" ]; then
58
            eval "glusterd_$i='glusterd -LDEBUG --xlator-option $wopt --xlator-option $bopt --xlator-option $ropt --xlator-option $sopt --xlator-option $clopt $lopt $popt'";
59
            eval "glusterd$i='glusterd -LDEBUG --xlator-option $wopt --xlator-option $bopt --xlator-option $ropt --xlator-option $sopt --xlator-option $clopt $lopt $popt'";
60
        else
61
            eval "glusterd_$i='glusterd --xlator-option $wopt --xlator-option $bopt --xlator-option $ropt --xlator-option $sopt --xlator-option $clopt $lopt $popt'";
62
            eval "glusterd$i='glusterd --xlator-option $wopt --xlator-option $bopt --xlator-option $ropt --xlator-option $sopt --xlator-option $clopt $lopt $popt'";
63
        fi
64
    done
65
}
66

67
function start_glusterd() {
68
    local g
69
    local index=$1
70

71
    g="glusterd_${index}"
72
    ${!g}
73
}
74

75
function start_glusterds() {
76
    for i in `seq 1 $CLUSTER_COUNT`; do
77
        start_glusterd $i
78
    done
79
}
80

81

82
function kill_glusterd() {
83
    local index=$1;
84
    local b;
85
    local pidfile;
86

87
    b="B$index";
88
    pidfile="${!b}/glusterd.pid";
89

90
    kill `cat $pidfile`;
91
}
92

93
function restart_glusterd() {
94
    local index=$1
95
    local b
96
    local pidfile
97
    local g
98

99
    b="B$index"
100
    pidfile="${!b}/glusterd.pid"
101

102
    kill `cat $pidfile`
103

104
    g="glusterd_${index}"
105
    ${!g}
106
}
107

108
function kill_node() {
109
    local index=$1;
110
    local h;
111

112
    h="H$index";
113

114
    terminate_pids $(ps -ef | grep gluster | grep ${!h} | awk '{print $2}')
115
    find $B0/$index/glusterd/vols -name '*.pid' | xargs rm -f
116
}
117

118

119
function define_hosts() {
120
    local count=$1;
121

122
    for i in `seq 1 $count`; do
123
        eval "H_$i=${CLUSTER_PFX}.$i"
124
        eval "H$i=${CLUSTER_PFX}.$i";
125
        case $OSTYPE in
126
        NetBSD)
127
                ifconfig lo0 alias ${CLUSTER_PFX}.$i 2>/dev/null
128
                ;;
129
        *)
130
                ;;
131
        esac
132
    done
133
}
134

135

136
function define_clis() {
137
    local count=$1;
138
    local h;
139

140
    for i in `seq 1 $count`; do
141
        b="B$i";
142
        #get the logdir
143
        logdir=`gluster --print-logdir`
144
        #Fetch the testcases name and prefix the cli log with it
145
        logfile=`echo ${0##*/}`_cli$i.log
146
        lopt="--log-file=$logdir/$logfile"
147
        logfile1=`echo ${0##*/}`_cli_$i.log
148
        lopt1="--log-file=$logdir/$logfile1"
149

150

151
        if [ "$2" == "-NO_FORCE" ]; then
152
                eval "CLI_$i='$CLI_NO_FORCE --glusterd-sock=${!b}/glusterd/gd.sock $lopt'";
153
                eval "CLI$i='$CLI_NO_FORCE --glusterd-sock=${!b}/glusterd/gd.sock $lopt1'";
154
        else
155
                eval "CLI_$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock $lopt'";
156
                eval "CLI$i='$CLI --glusterd-sock=${!b}/glusterd/gd.sock $lopt1'";
157
        fi
158
    done
159
}
160

161
function peer_count() {
162
    $CLI_1 peer status | grep 'Peer in Cluster (Connected)' | wc -l
163
}
164

165
function attempt_replace_brick {
166
    local cli_no=$1
167
    local vol=$2;
168
    local src_brick=$3;
169
    local dst_brick=$4;
170

171
    eval \$CLI_$cli_no volume replace-brick $vol $src_brick $dst_brick commit force;
172
    echo $?
173
}
174

175
function cluster_rebalance_status_field {
176
        #The rebalance status can be up to 3 words, (e.g.:'fix-layout in progress'), hence the awk-print $7 thru $9.
177
        #But if the status is less than 3 words, it also prints the next field i.e the run_time_in_secs.(e.g.:'completed 3.00').
178
        #So we trim the numbers out with  `tr`. Finally remove the trailing white spaces with sed. What we get is one of the
179
        #strings in the 'cli_vol_task_status_str' char array of cli-rpc-ops.c
180

181
        eval  \$CLI_$1 volume rebalance $2 status | awk '{print $7,$8,$9}' |sed -n 3p |tr -d '[^0-9+\.]'|sed 's/ *$//g'
182
}
183

184
function cluster_volinfo_field()
185
{
186
    local vol=$2;
187
    local field=$3;
188
    eval  \$CLI_$1  volume info $vol | grep "^$field: " | sed 's/.*: //';
189
}
190

191
function volinfo_field_1()
192
{
193
    local vol=$1;
194
    local field=$2;
195

196
    $CLI_1 volume info $vol | grep "^$field: " | sed 's/.*: //';
197
}
198

199
function volinfo_field_2()
200
{
201
    local vol=$1;
202
    local field=$2;
203

204
    $CLI_2 volume info $vol | grep "^$field: " | sed 's/.*: //';
205
}
206

207
function volume_exists_1() {
208
        $CLI_1 volume info $1 > /dev/null 2>&1
209
        if [ $? -eq 0 ]; then
210
                echo "Y"
211
        else
212
                echo "N"
213
        fi
214
}
215

216
function cluster_brick_up_status {
217
        local vol=$2
218
        local host=$3
219
        local brick=$4
220
        eval \$CLI_$1 volume status $vol $host:$brick --xml | sed -ne 's/.*<status>\([01]\)<\/status>/\1/p'
221
}
222

223
function cluster_remove_brick_status_completed_field {
224
        local vol=$1
225
        local brick_list=$2
226
        $CLI_1 volume remove-brick $vol $brick_list status | awk '{print $7}' | sed -n 3p
227
}
228

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

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

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

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