Skip to content

Commit f2e56cf

Browse files
authored
Merge pull request #3 from zelcash/fluxkdahardfork
Fix in case of curl Download doesn't end properly
2 parents 92f9144 + 779bfd1 commit f2e56cf

File tree

1 file changed

+90
-34
lines changed

1 file changed

+90
-34
lines changed

initialize-db.sh

Lines changed: 90 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,95 @@
11
#!/usr/bin/env bash
22

3+
# Retries a command a configurable number of times with backoff.
4+
#
5+
# The retry count is given by ATTEMPTS (default 5), the initial backoff
6+
# timeout is given by TIMEOUT in seconds (default 1.)
7+
#
8+
# Successive backoffs double the timeout.
9+
function with_backoff() {
10+
local max_attempts=${ATTEMPTS-5}
11+
local timeout=${TIMEOUT-1}
12+
local attempt=1
13+
local exitCode=0
14+
15+
while (($attempt < $max_attempts)); do
16+
if "$@"; then
17+
echo "Bootstrap downloaded creating $DBDIR"
18+
mkdir -p "$DBDIR"
19+
echo "Extracting bootstrap to $DBDIR"
20+
tar -xzvf bootstrap.tar.gz -C "$DBDIR"
21+
rm bootstrap.tar.gz
22+
echo "Bootstrap extract finish"
23+
return 0
24+
else
25+
exitCode=$?
26+
fi
27+
28+
echo "Failure! Retrying in $timeout.." 1>&2
29+
sleep $timeout
30+
attempt=$((attempt + 1))
31+
timeout=$((timeout * 2))
32+
done
33+
34+
if [[ $exitCode != 0 ]]; then
35+
rm -rf /data/chainweb-db/
36+
echo "Failed for the last time! ($@)" 1>&2
37+
fi
38+
39+
return $exitCode
40+
}
41+
342
DBDIR="/data/chainweb-db/0"
443
# Double check if dbdir already exists, only download bootstrap if it doesn't
5-
if [ -d $DBDIR ]
6-
then
7-
echo "Directory $DBDIR already exists, we will not download any bootstrap, if you want to download the bootstrap you need to delete the folder first"
44+
if [ -d $DBDIR ]; then
45+
echo "Directory $DBDIR already exists, we will not download any bootstrap, if you want to download the bootstrap you need to delete chainweb-db folder first"
846
else
9-
echo "$DBDIR does not exists, lets download the bootstrap"
10-
# Getting Kadena bootstrap from Zel Servers
11-
BOOTSTRAPLOCATIONS[0]="https://cdn-1.fluxos.network/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
12-
BOOTSTRAPLOCATIONS[1]="https://cdn-2.fluxos.network/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
13-
BOOTSTRAPLOCATIONS[2]="https://cdn-3.fluxos.network/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
14-
BOOTSTRAPLOCATIONS[3]="https://cdn-4.fluxos.network/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
15-
16-
httpstatus=0
17-
retry=0
18-
while [ $httpstatus != "200" ] && [ "$retry" -lt 3 ]
19-
do
20-
index=$(shuf -i 0-3 -n 1)
21-
echo "Testing bootstrap location ${BOOTSTRAPLOCATIONS[$index]}"
22-
httpstatus=$(curl --write-out '%{http_code}' --silent --connect-timeout 5 --head --output /dev/null ${BOOTSTRAPLOCATIONS[$index]})
23-
echo "Http status $httpstatus"
24-
retry=`expr $retry + 1`
25-
done
26-
27-
if [ $httpstatus == "200" ]
28-
then
29-
echo "Bootstrap location valid"
30-
echo "Downloading bootstrap and extract it to $DBDIR"
31-
# Install database
32-
mkdir -p "$DBDIR" && \
33-
curl "${BOOTSTRAPLOCATIONS[$index]}" | tar -xzC "$DBDIR"
34-
35-
echo "Bootstrap downloaded and extracted"
36-
else
37-
echo "None bootstrap was found, will download blockchain from node peers"
38-
fi
39-
fi
47+
echo "$DBDIR does not exists, lets download the bootstrap"
48+
# Getting Kadena bootstrap from Zel Servers
49+
BOOTSTRAPLOCATIONS[0]="https://cdn-1.fluxos.network/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
50+
BOOTSTRAPLOCATIONS[1]="https://cdn-2.fluxos.network/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
51+
BOOTSTRAPLOCATIONS[2]="https://cdn-3.fluxos.network/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
52+
BOOTSTRAPLOCATIONS[3]="https://cdn-4.fluxos.network/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz"
53+
BOOTSTRAPLOCATIONS[4]="http://62.171.173.1:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=893c39e311f349811f23d947714b8a3771e714405379c2ff68a45d69de00cea0"
54+
BOOTSTRAPLOCATIONS[5]="http://76.67.214.247:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=eec3f873005bce7feee77a67301e201c403ffa74d37686af06fed676accd3d48"
55+
BOOTSTRAPLOCATIONS[6]="http://62.171.147.231:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=35ada1ffb536c4a07caf668dd51bff4c7a31c38b682408b14f8b6a0377404e29"
56+
BOOTSTRAPLOCATIONS[7]="http://208.87.129.222:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=28519ea8a949df9a900154eb003a0fb1226d1f2fe44de38ef5d608cac75f4012"
57+
BOOTSTRAPLOCATIONS[8]="http://95.111.241.12:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=6aca11597a823d15e25fc2d9454ceb88a51cc018c9138008974acba982028cd1"
58+
BOOTSTRAPLOCATIONS[9]="http://207.180.248.154:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=9e2102c5ab0434c9c7704aeee963c2d26d3c9cc94762a7eecc1f6d4fe83ff02a"
59+
BOOTSTRAPLOCATIONS[10]="http://193.188.15.155:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=8dc2f09222b538a1630d6b312cfcff9d622bf262e3dc3e55f5217b21f36f95e2"
60+
BOOTSTRAPLOCATIONS[11]="http://62.171.190.234:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=b02d68e451f65361544b734320978dc194d734dae877f53925987c5b12fc5370"
61+
BOOTSTRAPLOCATIONS[12]="http://173.249.46.102:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=7e0f1644205d2b40d7ba16c91e6f023f1cb3dbdab5b3bfdf654944a22c9f0396"
62+
BOOTSTRAPLOCATIONS[13]="http://173.249.51.34:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=0919d90f2d7af3f43be9c08f2415a25afd30751817063f579acb7427ac0afde6"
63+
BOOTSTRAPLOCATIONS[14]="http://193.188.15.152:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=d78131144a1e5e2a0a5a9e19129668b4d9ffeb42b7818dc4ba55b5a9698280da"
64+
BOOTSTRAPLOCATIONS[15]="http://193.188.15.154:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=c0eab364891467eb443974533615bede91526a8e453b8267a584ee7ee6b6cb46"
65+
BOOTSTRAPLOCATIONS[16]="http://95.111.251.163:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=daa05a6a7e6f8ca43cfd6dab3ec752cc0d80be50db6733030895807a58ad2680"
66+
BOOTSTRAPLOCATIONS[17]="http://173.212.192.3:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=7d3c928566ce42f0186e19785af27483bb831ecfd90f9a584c9cfea30dc1603e"
67+
BOOTSTRAPLOCATIONS[18]="http://207.180.244.43:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=26124b7e7daac293648d69fab860669f35b8ed55becd35150a396fc5f7134e26"
68+
BOOTSTRAPLOCATIONS[19]="http://207.180.235.244:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=1fe7b40c4adfb5e1dc05c96458d0c6b2c7758ea3265ce8f19d60d0b0d8e611a1"
69+
BOOTSTRAPLOCATIONS[20]="http://207.180.244.236:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=9e00fe048c05117622621c82e8dd7e80445884c2ea00b4b47ae17fa369c79a31"
70+
BOOTSTRAPLOCATIONS[21]="http://161.97.154.69:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=d9c51c1306a1bdfe0a8424fa2d101a418bea4e0d38b939bb16245424f02426b9"
71+
BOOTSTRAPLOCATIONS[22]="http://207.180.250.106:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=09a7392d1bdfb184ab2c2af84ed8148dde6c621a1e98505c117238610cd0c65d"
72+
BOOTSTRAPLOCATIONS[23]="http://207.180.240.218:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=e12c9a4eb93d489b7e431fc0ca71696aa01af6cacea0a7d5184df695ceb4ba6c"
73+
BOOTSTRAPLOCATIONS[24]="http://193.188.15.153:16127/zelapps/zelshare/getfile/db-chainweb-node-ubuntu.18.04-latest.tar.gz?token=18c77c36d1db8d7b81a5a9066d9cacd465b906c41fd763a4490b3c5e1edc2ddb"
74+
75+
httpstatus=0
76+
retry=0
77+
while [ $httpstatus != "200" ] && [ "$retry" -lt 3 ]; do
78+
index=$(shuf -i 0-24 -n 1)
79+
echo "Testing bootstrap location ${BOOTSTRAPLOCATIONS[$index]}"
80+
httpstatus=$(curl --write-out '%{http_code}' --silent --connect-timeout 5 --head --output /dev/null ${BOOTSTRAPLOCATIONS[$index]})
81+
echo "Http status $httpstatus"
82+
retry=$(expr $retry + 1)
83+
done
84+
85+
if [ $httpstatus == "200" ]; then
86+
echo "Bootstrap location valid"
87+
echo "Downloading bootstrap"
88+
# Install database
89+
with_backoff curl --keepalive-time 30 \
90+
-C - \
91+
-o bootstrap.tar.gz "${BOOTSTRAPLOCATIONS[$index]}"
92+
else
93+
echo "None bootstrap was found, will download blockchain from node peers"
94+
fi
95+
fi

0 commit comments

Comments
 (0)