From 4fbae084ec4d8769e0a1cce994435e0d2a5f37df Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Mon, 4 Jul 2016 12:20:34 +1000 Subject: [PATCH 1/7] Add retrying loop code to installer. This is code as seen on install.meteor.com, seems to be working there (https://github.com/meteor/meteor/issues/6960#issuecomment-229817525) --- scripts/admin/launch-meteor | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/scripts/admin/launch-meteor b/scripts/admin/launch-meteor index cd31ad23ce..22815bcf3c 100755 --- a/scripts/admin/launch-meteor +++ b/scripts/admin/launch-meteor @@ -82,15 +82,36 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then fi echo "Installing a Meteor distribution in your home directory." 1>&2 - # Only show progress bar animations if we have a tty - # (Prevents tons of console junk when installing within a pipe) - if [[ -t 1 ]]; then - curl --progress-bar --fail "$TARBALL_URL" | tar -xzf - -C "$INSTALL_TMPDIR" - else - curl -s --fail "$TARBALL_URL" | tar -xzf - -C "$INSTALL_TMPDIR" - fi + TARBALL_FILE="$(dirname "$METEOR_WAREHOUSE_DIR")/.meteor-tarball-tmp" + rm -rf "$TARBALL_FILE" + + echo "Downloading Meteor distribution" + # keep trying to curl the file until it works (resuming where possible) + MAX_ATTEMPTS=99 + set +e + CODE=1 + ATTEMPTS=0 + while [ $CODE -ne 0 ] && [ $ATTEMPTS -lt $MAX_ATTEMPTS ] + do + ATTEMPTS=$((ATTEMPTS + 1)) + + # Only show progress bar animations if we have a tty + # (Prevents tons of console junk when installing within a pipe) + if [[ -t 1 ]]; then + curl --progress-bar --fail "$TARBALL_URL" -C - -o "$TARBALL_FILE" + else + curl -s --fail "$TARBALL_URL" -C - -o "$TARBALL_FILE" + fi + + CODE=$? + done + set -e # bomb out if it didn't work, eg no net + test -e "${TARBALL_FILE}" + tar -xzf "$TARBALL_FILE" -C "$INSTALL_TMPDIR" -o + rm -rf "$TARBALL_FILE" + test -x "${INSTALL_TMPDIR}/.meteor/meteor" mv "${INSTALL_TMPDIR}/.meteor" "$METEOR_WAREHOUSE_DIR" rmdir "${INSTALL_TMPDIR}" From 2860ab29ca541d738d3b91fc04d90735adc920eb Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Wed, 6 Jul 2016 11:48:12 +1000 Subject: [PATCH 2/7] Use sh compatible code (so we can have the exact same snippet as the installer). See https://github.com/meteor/meteor/pull/7348#discussion_r69518729 --- scripts/admin/launch-meteor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/admin/launch-meteor b/scripts/admin/launch-meteor index 22815bcf3c..7381f8f584 100755 --- a/scripts/admin/launch-meteor +++ b/scripts/admin/launch-meteor @@ -97,7 +97,7 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then # Only show progress bar animations if we have a tty # (Prevents tons of console junk when installing within a pipe) - if [[ -t 1 ]]; then + if [ -t 1 ]; then curl --progress-bar --fail "$TARBALL_URL" -C - -o "$TARBALL_FILE" else curl -s --fail "$TARBALL_URL" -C - -o "$TARBALL_FILE" From 5640fc3290289f21fca5dc2da51fcdd619f46219 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 6 Jul 2016 14:04:26 -0400 Subject: [PATCH 3/7] Make curl arguments slightly more readable. --- scripts/admin/launch-meteor | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/admin/launch-meteor b/scripts/admin/launch-meteor index 7381f8f584..8282014223 100755 --- a/scripts/admin/launch-meteor +++ b/scripts/admin/launch-meteor @@ -98,9 +98,11 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then # Only show progress bar animations if we have a tty # (Prevents tons of console junk when installing within a pipe) if [ -t 1 ]; then - curl --progress-bar --fail "$TARBALL_URL" -C - -o "$TARBALL_FILE" + curl --progress-bar --fail --continue-at - \ + "$TARBALL_URL" --output "$TARBALL_FILE" else - curl -s --fail "$TARBALL_URL" -C - -o "$TARBALL_FILE" + curl --silent --fail --continue-at - \ + "$TARBALL_URL" --output "$TARBALL_FILE" fi CODE=$? From 10773b36a161ef11815847a430b549f945420329 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 6 Jul 2016 14:04:04 -0400 Subject: [PATCH 4/7] Different .part files for different $TARBALL_URLs. --- scripts/admin/launch-meteor | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/admin/launch-meteor b/scripts/admin/launch-meteor index 8282014223..38cc1dfc18 100755 --- a/scripts/admin/launch-meteor +++ b/scripts/admin/launch-meteor @@ -82,7 +82,10 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then fi echo "Installing a Meteor distribution in your home directory." 1>&2 - TARBALL_FILE="$(dirname "$METEOR_WAREHOUSE_DIR")/.meteor-tarball-tmp" + # Generate the $TARBALL_FILE path based on $TARBALL_URL, but with unsafe + # characters replaced by underscores. + PART_FILE=".meteor-${TARBALL_URL//[^A-Za-z0-9_.-]/_}.part" + TARBALL_FILE="$(dirname "$METEOR_WAREHOUSE_DIR")/${PART_FILE}" rm -rf "$TARBALL_FILE" echo "Downloading Meteor distribution" From 876e122e63a5c28500f54dbf46e8cdfb1276d84b Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 6 Jul 2016 14:31:59 -0400 Subject: [PATCH 5/7] Ensure launch-meteor temporary files always get cleaned up. --- scripts/admin/launch-meteor | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/scripts/admin/launch-meteor b/scripts/admin/launch-meteor index 38cc1dfc18..4557d526af 100755 --- a/scripts/admin/launch-meteor +++ b/scripts/admin/launch-meteor @@ -73,7 +73,23 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then TARBALL_URL="${TMP_ROOT_URL}/meteor-bootstrap-${PLATFORM}.tar.gz" INSTALL_TMPDIR="$(dirname "$METEOR_WAREHOUSE_DIR")/.meteor-install-tmp" - rm -rf "$INSTALL_TMPDIR" + + # Generate the $TARBALL_FILE path based on $TARBALL_URL, but with unsafe + # characters replaced by underscores. + PART_FILE=".meteor-${TARBALL_URL//[^A-Za-z0-9_.-]/_}.part" + TARBALL_FILE="$(dirname "$METEOR_WAREHOUSE_DIR")/${PART_FILE}" + + cleanUp() { + rm -rf "$TARBALL_FILE" + rm -rf "$INSTALL_TMPDIR" + } + + # Remove temporary files now in case they exist. + cleanUp + + # Make sure cleanUp gets called if we exit abnormally. + trap cleanUp EXIT + mkdir "$INSTALL_TMPDIR" if [ -n "${USER-}" ]; then echo "$USER, this is your first time using Meteor!" 1>&2 @@ -82,12 +98,6 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then fi echo "Installing a Meteor distribution in your home directory." 1>&2 - # Generate the $TARBALL_FILE path based on $TARBALL_URL, but with unsafe - # characters replaced by underscores. - PART_FILE=".meteor-${TARBALL_URL//[^A-Za-z0-9_.-]/_}.part" - TARBALL_FILE="$(dirname "$METEOR_WAREHOUSE_DIR")/${PART_FILE}" - rm -rf "$TARBALL_FILE" - echo "Downloading Meteor distribution" # keep trying to curl the file until it works (resuming where possible) MAX_ATTEMPTS=99 @@ -115,13 +125,15 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then # bomb out if it didn't work, eg no net test -e "${TARBALL_FILE}" tar -xzf "$TARBALL_FILE" -C "$INSTALL_TMPDIR" -o - rm -rf "$TARBALL_FILE" test -x "${INSTALL_TMPDIR}/.meteor/meteor" mv "${INSTALL_TMPDIR}/.meteor" "$METEOR_WAREHOUSE_DIR" - rmdir "${INSTALL_TMPDIR}" # just double-checking :) test -x "$METEOR_WAREHOUSE_DIR/meteor" + + # The `trap cleanUp EXIT` line above won't actually fire after the exec + # call below, so call cleanUp manually. + cleanUp fi exec "$METEOR_WAREHOUSE_DIR/meteor" "$@" From 7c27f966d4158ff6447916bea2485bd016fedb87 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Wed, 6 Jul 2016 15:07:47 -0400 Subject: [PATCH 6/7] Only retry tarball download 10 times, and add a 5 second delay. Hammering the server 98 times after a 404 seems excessive. --- scripts/admin/launch-meteor | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/admin/launch-meteor b/scripts/admin/launch-meteor index 4557d526af..fe627d3f81 100755 --- a/scripts/admin/launch-meteor +++ b/scripts/admin/launch-meteor @@ -100,11 +100,11 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then echo "Downloading Meteor distribution" # keep trying to curl the file until it works (resuming where possible) - MAX_ATTEMPTS=99 + MAX_ATTEMPTS=10 + RETRY_DELAY_SECS=5 set +e - CODE=1 ATTEMPTS=0 - while [ $CODE -ne 0 ] && [ $ATTEMPTS -lt $MAX_ATTEMPTS ] + while [ $ATTEMPTS -lt $MAX_ATTEMPTS ] do ATTEMPTS=$((ATTEMPTS + 1)) @@ -118,7 +118,13 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then "$TARBALL_URL" --output "$TARBALL_FILE" fi - CODE=$? + if [ $? -eq 0 ] + then + break + fi + + echo "Retrying download in $RETRY_DELAY_SECS seconds..." + sleep $RETRY_DELAY_SECS done set -e From 3022186923532cc81bccbf5a1da7a2a7fe46d767 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Thu, 7 Jul 2016 14:06:22 +1000 Subject: [PATCH 7/7] Slightly DRY-ed the install script --- scripts/admin/launch-meteor | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/scripts/admin/launch-meteor b/scripts/admin/launch-meteor index fe627d3f81..1ec76b4280 100755 --- a/scripts/admin/launch-meteor +++ b/scripts/admin/launch-meteor @@ -98,6 +98,14 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then fi echo "Installing a Meteor distribution in your home directory." 1>&2 + + # Only show progress bar animations if we have a tty + # (Prevents tons of console junk when installing within a pipe) + VERBOSITY="--silent"; + if [ -t 1 ]; then + VERBOSITY="--progress-bar" + fi + echo "Downloading Meteor distribution" # keep trying to curl the file until it works (resuming where possible) MAX_ATTEMPTS=10 @@ -108,15 +116,8 @@ if [ ! -x "$METEOR_WAREHOUSE_DIR/meteor" ]; then do ATTEMPTS=$((ATTEMPTS + 1)) - # Only show progress bar animations if we have a tty - # (Prevents tons of console junk when installing within a pipe) - if [ -t 1 ]; then - curl --progress-bar --fail --continue-at - \ - "$TARBALL_URL" --output "$TARBALL_FILE" - else - curl --silent --fail --continue-at - \ - "$TARBALL_URL" --output "$TARBALL_FILE" - fi + curl $VERBOSITY --fail --continue-at - \ + "$TARBALL_URL" --output "$TARBALL_FILE" if [ $? -eq 0 ] then