forked from CyberMiles/travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
travis-cluster.sh
executable file
·116 lines (94 loc) · 1.9 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
#!/bin/bash
INST_COUNT=$1
CLEAR=$2
CLS='--clear'
BASE_DIR=~/.travis
TRPCPORT=26657
TP2PPORT=26656
ERPCPORT=8545
RSTEP=10
#seeds="127.0.0.1:$TP2PPORT"
seeds=""
shopt -s extglob
# 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
INST_COUNT=1
else
if [ -z $CLEAR ]; then
CLEAR='-'
fi
fi
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/config
cp $BASE_DIR/config/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 !(eni)
travis node init --home .
if [ $i -ne 1 ]; then
modifyConf $dir $seq
else
v_node_id=`travis node show_node_id --home .`
seeds="[email protected]:$TP2PPORT"
fi
fi
cd $dir
if [ $INST_COUNT -eq 1 ]; then
travis node start --home .
else
travis node start --home . > travis.log 2>&1 &
fi
done