-
Notifications
You must be signed in to change notification settings - Fork 2
/
bfm_ctl.sh
261 lines (211 loc) · 7.21 KB
/
bfm_ctl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
if [ ! -z $1 ] && [ $1 == "-h" ]; then
echo "-h help"
echo "-u username"
echo "-p password"
echo "-status show cluster status"
echo "-pause cluster check pause"
echo "-resume cluster check resume"
echo "-watchMode [A|M] set watch strategy A:availability, M:manual"
echo "-switchOver 192.168.1.22:5432 switch to selected slave"
echo "-reinit 192.168.1.22:5432 re-initialize selected slave with pg_rewind or pg_basebackup"
echo "-encrypt clearString encrpyt the clear string for use encrypted bfm password function"
fi
if [ ! -z $1 ] && [ ! -z $2 ] && [ $1 == "-u" ]; then
export clsUser=$2
fi
if [ ! -z $1 ] && [ ! -z $2 ] && [ $1 == "-p" ]; then
export clsPwd=$2
fi
if [ ! -z $1 ] && [ $1 == "-status" ]; then
export clsCommand="status"
fi
if [ ! -z $1 ] && [ $1 == "-pause" ]; then
export clsCommand="pause"
fi
if [ ! -z $1 ] && [ $1 == "-resume" ]; then
export clsCommand="resume"
fi
if [ ! -z $1 ] && [ $1 == "-mailPause" ]; then
export clsCommand="mail-pause"
fi
if [ ! -z $1 ] && [ $1 == "-mailResume" ]; then
export clsCommand="mail-resume"
fi
if [ ! -z $1 ] && [ ! -z $2 ] && [ $1 == "-switchOver" ]; then
export clsCommand="switchOver"
export targetSlave=$2
fi
if [ ! -z $1 ] && [ ! -z $2 ] && [ $1 == "-watchMode" ]; then
export clsCommand="strategy"
export clsStrategy=$2
fi
if [ ! -z $1 ] && [ ! -z $2 ] && [ $1 == "-encrypt" ]; then
export clsCommand="encrypt"
export clearStr=$2
fi
if [ ! -z $2 ] && [ ! -z $3 ] && [ $2 == "-u" ]; then
export clsUser=$3
fi
if [ ! -z $2 ] && [ ! -z $3 ] && [ $2 == "-p" ]; then
export clsPwd=$3
fi
if [ ! -z $2 ] && [ $2 == "-status" ]; then
export clsCommand="status"
fi
if [ ! -z $2 ] && [ $2 == "-pause" ]; then
export clsCommand="pause"
fi
if [ ! -z $2 ] && [ $2 == "-resume" ]; then
export clsCommand="resume"
fi
if [ ! -z $2 ] && [ $2 == "-mailPause" ]; then
export clsCommand="mail-pause"
fi
if [ ! -z $2 ] && [ $2 == "-mailResume" ]; then
export clsCommand="mail-resume"
fi
if [ ! -z $2 ] && [ ! -z $3 ] && [ $2 == "-switchOver" ]; then
export clsCommand="switchOver"
export targetSlave=$3
fi
if [ ! -z $2 ] && [ ! -z $3 ] && [ $2 == "-watchMode" ]; then
export clsCommand="strategy"
export clsStrategy=$3
fi
if [ ! -z $2 ] && [ ! -z $3 ] && [ $2 == "-encrypt" ]; then
export clsCommand="encrypt"
export clearStr=$3
fi
if [ ! -z $3 ] && [ ! -z $4 ] &&[ $3 == "-u" ]; then
export clsUser=$4
fi
if [ ! -z $3 ] && [ ! -z $4 ] && [ $3 == "-p" ]; then
export clsPwd=$4
fi
if [ ! -z $3 ] && [ $3 == "-status" ]; then
export clsCommand="status"
fi
if [ ! -z $3 ] && [ $3 == "-pause" ]; then
export clsCommand="pause"
fi
if [ ! -z $3 ] && [ $3 == "-resume" ]; then
export clsCommand="resume"
fi
if [ ! -z $3 ] && [ $3 == "-mailPause" ]; then
export clsCommand="mail-pause"
fi
if [ ! -z $3 ] && [ $3 == "-mailResume" ]; then
export clsCommand="mail-resume"
fi
if [ ! -z $3 ] && [ ! -z $4 ] && [ $3 == "-switchOver" ]; then
export clsCommand="switchOver"
export targetSlave=$4
fi
if [ ! -z $3 ] && [ ! -z $4 ] && [ $3 == "-reinit" ]; then
export clsCommand="reinit"
export targetSlave=$4
fi
if [ ! -z $3 ] && [ ! -z $4 ] && [ $3 == "-watchMode" ]; then
export clsCommand="strategy"
export clsStrategy=$4
fi
if [ ! -z $3 ] && [ ! -z $4 ] && [ $3 == "-encrypt" ]; then
export clsCommand="encrypt"
export clearStr=$4
fi
if [ ! -z $4 ] && [ $4 == "-status" ]; then
export clsCommand="status"
fi
if [ ! -z $4 ] && [ $4 == "-pause" ]; then
export clsCommand="pause"
fi
if [ ! -z $4 ] && [ $4 == "-resume" ]; then
export clsCommand="resume"
fi
if [ ! -z $4 ] && [ $4 == "-mailPause" ]; then
export clsCommand="mail-pause"
fi
if [ ! -z $4 ] && [ $4 == "-mailResume" ]; then
export clsCommand="mail-resume"
fi
if [ ! -z $4 ] && [ ! -z $5 ] && [ $4 == "-switchOver" ]; then
export clsCommand="switchOver"
export targetSlave=$5
fi
if [ ! -z $4 ] && [ ! -z $5 ] && [ $4 == "-reinit" ]; then
export clsCommand="reinit"
export targetSlave=$5
fi
if [ ! -z $4 ] && [ ! -z $5 ] && [ $4 == "-watchMode" ]; then
export clsCommand="strategy"
export clsStrategy=$5
fi
if [ ! -z $4 ] && [ ! -z $5 ] && [ $4 == "-encrypt" ]; then
export clsCommand="encrypt"
export clearStr=$5
fi
if [ ! -z $5 ] && [ $5 == "-status" ]; then
export clsCommand="status"
fi
if [ ! -z $5 ] && [ $5 == "-pause" ]; then
export clsCommand="pause"
fi
if [ ! -z $5 ] && [ $5 == "-resume" ]; then
export clsCommand="resume"
fi
if [ ! -z $5 ] && [ $5 == "-mailPause" ]; then
export clsCommand="mail-pause"
fi
if [ ! -z $5 ] && [ $5 == "-mailResume" ]; then
export clsCommand="mail-resume"
fi
if [ ! -z $5 ] && [ ! -z $6 ] && [ $5 == "-switchOver" ]; then
export clsCommand="switchOver"
export targetSlave=$6
fi
if [ ! -z $5 ] && [ ! -z $6 ] && [ $5 == "-reinit" ]; then
export clsCommand="reinit"
export targetSlave=$6
fi
if [ ! -z $5 ] && [ ! -z $6 ] && [ $5 == "-watchMode" ]; then
export clsCommand="strategy"
export clsStrategy=$6
fi
if [ ! -z $5 ] && [ ! -z $6 ] && [ $5 == "-encrypt" ]; then
export clsCommand="encrypt"
export clearStr=$6
fi
if [ -z $clsUser ] || [ -z $clsPwd ]; then
echo "user or password NOT set. "
else
if [ -f /etc/bfm/bfmwatcher/application.properties ]; then
export bfmPort=$(cat /etc/bfm/bfmwatcher/application.properties |grep watcher.cluster-port |cut -d "=" -f 2 |tr -d " ")
elif [ -f ./application.properties ]; then
export bfmPort=$(cat /etc/bfm/bfmwatcher/application.properties |grep watcher.cluster-port |cut -d "=" -f 2 |tr -d " ")
else
export bfmPort=9994
fi
active_bfm=$(curl -s http://localhost:$bfmPort/bfm/get-active-bfm -u $clsUser:$clsPwd)
echo -e "\nActive BFM :"$active_bfm
if [ ! -z $clsCommand ] && [ $clsCommand == "status" ]; then
curl -X GET http://$active_bfm/bfm/cluster-status -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "pause" ]; then
curl -X GET http://$active_bfm/bfm/check-pause -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "resume" ]; then
curl -X GET http://$active_bfm/bfm/check-resume -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "mail-pause" ]; then
curl -X GET http://$active_bfm/bfm/mail-pause -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "mail-resume" ]; then
curl -X GET http://$active_bfm/bfm/mail-resume -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "strategy" ]; then
curl -X POST http://$active_bfm/bfm/watch-strategy/$clsStrategy -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "switchOver" ]; then
curl -X POST http://$active_bfm/bfm/switchover/$targetSlave -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "reinit" ]; then
curl -X POST http://$active_bfm/bfm/reinit/$targetSlave -u $clsUser:$clsPwd
elif [ ! -z $clsCommand ] && [ $clsCommand == "encrypt" ]; then
curl -X POST http://$active_bfm/bfm/encrypt/$clearStr -u $clsUser:$clsPwd
else
echo "command not found..."$clsCommand
fi
fi