-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy_storage.sh
More file actions
executable file
·128 lines (114 loc) · 3.56 KB
/
Copy pathdeploy_storage.sh
File metadata and controls
executable file
·128 lines (114 loc) · 3.56 KB
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
#!/bin/bash
# Usage - ./deploy_storage.sh
USERNAME=$(cat config.yaml | shyaml get-value remote_user)
DOCKER_USER=$(cat config.yaml | shyaml get-value docker_user)
DOCKER_PASS=$(cat config.yaml | shyaml get-value docker_pass)
SSERVERS=()
NSERVERS=()
for ((i=0; i<16; i++)); do
SSERVERS[i]=$(cat config.yaml | shyaml get-values storage_nodes.$i.ips)
NSERVERS[i]=$(cat config.yaml | shyaml get-value storage_nodes.$i.number)
done
PORT=4000
DIST=()
N=4
get_unique_snodes(){
declare -A items=()
for ((i=0; i<16; i++)); do
for item in ${SSERVERS[i]}; do
items[$item]=1
done
done
SUNIQUE=(${!items[*]})
echo "SUNIQUE is "
echo ${SUNIQUE[@]}
}
setup_deps() {
echo "--- Setting up dependencies"
# Setup docker
for ((i = 0; i < ${#SUNIQUE[@]}; i++)); do
# Setup docker only if docker not already present
ssh ${USERNAME}@${SUNIQUE[i]} '
if [ -x "$(command -v docker)" ]; then
:
else
(curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - ) &> /dev/null
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" &> /dev/null
sudo apt-get update &> /dev/null
sudo apt-get install -y docker-ce=18.06.1~ce~3-0~ubuntu &> /dev/null
sudo usermod -a -G docker $USER &> /dev/null
fi
' &
done
wait
# Login and pull storage image
for ((i = 0; i < ${#SUNIQUE[@]}; i++)); do
ssh ${USERNAME}@${SUNIQUE[i]} "
docker login -u ${DOCKER_USER} -p ${DOCKER_PASS} &> /dev/null
docker pull ${DOCKER_USER}/rainblock:mainStore &> /dev/null
" &
done
wait
}
# Gives the number of containers in each machine
# Distributes containers uniformly
# Override the DIST array to change the distribution
get_distribution() {
for ((i=0; i<16; i++)); do
NUM=(${SSERVERS[i]})
QUANT=$(( ${NSERVERS[i]}/${#NUM[@]} ))
for ((j = 0; j < ${#NUM[@]}-1; j++)); do
DIST[i]+=$QUANT
DIST[i]+=" "
done
REM=$(( ${NSERVERS[i]} - $QUANT*(${#NUM[@]}-1) ))
DIST[i]+=$REM
# echo "Container distribution for $i: ${DIST[i]} "
done
}
stop_all_storage_container() {
echo "--- Removing older storage containers"
for ((i = 0; i < ${#SUNIQUE[@]}; i++)); do
ssh ${USERNAME}@${SUNIQUE[i]} "
docker ps --filter name=sstore$k-* -aq | xargs docker stop | xargs docker rm &> /dev/null
" &
done
}
setup_storage_container() {
mv storage_ips.txt storage_ips.copy
stop_all_storage_container
echo "--- Starting storage nodes"
echo "storage:" >> storage_ips.txt
for ((k = 0; k < 16; k++)); do
echo -e "\t$k:" >> storage_ips.txt
SARRAY=(${SSERVERS[k]})
DISTARRAY=(${DIST[k]})
for ((i = 0; i < ${#SARRAY[@]}; i++)); do
for ((j = 0; j < ${DISTARRAY[i]}; j++)); do
((l=l%N)); ((l++==0)) && wait
ssh ${USERNAME}@${SARRAY[i]} "
docker run --name sstore$k-$j -p $(( PORT+k*100+j )):50051 -d ${DOCKER_USER}/rainblock:mainStore node -r ts-node/register src/server.ts $k 50051 &> /dev/null
" &
echo -e "\t\t- '${SARRAY[i]}:$(( PORT+100*k+j ))'" >> storage_ips.txt
done
done
wait
done
}
test_container() {
# Testing storage deployment
for ((i = 0; i < ${#SUNIQUE[@]}; i++)); do
ssh ${USERNAME}@${SUNIQUE[i]} '
docker container ls
' &
done
}
finish_storage_config() {
echo -e "rpc:\n\tstorageTimeout: 5000\nbeneficiary: 'ea674fdde714fd979de3edf0f56aa9716b898ec8'\ngenesisBlock: 'genesis.bin'" >> storage_ips.txt
}
get_unique_snodes
setup_deps
get_distribution
setup_storage_container
test_container
finish_storage_config