This repository has been archived by the owner on Feb 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathsetup.sh
executable file
·692 lines (601 loc) · 20.1 KB
/
setup.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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#!/bin/bash
#======================================================================================================================
#
# FILE: setup.sh
#
# DESCRIPTION: Install Rainbond Cluster
#
# BUGS: https://github.com/goodrain/rainbond-install/issues
#
# COPYRIGHT: (c) 2018 by the Goodrain Delivery Team.
#
# LICENSE: Apache 2.0
# CREATED: 08/03/2018 11:38:02 AM
#======================================================================================================================
[[ $DEBUG ]] && set -x
INSTALL_TYPE=${2:-"online"}
MAIN_CONFIG="/srv/pillar/rainbond.sls"
RAINBOND_HOMEPAGE="https://www.rainbond.com"
PILLAR_DIR="./install/pillar"
DOMAIN_API="http://domain.grapps.cn"
SYS_NAME=$(grep "^ID=" /etc/os-release | awk -F = '{print $2}'|sed 's/"//g')
SYS_VER=$(grep "^VERSION_ID=" /etc/os-release | awk -F = '{print $2}'|sed 's/"//g')
CPU_NUM=$(grep "processor" /proc/cpuinfo | wc -l )
CPU_LIMIT=2
MEM_SIZE=$(free -h | grep Mem | awk '{print $2}' | cut -d 'G' -f1)
MEM_LIMIT=4
DEFAULT_LOCAL_IP=${4:-"$(ip ad | grep 'inet ' | awk '{print $2}' | cut -d '/' -f 1 | egrep '^10\.|^172.|^192.168' | grep -v '172.30.42.1' | head -1)"}
DEFAULT_PUBLIC_IP=${3:-"$(ip ad | grep 'inet ' | awk '{print $2}' | cut -d '/' -f 1 | egrep -v '^10\.|^172.|^192.168|^127.' | head -1)"}
INIT_FILE="./.initialized"
YQBIN="/usr/local/bin/yq"
DOMAIN=$7
ROLE=$1
SYS_COMMON_PKGS=(ntpdate curl net-tools pwgen)
BASE_MODULES=(common storage docker image base)
MANAGE_MODULES=(master)
COMPUTE_MODULES=(worker)
STORAGE=$5
NETWORK=$6
#STORAGE_CLIENT_ARGS=${5:-"/grdata nfs rw 0 0"}
which_cmd() {
which "${1}" 2>/dev/null || \
command -v "${1}" 2>/dev/null
}
check_cmd() {
which_cmd "${1}" >/dev/null 2>&1 && return 0
return 1
}
setup_terminal() {
TPUT_RESET=""
TPUT_BLACK=""
TPUT_RED=""
TPUT_GREEN=""
TPUT_YELLOW=""
TPUT_BLUE=""
TPUT_PURPLE=""
TPUT_CYAN=""
TPUT_WHITE=""
TPUT_BGBLACK=""
TPUT_BGRED=""
TPUT_BGGREEN=""
TPUT_BGYELLOW=""
TPUT_BGBLUE=""
TPUT_BGPURPLE=""
TPUT_BGCYAN=""
TPUT_BGWHITE=""
TPUT_BOLD=""
TPUT_DIM=""
TPUT_UNDERLINED=""
TPUT_BLINK=""
TPUT_INVERTED=""
TPUT_STANDOUT=""
TPUT_BELL=""
TPUT_CLEAR=""
# Is stderr on the terminal? If not, then fail
test -t 2 || return 1
if check_cmd tput
then
if [ $(( $(tput colors 2>/dev/null) )) -ge 8 ]
then
# Enable colors
TPUT_RESET="$(tput sgr 0)"
TPUT_BLACK="$(tput setaf 0)"
TPUT_RED="$(tput setaf 1)"
TPUT_GREEN="$(tput setaf 2)"
TPUT_YELLOW="$(tput setaf 3)"
TPUT_BLUE="$(tput setaf 4)"
TPUT_PURPLE="$(tput setaf 5)"
TPUT_CYAN="$(tput setaf 6)"
TPUT_WHITE="$(tput setaf 7)"
TPUT_BGBLACK="$(tput setab 0)"
TPUT_BGRED="$(tput setab 1)"
TPUT_BGGREEN="$(tput setab 2)"
TPUT_BGYELLOW="$(tput setab 3)"
TPUT_BGBLUE="$(tput setab 4)"
TPUT_BGPURPLE="$(tput setab 5)"
TPUT_BGCYAN="$(tput setab 6)"
TPUT_BGWHITE="$(tput setab 7)"
TPUT_BOLD="$(tput bold)"
TPUT_DIM="$(tput dim)"
TPUT_UNDERLINED="$(tput smul)"
TPUT_BLINK="$(tput blink)"
TPUT_INVERTED="$(tput rev)"
TPUT_STANDOUT="$(tput smso)"
TPUT_BELL="$(tput bel)"
TPUT_CLEAR="$(tput clear)"
fi
fi
return 0
}
setup_terminal || echo >/dev/null
progress() {
echo >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- "
}
ok() {
printf >&2 "${TPUT_BGGREEN}${TPUT_WHITE}${TPUT_BOLD} OK ${TPUT_RESET} ${*} \n\n"
}
failed() {
printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} FAILED ${TPUT_RESET} ${*} \n\n"
}
error() {
printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} Error ${TPUT_RESET} ${*} \n\n"
}
info() {
printf >&2 " --- ${TPUT_DIM}${TPUT_BOLD}${*}${TPUT_RESET} --- \n\n"
}
fatal() {
printf >&2 "${TPUT_BGRED}${TPUT_WHITE}${TPUT_BOLD} ABORTED ${TPUT_RESET} ${*} \n\n"
exit 1
}
which cp | grep "alias" > /dev/null
if [ "$?" -eq 0 ];then
unalias cp
fi
[ ! -d "/srv/pillar/" ] && (
mkdir -p /srv/pillar/
cp rainbond.yaml.default ${MAIN_CONFIG}
)
which yq >/dev/null 2>&1 || (
cp -a ./scripts/yq /usr/local/bin/yq
chmod +x /usr/local/bin/yq
)
# setup first node role
[ -f "/tmp/.role" ] && rm -rf /tmp/.role
echo $ROLE | grep "worker" >/dev/null 2>&1
if [ "$?" -eq 0 ];then
touch /tmp/.role && INSTALL_MODULES=(common storage docker image base master worker)
else
INSTALL_MODULES=(common storage docker image base master)
fi
# config centos salt mirrors
salt_centos_mirrors(){
if [ "$INSTALL_TYPE" == "online" ];then
cat > /etc/yum.repos.d/salt-repo.repo << END
[saltstack]
name=SaltStack archive/2018.3.2 Release Channel for RHEL/CentOS $releasever
baseurl=http://mirrors.ustc.edu.cn/salt/yum/redhat/7/\$basearch/archive/2018.3.2
skip_if_unavailable=True
failovermethod=priority
gpgcheck=0
enabled=1
enabled_metadata=1
END
ls /etc/yum.repos.d/ | grep -i epel >/dev/null
[ $? -ne 0 ] && yum install epel-release -y >/dev/null 2>&1
else
mkdir -p /etc/yum.repos.d/backup >/dev/null 2>&1
mv -f /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup >/dev/null 2>&1
cat > /etc/yum.repos.d/rainbond.repo << EOF
[rainbond]
name=rainbond_offline_install_repo
baseurl=file:///opt/rainbond/install/install/pkgs/centos/
gpgcheck=0
enabled=1
EOF
fi
yum makecache fast -q >/dev/null 2>&1
}
# config debian salt mirrors
salt_debian_mirrors(){
apt update >/dev/null
apt install -y -q curl apt-transport-https >/dev/null
if [ "$INSTALL_TYPE" == "online" ];then
cat > /etc/apt/sources.list.d/salt.list << END
deb http://mirrors.ustc.edu.cn/salt/apt/debian/9/amd64/2018.3 stretch main
END
curl https://mirrors.ustc.edu.cn/salt/apt/debian/9/amd64/latest/SALTSTACK-GPG-KEY.pub 2>/dev/null | apt-key add -
else
fatal "Not support Now"
fi
apt update >/dev/null 2>&1
}
progress "Start Check System,will install Rainbond $(cat ./VERSION)"
if [ "$SYS_NAME" == "centos" ];then
CENTOS_RELEASE=$(cat /etc/redhat-release | cut -d' ' -f4)
if [ "$CENTOS_RELEASE" == "7.3.1611" ] || [ "$CENTOS_RELEASE" == "7.4.1708" ];then
salt_centos_mirrors
if [ "$INSTALL_TYPE" == "online" ];then
ok "Configuring SaltStack online $SYS_NAME mirrors"
else
ok "Configuring SaltStack offline $SYS_NAME mirrors"
fi
else
fatal "Support CentOS 7.3 Or CentOS 7.4"
fi
elif [ "$SYS_NAME" == "debian" -o "$SYS_NAME" == "ubuntu" ];then
salt_debian_mirrors
if [ "$INSTALL_TYPE" == "online" ];then
ok "Configuring SaltStack online $SYS_NAME mirrors"
else
ok "Configuring SaltStack offline $SYS_NAME mirrors"
fi
else
fatal "Only support CentOS/Debian/Ubuntu"
fi
# CentOS install required packages
yum_install_func(){
local Centos_PKGS=(ntpdate curl net-tools pwgen perl bind-utils dstat iproute bash-completion salt-ssh)
for pkg in ${Centos_PKGS[@]}
do
yum install -y -q $pkg >/dev/null
done
ok "Install required packages successful."
}
# Debian/Ubuntu install required packages
apt_install_func(){
local Debian_PKGS=(ntpdate curl net-tools pwgen uuid-runtime iproute2 systemd dnsutils python-pip salt-ssh)
for pkg in ${Debian_PKGS[@]}
do
apt install -y -q $pkg >/dev/null
done
ok "Install required packages successful."
}
progress "Detect $SYS_NAME required packages..."
case $SYS_NAME in
"centos")
[ "$SYS_VER" == "7" ] && yum_install_func || error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
"ubuntu")
[ "$SYS_VER" == "16.04" ] && apt_install_func || error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
"debian")
[ "$SYS_VER" == "9" ] && apt_install_func || error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
*)
error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
esac
# up domain to dns nameserver
reg_status(){
uid=$( Read_Sls_File reg-uuid $MAIN_CONFIG )
iip=$( Read_Sls_File master-private-ip $MAIN_CONFIG )
eip=$( Read_Sls_File master-public-ip $MAIN_CONFIG )
if [ ! -z "$eip" ];then
ip=$eip
else
ip=$iip
fi
domain=$( Read_Sls_File domain $MAIN_CONFIG )
if [[ "$domain" =~ "grapps" ]];then
curl -s --connect-timeout 20 ${DOMAIN_API}/status\?uuid=$uid\&ip=$ip\&type=True\&domain=$domain >/dev/null
fi
}
# update rainbond.sls
Write_Sls_File(){
key=$1
value=$2
slsfile=${3:-$MAIN_CONFIG}
isExist=$( $YQBIN r $slsfile $key )
if [ "$isExist" == "null" ];then
$YQBIN w -i $slsfile $key "$value"
fi
}
# get key from rainbond.sls
Read_Sls_File(){
key=$1
slsfile=${2:-$MAIN_CONFIG}
$YQBIN r $slsfile $key
}
Check_Service_State(){
sname=$1
systemctl is-active $sname > /dev/null 2>&1
}
Install_PKG(){
pkg_name="$@"
$INSTALL_BIN install -y -q $pkg_name > /dev/null
}
# check python urllib3 for aliyun (CentOS 7.x)
Check_Python_Urllib(){
if [ ! -f "$INIT_FILE" ];then
if ( which pip > /dev/null 2>&1 );then
if ( pip show urllib3 > /dev/null 2>&1 );then
if [ "$SYS_NAME" == "centos" ];then
pip uninstall urllib3 -y > /dev/null 2>&1
else
pip install -U urllib3 > /dev/null 2>&1
fi
fi
fi
fi
}
#============================== check func =====================================
Check_Internet(){
check_url=$1
curl -s --connect-timeout 15 $check_url -o /dev/null 2>/dev/null
if [ "$?" -eq 0 ];then
return 0
else
error "Unable to connect to internet."
fi
}
Check_Docker_Version(){
if (which docker > /dev/null 2>&1 );then
existDocker=$(docker -v | awk '{print $3$5}' 2>/dev/null)
grDocker=$(Read_Sls_File docker.version)
if [ "$existDocker" != "$grDocker" ];then
error "Rainbond integrated customized docker, Please stop and uninstall it first."
fi
fi
}
Check_System_Version(){
case $SYS_NAME in
"centos")
[ "$SYS_VER" == "7" ] \
&& return 0 \
|| error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
"ubuntu")
[ "$SYS_VER" == "16.04" ] \
&& return 0 \
|| error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
"debian")
[ "$SYS_VER" == "8" -o "$SYS_VER" == "9" ] \
&& return 0 \
|| error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
*)
error "$SYS_NAME:$SYS_VER is not supported temporarily."
;;
esac
}
Check_Net(){
if [[ "$DEFAULT_LOCAL_IP" == "0.0.0.0" ]];then
DEFAULT_LOCAL_IP="$(ip ad | grep 'inet ' | awk '{print $2}' | cut -d '/' -f 1 | egrep '^10\.|^172.|^192.168' | grep -v '172.30.42.1' | head -1)"
fi
echo $DEFAULT_LOCAL_IP > ./LOCAL_IP
echo $DEFAULT_LOCAL_IP > /tmp/LOCAL_IP
info "Rainbond default static network ip: ${DEFAULT_LOCAL_IP}."
}
Get_Hardware_Info(){
CPU_STATUS=$(awk -v num1=$CPU_NUM -v num2=2 'BEGIN{print(num1>=num2)?"0":"1"}')
MEM_STATUS=$(awk -v num1=$MEM_SIZE -v num2=3 'BEGIN{print(num1>num2)?"0":"1"}')
if [ "$CPU_STATUS" == '0' -a "$MEM_STATUS" == '0' ];then
info "Rainbond minimum requirement is ${CPU_LIMIT} CPUs,${MEM_LIMIT}G memory.You Have ${CPU_NUM} CPUs,${MEM_SIZE}G memory."
else
error "Rainbond minimum requirement is ${CPU_LIMIT} CPUs,${MEM_LIMIT}G memory.You Have ${CPU_NUM} CPUs,${MEM_SIZE}G memory."
fi
}
# check system
system_check(){
progress "Checking internet connect ..."
if [ "$INSTALL_TYPE" == "online" ];then
Check_Internet $RAINBOND_HOMEPAGE && ok
else
ok
fi
progress "Check system environment..."
Check_Docker_Version && ok
# disk cpu memory
progress "Getting Hardware information ..."
Get_Hardware_Info && ok
#ipaddr(inet pub) type .mark in .sls
progress "Getting Network information ..."
Check_Net && ok
}
#============================== init func =====================================
Init_system(){
# configure ip address
LOCAL_IP=$(cat ./LOCAL_IP 2> /dev/null)
DEFAULT_LOCAL_IP=${LOCAL_IP:-$DEFAULT_LOCAL_IP}
Write_Sls_File master-private-ip $DEFAULT_LOCAL_IP
Write_Sls_File vip $DEFAULT_LOCAL_IP
if [[ "$DEFAULT_PUBLIC_IP" == "0.0.0.0" ]];then
DEFAULT_PUBLIC_IP="$(ip ad | grep 'inet ' | awk '{print $2}' | cut -d '/' -f 1 | egrep -v '^10\.|^172.|^192.168|^127.' | head -1)"
Write_Sls_File master-public-ip "${DEFAULT_PUBLIC_IP}"
else
Write_Sls_File master-public-ip "${DEFAULT_PUBLIC_IP}"
fi
# configure hostname and hosts
# reset /etc/hosts
[ -f "/tmp/.new.hosts" ] || (
cp /etc/hosts /tmp/hosts.bak
cat /etc/hosts | grep -E 'storage|compute' > /opt/rainbond/install/install/salt/install/files/storage/storage.hosts
)
echo -e "127.0.0.1\tlocalhost" > /etc/hosts
MASTER_HOSTNAME=$(Read_Sls_File master-hostname)
hostname -b $MASTER_HOSTNAME
echo $MASTER_HOSTNAME > /etc/hostname
#grep "$MASTER_HOSTNAME" /etc/hosts && sed -i '/$MASTER_HOSTNAME/d' /etc/hosts
echo -e "$DEFAULT_LOCAL_IP\t$MASTER_HOSTNAME" >> /etc/hosts
# Get current directory
Write_Sls_File install-script-path "$PWD"
# Get dns and write global dns info
dns_value=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}' | head -1)
Write_Sls_File dns.current "$dns_value"
# generate secretkey
secretkey=$(pwgen 32 1)
Write_Sls_File secretkey "${secretkey:-auv2aequ1dahj9GameeGam9fei8Kohng}"
#judgment below uses for offline env : do not exec ntp cmd ( changed by guox 2018.5.18 ).
if [ "$INSTALL_TYPE" == "online" ];then
progress "update localtime"
ntpdate ntp1.aliyun.com ntp2.aliyun.com ntp3.aliyun.com > /dev/null 2>&1 && ok
else
return 0
fi
#config domain
if [ ! -z "$DOMAIN" ];then
Write_Sls_File domain $DOMAIN
fi
}
run(){
## Generate random user & password
DB_USER=write
DB_PASS=$(echo $((RANDOM)) | base64 | md5sum | cut -b 1-8)
DB_TYPE=$(Read_Sls_File database.type)
Write_Sls_File database.$DB_TYPE.host ${DEFAULT_LOCAL_IP}
Write_Sls_File database.$DB_TYPE.user ${DB_USER}
Write_Sls_File database.$DB_TYPE.pass ${DB_PASS}
STORAGE_CLIENT_ARGS=$(cat /tmp/.storage.value )
[ -z "$STORAGE_CLIENT_ARGS" ] && STORAGE_CLIENT_ARGS="/grdata nfs rw 0 0"
#rm -rf /tmp/.storage.value
Write_Sls_File storage.type ${STORAGE}
#Write_Sls_File storage.client_args ${STORAGE_CLIENT_ARGS:-"/grdata nfs rw 0 0"}
Write_Sls_File storage.client_args "${STORAGE_CLIENT_ARGS}"
Write_Sls_File etcd.server.bind.host ${DEFAULT_LOCAL_IP}
Write_Sls_File etcd.server.token $(uuidgen)
Write_Sls_File etcd.server.members[0].host ${DEFAULT_LOCAL_IP}
Write_Sls_File etcd.server.members[0].name ${MASTER_HOSTNAME}
Write_Sls_File etcd-endpoints "http://${DEFAULT_LOCAL_IP}:2379"
IP_INFO=$(ip ad | grep 'inet ' | egrep ' 10.|172.|192.168' | awk '{print $2}' | cut -d '/' -f 1 | grep -v '172.30.42.1')
IP_ITEMS=($IP_INFO)
INET_IP=${IP_ITEMS%%.*}
[ -f "/tmp/.role" ] && export NETWORK=calico
Write_Sls_File network.type ${NETWORK}
if [ "$NETWORK" == "calico" ];then
if [[ $INET_IP == '172' ]];then
CALICO_NET=10.0.0.0/16
elif [[ $INET_IP == '10' ]];then
CALICO_NET=172.16.0.0/16
else
CALICO_NET=172.16.0.0/16
fi
Write_Sls_File network.calico.bind ${DEFAULT_LOCAL_IP}
Write_Sls_File network.calico.net ${CALICO_NET}
else
if [[ $INET_IP == '192' ]];then
MIDONET_NET=10.0.0.0/16
else
MIDONET_NET=172.16.0.0/16
fi
Write_Sls_File network.midonet.cidr ${MIDONET_NET}
Write_Sls_File network.midonet.net ${MIDONET_NET}
fi
Write_Sls_File lb-endpoints "http://${DEFAULT_LOCAL_IP}:10002"
cat > ${PILLAR_DIR}/top.sls <<EOF
base:
'*':
- rainbond
EOF
}
# salt-ssh install salt-master,salt-minion
Install_Salt(){
# check python env
info "Check python environment ..."
Check_Python_Urllib && ok
inet_ip=$(Read_Sls_File "master-private-ip" )
cat > /etc/salt/roster <<EOF
manage01:
host: $inet_ip
port: 22
user: root
sudo: True
tty: True
priv: /etc/salt/pki/master/ssh/salt-ssh.rsa
EOF
[ -d "/root/.ssh" ] || (mkdir -p /root/.ssh && chmod 700 /root/.ssh )
[ -f "/etc/salt/pki/master/ssh/salt-ssh.rsa.pub" ] && cat /etc/salt/pki/master/ssh/salt-ssh.rsa.pub >> /root/.ssh/authorized_keys || (
salt-ssh "*" w >/dev/null 2>&1 || cat /etc/salt/pki/master/ssh/salt-ssh.rsa.pub >> /root/.ssh/authorized_keys
)
[ ! -d "~/.ssh/id_rsa" ] && (
cp -a /etc/salt/pki/master/ssh/salt-ssh.rsa ~/.ssh/id_rsa
cp -a /etc/salt/pki/master/ssh/salt-ssh.rsa.pub ~/.ssh/id_rsa.pub
)
cp -rp $PWD/install/salt /srv/
cp -rp $PWD/install/pillar/top.sls /srv/pillar/top.sls
info "Salt-ssh test."
salt-ssh "*" --priv=/etc/salt/pki/master/ssh/salt-ssh.rsa test.ping -i > /dev/null && ok
progress "Install Salt-Master & Salt-Minion"
salt-ssh "*" state.sls salt.setup --state-output=mixed
info "Waiting to start salt."
for ((i=1;i<=60;i++ )); do
echo -e -n "."
sleep 1
uuid=$(timeout 600 salt "*" grains.get uuid | grep '-' | awk '{print $1}')
[ ! -z "$uuid" ] && (
Write_Sls_File reg-uuid "$uuid" $MAIN_CONFIG
) && break
done
}
Init_Config_Func(){
Write_Sls_File install-type "$INSTALL_TYPE"
progress "Init system config ..."
Init_system && ok
progress "Init config ..."
run && ok
Install_Salt && ok
}
#================================ setup rainbond =========================================
#check_func(){
# progress "check system func."
# System_Check
#}
config(){
if [ ! -f "$INIT_FILE" ];then
progress "Init rainbond configure."
Init_Config_Func && touch $INIT_FILE
fi
}
install(){
fail_num=0
step_num=1
all_steps=${#INSTALL_MODULES[@]}
#progress "Start init node"
for module in ${INSTALL_MODULES[@]}
do
if [ "$module" = "image" ];then
info "Start pull $module(step: $step_num/$all_steps)"
else
info "Start install $module(step: $step_num/$all_steps) ..."
fi
if ! (salt "*" state.sls $module);then
((fail_num+=1))
break
fi
((step_num++))
sleep 1
done
#info "Start install master services"
#if ! (salt "*" state.sls master);then
# ((fail_num+=1))
#fi
#if [[ "$ROLE" =~ "worker" ]];then
# info "Start install worker services"
# if ! (salt "*" state.sls worker);then
# ((fail_num+=1))
# fi
#fi
if [ "$fail_num" -eq 0 ];then
if [ "$INSTALL_TYPE" == "online" ];then
reg_status || return 0
fi
uuid=$(salt '*' grains.get uuid | grep "-" | awk '{print $1}')
if [ -z "$uuid" ];then
fatal "Please check node status[uuid], Just Run systemctl status node"
exit 1
fi
for ((i=1;i<=60;i++ ));do
sleep 1
notready=$(grctl node list | grep $uuid | grep offline)
[ ! -z "$notready" ] && (
grctl node up $uuid
) && break
done
info "Install Rainbond successfully"
docker images | grep "rainbond" | awk '{print $1":"$2}' | xargs -I {} docker rmi {} >/dev/null 2>&1
public_ip=$(yq r /srv/pillar/rainbond.sls master-public-ip)
private_ip=$(yq r /srv/pillar/rainbond.sls master-private-ip)
for ((i=1;i<=60;i++ ));do
sleep 1
status_code=$(curl -s -I http://127.0.0.1:7070 | head -1 | awk '{print $2}')
check_code=$(awk -v num1=$status_code -v num2=400 'BEGIN{print(num1<num2)?"0":"1"}')
[ "$check_code" == "0" ] && (
if [ ! -z "$public_ip" ];then
#echo_banner "http://${public_ip}:7070"
echo "${public_ip}" > /opt/rainbond/envs/.exip
else
#echo_banner "http://${private_ip}:7070"
echo "${private_ip}" > /opt/rainbond/envs/.exip
fi
) && break
done
else
failed "install failed... get help from https://t.goodrain.com"
exit 1
fi
}
case $1 in
*)
system_check && config && install
;;
esac