-
Notifications
You must be signed in to change notification settings - Fork 1
/
joining.sh
executable file
·115 lines (92 loc) · 3.16 KB
/
joining.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
#!/bin/bash
start_time=$(date '+%s')
M=$1
total_node_nums=$2
sever_index=$3
number_of_server=$4
parameter_array=("$@")
server_array=()
node_nums=$((total_node_nums / number_of_server))
ports=13000
node=$((sever_index * node_nums))
for ((i=4; i<${#parameter_array[@]}; i++)); do
server_array+=("${parameter_array[i]}")
done
echo Parameter initialize done! Mode $M, node scale $total_node_nums, number of server $number_of_server
echo "${server_array}"
sleep 1
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Mode 1 is initialize Bootstrap and join nodes
if [ $M -eq 1 ];
then
echo Mode 1 start
pkill -9 python3
source ~/anaconda3/bin/activate base
# Bootstrap ~ Node(node_nums -1) join
while [ $node -lt $node_nums ]; do
if [ $ports = '13000' ]
then
(SERVER_ARRAY=$(IFS=,; echo "${server_array[*]}") python3 Main.py --bootstrap=True --port=$ports --node_num=$node) &
echo Bootstrap initialized!
((ports++))
((node++))
sleep 1
else
echo Node $node join!
(SERVER_ARRAY=$(IFS=,; echo "${server_array[*]}") python3 Main.py --port=$ports --node_num=$node) &
while true; do
if tail -n 1 log.txt | grep -q "Queue reset!($node)"; then
((ports++))
((node++))
break
fi
sleep 1
done
fi
done
# server_array index++
((sever_index++))
echo "${server_array[$sever_index]} , $sever_index"
# send to next server(Mode 2) to join Nodes
ssh -p 6304 user@${server_array[$sever_index]} "source ~/anaconda3/bin/activate base; cd pyCAN; ./joining.sh 2 $total_node_nums $sever_index $number_of_server ${server_array[@]}"
#----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Mode 2 is Node join from other servers and last server send Mode 3 to original server
elif [ $M -eq 2 ];
then
echo Mode 2 start
if [ $sever_index -lt $number_of_server ];
then
pkill -9 python3
ip_node_nums=`expr "$sever_index" \* "$node_nums"`
ports=`expr "$ports" + "$ip_node_nums"`
node=$ip_node_nums
while [ $node -lt `expr "$node_nums" + "$ip_node_nums"` ]; do
echo Node $node join!
SERVER_ARRAY=$(IFS=,; echo "${server_array[*]}") python3 Main.py --port=$ports --node_num=$node &
while true; do
if tail -n 1 log.txt | grep -q "Queue reset!($node)"; then
((ports++))
((node++))
break
fi
sleep 1
done
done
# server_array index ++
((sever_index++))
if [ $sever_index -ne $number_of_server ];
then
# send to next server(Mode 2) to join Nodes
ssh -p 6304 user@${server_array[$sever_index]} "source ~/anaconda3/bin/activate base; cd pyCAN; ./joining.sh 2 $total_node_nums $sever_index $number_of_server ${server_array[@]}"
fi
else
echo Last server join done! Please check your parameters
fi
echo done!
fi
end_time=$(date '+%s')
diff=$((end_time - start_time))
hour=$((diff / 3600 % 24))
minute=$((diff / 60 % 60))
second=$((diff % 60))
echo "$hour hour $minute minute $second second"