forked from CyberMiles/travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
travis-cluster.sh
executable file
·133 lines (111 loc) · 2.23 KB
/
travis-cluster.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
#!/bin/bash
INST_COUNT=$1
CLEAR=$2
CLS='--clear'
MV='--mv' #multi validators
BASE_DIR=~/.travis
TRPCPORT=46657
TP2PPORT=46656
ERPCPORT=8545
RSTEP=10
seeds="127.0.0.1:$TP2PPORT"
# init params
if [ -z $INST_COUNT ]; then
INST_COUNT=1
CLEAR='-'
else
if [[ ! $INST_COUNT =~ ^[0-9]+$ ]]; then
if [ $INST_COUNT == "$CLS" ]; then
CLEAR="$CLS"
fi
if [ $INST_COUNT == "$MV" ]; then
CLEAR="$MV"
fi
INST_COUNT=1
else
if [ -z $CLEAR ]; then
CLEAR='-'
fi
fi
fi
# init seeds
# for now only 46656 one node included
if [ $INST_COUNT -gt 1 ]; then
for i in `seq 2 $INST_COUNT`
do
tp2pport=$(($TP2PPORT + $i * $RSTEP))
# seeds="$seeds,127.0.0.1:$tp2pport"
done
fi
# change several ports to specific with step as 10
modifyConf()
{
dir=$1
seq=$2
trpcport=$(($TRPCPORT + $seq * $RSTEP))
tp2pport=$(($TP2PPORT + $seq * $RSTEP))
erpcport=$(($ERPCPORT + $seq * $RSTEP))
cd $dir
cp $BASE_DIR/genesis.json .
sed -i '' "s/$TRPCPORT/$trpcport/g" ./config.toml
sed -i '' "s/$TP2PPORT/$tp2pport/g" ./config.toml
sed -i '' "s/$ERPCPORT/$erpcport/g" ./config.toml
sed -i '' "s/seeds = \"\"/seeds = \"$seeds\"/g" ./config.toml
}
# kill running travis first
rc=`ps aux | grep "[t]ravis node start" | wc -l`
if [ $rc -ne 0 ] ; then
ps aux | grep "[t]ravis node start" | awk '{print $2}' | xargs kill
fi
while true
do
c=`ps aux | grep "[t]ravis node start" | awk '{print $2}' | wc -l`
if [ $c -ne 0 ]; then
echo 'stopping old travis nodes'
sleep 1
else
break
fi
done
if [ $INST_COUNT -eq 0 ]; then
exit
fi
cd
for i in `seq 1 $INST_COUNT`
do
if [ $i -ne 1 ]; then
# seq is empty string for the first instance
seq=$(($i - 1))
fi
dir=$BASE_DIR$seq
# make .travis* directory if not exist
if [ ! -d "$dir" ]; then
mkdir $dir
newnode=1
else
newnode=0
fi
cd $dir
if [ $CLEAR == "$CLS" ] || [ $newnode -eq 1 ] ; then
rm -rf *
travis node init --home .
if [ $i -ne 1 ]; then
modifyConf $dir $seq
else
sed -i '' "s/seeds = \"\"/seeds = \"$seeds\"/g" ./config.toml
fi
fi
if [ $CLEAR == "$MV" ] ; then
# ....
cd ..
rm -rf $dir
cp -r ~/.o_travis/.travis$seq ~
cd $dir
# ....
fi
if [ $INST_COUNT -eq 1 ]; then
travis node start --home .
else
travis node start --home . > travis.log 2>&1 &
fi
done