forked from open-c3/open-c3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsingle.sh
executable file
·332 lines (275 loc) · 9.57 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
#!/bin/bash
BASE_PATH=/data/open-c3
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]get open-c3 ..."
if [ ! -d $BASE_PATH ]; then
if [ ! -d /data ];then
mkdir /data
fi
cd /data && git clone $GITADDR/open-c3/open-c3
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
cd $BASE_PATH/Installer && git clone $GITADDR/open-c3/open-c3-install-cache install-cache
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" ]; 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
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
cd $BASE_PATH/c3-front/dist && git clone $GITADDR/open-c3/open-c3.github.io book
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"
/data/open-c3/open-c3.sh start
}
function start() {
echo =================================================================
echo "[INFO]start ..."
cd $BASE_PATH/Installer/C3/ && ../docker-compose up -d --build
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
}
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
;;
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
reload)
reload
;;
*)
echo "Usage: $0 {start|stop|status|restart|reload|install|rebuild|reborn|upgrade}"
echo "$0 install 10.10.10.10(Your Internet IP)"
exit 2
esac