Skip to content

Commit 5166655

Browse files
irek-makowskiIreneusz Makowski
andauthored
Retry upon 404 and exit if always 404 #207 (#233)
* Changed only description because default of autoupgrade is set to N * Retry upon 404 and exit if always 404 #207 * Retry upon 404 and exit if always 404 #207 - improved reliability of downloads * Retry upon 404 and exit if always 404 #207 - improved reliability of downloads * New function for download Co-authored-by: Ireneusz Makowski <Ireneusz.Makowski@3ds.com>
1 parent 67eb3f4 commit 5166655

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

scripts/setup_fullnode.sh

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,22 @@ function deleteOldFile() {
116116
fi
117117
}
118118

119+
function downloadFile()
120+
{
121+
echo "Downloading file: $1"
122+
curl -Ss --connect-timeout 10 \
123+
--max-time 10 \
124+
--retry 10 \
125+
--retry-delay 0 \
126+
--retry-max-time 180 \
127+
$1 > $2
128+
response=$?
129+
if test "$response" != "0"; then
130+
echo -e "${RED} Download of configuration failed with following: $response"
131+
exit 1
132+
fi
133+
}
134+
119135
function preDockerCompose() {
120136
# set monitor home
121137
IOTEX_MONITOR_HOME=$IOTEX_HOME/monitor
@@ -124,15 +140,15 @@ function preDockerCompose() {
124140

125141
export IOTEX_HOME IOTEX_MONITOR_HOME IOTEX_IMAGE
126142

127-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml.gateway > $IOTEX_MONITOR_HOME/docker-compose.yml.gateway
128-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml > $IOTEX_MONITOR_HOME/docker-compose.yml.default
129-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/.env > $IOTEX_MONITOR_HOME/.env
143+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml.gateway" "$IOTEX_MONITOR_HOME/docker-compose.yml.gateway"
144+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/docker-compose.yml" "$IOTEX_MONITOR_HOME/docker-compose.yml.default"
145+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/.env" "$IOTEX_MONITOR_HOME/.env"
130146
}
131147

132148
function enableMonitor() {
133149
echo "Download config files for monitor"
134-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/prometheus.yml > $IOTEX_MONITOR_HOME/prometheus.yml
135-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/alert.rules > $IOTEX_MONITOR_HOME/alert.rules
150+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/prometheus.yml" "$IOTEX_MONITOR_HOME/prometheus.yml"
151+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/monitor/alert.rules" "$IOTEX_MONITOR_HOME/alert.rules"
136152
}
137153

138154
function checkPrivateKey() {
@@ -215,13 +231,13 @@ function determinPrivKey() {
215231

216232
function downloadConfig() {
217233
echo "download new config"
218-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/config_${env}.yaml > $IOTEX_HOME/etc/config.yaml
219-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/genesis_${env}.yaml > $IOTEX_HOME/etc/genesis.yaml
234+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/config_${env}.yaml" "$IOTEX_HOME/etc/config.yaml"
235+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/genesis_${env}.yaml" "$IOTEX_HOME/etc/genesis.yaml"
220236

221237
#Download patch file
222238
if [ "${_ENV_}X" = "mainnetX" ];then
223239
echo -e "Downloading the patch file"
224-
curl https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/trie.db.patch > $IOTEX_HOME/data/trie.db.patch
240+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/trie.db.patch" "$IOTEX_HOME/data/trie.db.patch"
225241
fi
226242

227243
SED_IS_GNU=0
@@ -340,12 +356,12 @@ function startAutoUpdate() {
340356
# Download auto-update command
341357
mkdir -p $IOTEX_HOME/bin
342358
if [ "$(uname)"X = "Darwin"X ];then
343-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/tools/auto-update/auto-update_darwin-amd64 > $IOTEX_HOME/bin/auto-update || exit 1
359+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/tools/auto-update/auto-update_darwin-amd64" "$IOTEX_HOME/bin/auto-update" || exit 1
344360
else
345-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/tools/auto-update/auto-update_linux-amd64 > $IOTEX_HOME/bin/auto-update || exit 1
361+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/tools/auto-update/auto-update_linux-amd64" "$IOTEX_HOME/bin/auto-update" || exit 1
346362
fi
347363

348-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/scripts/update_silence.sh > $IOTEX_HOME/bin/update_silence.sh || exit 1
364+
downloadFile "https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/master/scripts/update_silence.sh" "$IOTEX_HOME/bin/update_silence.sh" || exit 1
349365
chmod +x $IOTEX_HOME/bin/auto-update $IOTEX_HOME/bin/update_silence.sh
350366

351367
# Run background

scripts/update_silence.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,31 @@ function downloadConfig() {
8686
#curl -LSs https://t.iotex.me/${env}-data-latest > $IOTEX_HOME/data.tar.gz
8787
#cd ${IOTEX_HOME} && tar -xzf data.tar.gz
8888
echo "download new config"
89-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/config_${_ENV_}.yaml > $IOTEX_HOME/etc/config.yaml
90-
curl -Ss https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/genesis_${_ENV_}.yaml > $IOTEX_HOME/etc/genesis.yaml
89+
curl -Ss --connect-timeout 10 \
90+
--max-time 10 \
91+
--retry 10 \
92+
--retry-delay 0 \
93+
--retry-max-time 40 \
94+
https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/config_${_ENV_}.yaml > $IOTEX_HOME/etc/config.yaml
95+
96+
response=$?
97+
if test "$response" != "0"; then
98+
echo -e "${RED} Download of default configuration failed with: $response"
99+
exit 1
100+
fi
101+
102+
curl -Ss --connect-timeout 10 \
103+
--max-time 10 \
104+
--retry 10 \
105+
--retry-delay 0 \
106+
--retry-max-time 40 \
107+
https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/${version}/genesis_${_ENV_}.yaml > $IOTEX_HOME/etc/genesis.yaml
108+
109+
response=$?
110+
if test "$response" != "0"; then
111+
echo -e "${RED} Download of genesis configuration failed with: $response"
112+
exit 1
113+
fi
91114
# https://raw.githubusercontent.com/iotexproject/iotex-bootstrap/v0.9.2/config_mainnet.yaml
92115

93116
SED_IS_GNU=0

0 commit comments

Comments
 (0)