forked from open-c3/open-c3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsingle.sh
executable file
·498 lines (409 loc) · 14.6 KB
/
single.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
#!/bin/bash
BASE_PATH=/data/open-c3
if [ "X$OPENC3VERSION" == "X" ]; then
OPENC3VERSION=v2.2.0
fi
MASTERVERSION=$(echo $OPENC3VERSION | awk -F- '{print $1}')
GITADDR=http://github.com
DOCKERINSTALL=https://get.docker.com
if [ "X$OPENC3_ZONE" == "XCN" ]; then
GITADDR=http://gitee.com
DOCKERINSTALL=https://get.daocloud.io/docker
fi
function install() {
echo =================================================================
echo "[INFO]install git ..."
git --help 1>/dev/null 2>&1 || yum install git -y
git --help 1>/dev/null 2>&1
if [ $? = 0 ]; then
echo "[SUCC]git installed."
else
echo "[FAIL]install git fail."
exit 1
fi
echo =================================================================
echo "[INFO]get open-c3 ..."
if [ ! -d $BASE_PATH ]; then
if [ ! -d /data ];then
mkdir /data
fi
if [ -d /data/open-c3-installer/open-c3 ];then
cd /data && cp -r /data/open-c3-installer/open-c3 .
else
cd /data && git clone -b "$OPENC3VERSION" $GITADDR/open-c3/open-c3
fi
fi
if [ -d "$BASE_PATH" ]; then
echo "[SUCC]get open-c3 success."
else
echo "[FAIL]get open-c3 fail."
exit 1
fi
cd $BASE_PATH || exit 1
echo =================================================================
echo "[INFO]create Installer/C3/.env"
if [ "X$1" != "X" ]; then
echo $1 |grep "^[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}$" > /dev/null
if [ $? = 0 ]; then
random=$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM
name="test"
if [ "X$OPEN_C3_NAME" != "X" ];then
name=$OPEN_C3_NAME
fi
echo "OPEN_C3_RANDOM=$random" > $BASE_PATH/Installer/C3/.env
echo "OPEN_C3_EXIP=$1" >> $BASE_PATH/Installer/C3/.env
echo "OPEN_C3_NAME=$name" >> $BASE_PATH/Installer/C3/.env
else
echo "$0 install 10.10.10.10(Your Internet IP)"
exit 1
fi
else
echo "$0 install 10.10.10.10(Your Internet IP)"
exit 1
fi
if [ -f "$BASE_PATH/Installer/C3/.env" ]; then
echo "[SUCC]create $BASE_PATH/Installer/C3/.env success."
else
echo "[FAIL]create $BASE_PATH/Installer/C3/.env fail."
exit 1
fi
echo =================================================================
echo "[INFO]create Connector/config.ini/current ..."
if [ ! -f $BASE_PATH/Connector/config.ini/current ];then
cp $BASE_PATH/Connector/config.ini/openc3 $BASE_PATH/Connector/config.ini/current
fi
if [ -f "$BASE_PATH/Connector/config.ini/current" ]; then
echo "[SUCC]create Connector/config.ini/current success."
else
echo "[FAIL]create Connector/config.ini/current fail."
exit 1
fi
echo =================================================================
echo "[INFO]install docker ..."
docker --help 1>/dev/null 2>&1 || curl -fsSL $DOCKERINSTALL | bash
docker --help 1>/dev/null 2>&1
if [ $? = 0 ]; then
echo "[SUCC]docker installed."
else
echo "[FAIL]install docker fail."
exit 1
fi
echo =================================================================
echo "[INFO]start docker ..."
docker ps 1>/dev/null 2>&1 || service docker start
docker ps 1>/dev/null 2>&1
if [ $? = 0 ]; then
echo "[SUCC]docker is started."
else
echo "[FAIL]start docker fail."
exit 1
fi
echo =================================================================
echo "[INFO]enable docker.service ..."
systemctl enable docker.service
if [ $? = 0 ]; then
echo "[SUCC]enable docker.service success."
else
echo "[FAIL]enable docker.service fail."
exit 1
fi
echo =================================================================
echo "[INFO]get open-c3-install-cache ..."
if [ ! -d "$BASE_PATH/Installer/install-cache" ]; then
if [ -d /data/open-c3-installer/install-cache ];then
cd $BASE_PATH/Installer && cp -r /data/open-c3-installer/install-cache .
else
cd $BASE_PATH/Installer && git clone $GITADDR/open-c3/open-c3-install-cache install-cache
fi
cd $BASE_PATH
fi
if [ -d "$BASE_PATH/Installer/install-cache" ]; then
echo "[SUCC]get open-c3-install-cache success."
else
echo "[FAIL]get open-c3-install-cache fail."
exit 1
fi
echo =================================================================
echo "[INFO]create c3-front/dist ..."
if [ -d "$BASE_PATH/Installer/install-cache/c3-front/dist-$MASTERVERSION" ]; then
rm -rf $BASE_PATH/c3-front/dist
cp -r "$BASE_PATH/Installer/install-cache/c3-front/dist-$MASTERVERSION" $BASE_PATH/c3-front/dist
else
echo "[Warn]nofind c3-front/dist-$MASTERVERSION in open-c3-install-cache."
if [ -d "$BASE_PATH/Installer/install-cache/c3-front/dist" ]; then
rm -rf $BASE_PATH/c3-front/dist
cp -r "$BASE_PATH/Installer/install-cache/c3-front/dist" $BASE_PATH/c3-front/dist
else
echo "[FAIL]nofind c3-front/dist in open-c3-install-cache."
fi
fi
if [ -d "$BASE_PATH/c3-front/dist" ]; then
echo "[SUCC]create c3-front/dist success."
else
echo "[FAIL]create c3-front/dist fail."
exit 1
fi
echo =================================================================
echo "[INFO]create c3-front/dist/book ..."
rm -rf $BASE_PATH/c3-front/dist/book
if [ -d /data/open-c3-installer/book ]; then
cp -r /data/open-c3-installer/book $BASE_PATH/c3-front/dist/book
else
cd $BASE_PATH/c3-front/dist && git clone $GITADDR/open-c3/open-c3.github.io book
fi
if [ -d "$BASE_PATH/c3-front/dist/book" ]; then
echo "[SUCC]create c3-front/dist/book success."
else
echo "[FAIL]create c3-front/dist/book fail."
exit 1
fi
cd $BASE_PATH || exit 1
echo =================================================================
echo "[INFO]create web-shell/node_modules ..."
if [ -d "$BASE_PATH/Installer/install-cache/web-shell/node_modules" ]; then
rm -rf $BASE_PATH/web-shell/node_modules
cp -r $BASE_PATH/Installer/install-cache/web-shell/node_modules $BASE_PATH/web-shell/node_modules
else
echo "[FAIL]nofind web-shell/node_modules in open-c3-install-cache."
fi
if [ -d "$BASE_PATH/web-shell/node_modules" ]; then
echo "[SUCC]create web-shell/node_modules success."
else
echo "[FAIL]create web-shell/node_modules fail."
exit 1
fi
echo =================================================================
echo "[INFO]create Installer/C3/mysql/init/init.sql ..."
cat $BASE_PATH/*/schema.sql > $BASE_PATH/Installer/C3/mysql/init/init.sql
cat $BASE_PATH/Installer/C3/mysql/init.sql >> $BASE_PATH/Installer/C3/mysql/init/init.sql
if [ -f "$BASE_PATH/Installer/C3/mysql/init/init.sql" ]; then
echo "[SUCC]create Installer/C3/mysql/init/init.sql success."
else
echo "[FAIL]create Installer/C3/mysql/init/init.sql fail."
exit 1
fi
echo =================================================================
echo "[INFO]get MYDan ..."
mkdir -p $BASE_PATH/MYDan
rm -rf $BASE_PATH/MYDan/repo
if [ -d "$BASE_PATH/Installer/install-cache/MYDan" ]; then
rsync -av $BASE_PATH/Installer/install-cache/MYDan/ $BASE_PATH/MYDan/
if [ $? = 0 ]; then
echo "[SUCC]rsync MYDan from install-cache success."
else
echo "[FAIL]rsync MYDan from install-cache fail."
exit 1
fi
else
cd $BASE_PATH/MYDan && git clone https://github.com/MYDan/repo
cd $BASE_PATH
if [ -d "$BASE_PATH/MYDan/repo" ]; then
echo "[SUCC]get MYDan success."
else
echo "[FAIL]get MYDan fail."
exit 1
fi
fi
echo =================================================================
echo "[INFO]sync MYDan/repo ..."
if [ -d "$BASE_PATH/Installer/install-cache/MYDan" ]; then
echo "[INFO]rsync MYDan from install-cache done. skip"
else
cd $BASE_PATH/MYDan/repo/scripts && SYNC_MYDan_VERSION=20201213220001:10108f7303adc9992db663bfd99ddf1b ./sync.sh
cd $BASE_PATH
if [ $? = 0 ]; then
echo "[SUCC]sync MYDan/repo success."
else
echo "[FAIL]sync MYDan/repo fail."
exit 1
fi
fi
echo "[SUCC]openc-c3 installed successfully."
echo =================================================================
echo "Web page: http://$1"
echo "User: open-c3"
echo "Password: changeme"
echo "[INFO]Run command to start service: /data/open-c3/open-c3.sh start"
if [ -d /data/open-c3-installer/dev-cache ];then
cp -r /data/open-c3-installer/dev-cache /data/open-c3/Installer/
fi
/data/open-c3/Installer/scripts/dev.sh build
/data/open-c3/open-c3.sh dup
/data/open-c3/open-c3.sh start
echo =================================================================
echo "[INFO]run script ..."
if [ -x "$BASE_PATH/Installer/scripts/single/$MASTERVERSION.sh" ]; then
$BASE_PATH/Installer/scripts/single/$MASTERVERSION.sh
if [ $? = 0 ]; then
echo "[SUCC]run script success."
else
echo "[FAIL]run script fail."
exit 1
fi
fi
mkdir -p /data/open-c3-data/grafana-data
rsync -av /data/open-c3/Installer/install-cache/grafana-data/ /data/open-c3-data/grafana-data/
}
function start() {
echo =================================================================
echo "[INFO]start ..."
DCF=docker-compose.yml
if [ -f "Connector/mysql.config-test" ]; then
DCF=docker-compose-nomysql.yml
fi
if [ -f "Installer/C3/docker-compose-private.yml" ]; then
DCF=docker-compose-private.yml
fi
#prometheus
mkdir -p /data/open-c3-data/prometheus-data
chmod 777 /data/open-c3-data/prometheus-data
if [ ! -f /data/open-c3/prometheus/config/prometheus.yml ];then
cp /data/open-c3/prometheus/config/prometheus.example.yml /data/open-c3/prometheus/config/prometheus.yml
fi
if [ ! -f /data/open-c3/prometheus/config/openc3_node_sd.yml ];then
cp /data/open-c3/prometheus/config/openc3_node_sd.example.yml /data/open-c3/prometheus/config/openc3_node_sd.yml
fi
#
#alertmanager
if [ ! -f /data/open-c3/alertmanager/config/alertmanager.yml ];then
cp /data/open-c3/alertmanager/config/alertmanager.example.yml /data/open-c3/alertmanager/config/alertmanager.yml
fi
#
#lua.1
mkdir -p /data/open-c3/lua/lualib
rsync -av /data/open-c3/Installer/install-cache/lualib/ /data/open-c3/lua/lualib/
#
cd $BASE_PATH/Installer/C3/ && ../docker-compose -f $DCF up -d --build
#grafana
docker cp /data/open-c3/grafana/config/grafana.ini openc3-grafana:/etc/grafana/grafana.ini
docker restart openc3-grafana
docker cp /data/open-c3/grafana/config/grafana-fresh.ini openc3-grafana-fresh:/etc/grafana/grafana.ini
docker restart openc3-grafana-fresh
#
#lua
cp /data/open-c3/lua/config/lua/sso.example.lua /data/open-c3/lua/config/lua/sso.temp.lua
#OPENC3 TODO 这里ip替换域名是lua解析容器中的域名失败
# REIP=$(docker exec -it openc3-lua ping -c 1 OPENC3_SERVER_IP|grep openc3-server.c3_JobNet|awk -F '[()]' '{print $2}'|grep ^[0-9\.]*$|tail -n 1 )
COOKIEKEY=$(cat /data/open-c3/Connector/config.inix | grep -v '^ *#' | grep cookiekey:|awk '{print $2}'|grep ^[a-zA-Z0-9]*$)
# sed -i "s/OPENC3_SERVER_IP/$REIP/" /data/open-c3/lua/config/lua/sso.temp.lua
sed -i "s/ngx.var.cookie_sid/ngx.var.cookie_$COOKIEKEY/g" /data/open-c3/lua/config/lua/sso.temp.lua
cp /data/open-c3/lua/config/lua/sso.temp.lua /data/open-c3/lua/config/lua/sso.lua
docker restart openc3-lua
#
echo "[SUCC]started."
}
function stop() {
echo =================================================================
echo "[INFO]stop ..."
cd $BASE_PATH/Installer/C3/ && ../docker-compose kill
echo "[SUCC]stoped."
}
function restart() {
echo =================================================================
echo "[INFO]restart ..."
Date=$(date "+%F %H:%M:%S")
echo "#$Date restart" >> $BASE_PATH/Connector/config.ini/current
echo "[SUCC]The operation is complete and the service will restart in a few seconds."
}
function reload() {
echo =================================================================
echo "[INFO]reload ..."
Date=$(date "+%F %H:%M:%S")
echo "#$Date reload" >> $BASE_PATH/Connector/config.ini/current
echo "[SUCC]The operation is complete and the service will reload in a few seconds."
}
function check() {
module=$1
X=$(curl localhost/api/$module/mon 2>/dev/null)
if [ "X$X" = "Xok" ]; then
echo "[SUCC]module $module up."
else
echo "[FAIL]module $module down."
fi
}
function status() {
echo =================================================================
check connector
check agent
check job
check jobx
check ci
}
function inx() {
docker exec -it openc3-server env LANG=C.UTF-8 LC_ALL=C bash
}
function app() {
docker exec -it openc3-server env LANG=C.UTF-8 LC_ALL=C /data/Software/mydan/Connector/pp/c3mc-app
}
function sql() {
docker exec -it openc3-mysql env LANG=C.UTF-8 mysql -uroot -popenc3123456^!
}
function log() {
docker logs -f openc3-server
}
function dup() {
docker exec -t openc3-server c3mc-sys-dup
}
OPENC3_ZONE_CHECK=$(cat /data/open-c3/.git/config |grep gitee.com/open-c3/open-c3|wc -l)
if [ "X$OPENC3_ZONE_CHECK" == "X1" ];then
export OPENC3_ZONE=CN
fi
case "$1" in
install)
install $2
;;
rebuild)
stop && start
;;
reborn)
$BASE_PATH/Installer/scripts/databasectrl.sh backup
$BASE_PATH/Installer/scripts/upgrade.sh
stop && start
$BASE_PATH/Installer/scripts/upgrade.sh
;;
upgrade)
$BASE_PATH/Installer/scripts/upgrade.sh $2 $3
;;
switchversion)
if [ "X$2" = "X" ];then
echo "$0 switchversion vx.x.x";
exit 1;
fi
$BASE_PATH/Installer/scripts/versionctrl.sh list
$BASE_PATH/Installer/scripts/versionctrl.sh switch $2
;;
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
reload)
reload
;;
inx)
inx
;;
app)
app
;;
sql)
sql
;;
log)
log
;;
dup)
dup
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|install|rebuild|reborn|upgrade|switchversion|inx|app|sql|log|dup}"
echo "$0 install 10.10.10.10(Your Internet IP)"
exit 2
esac