From abfff66d536ed3c9a42c5b5c86114711fdfb445f Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Thu, 6 Sep 2018 12:59:47 -0700 Subject: [PATCH] Retry ssh a couple times before giving up --- scripts/gcloud.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/gcloud.sh b/scripts/gcloud.sh index 7919060e5..c7d17d5a7 100644 --- a/scripts/gcloud.sh +++ b/scripts/gcloud.sh @@ -218,7 +218,18 @@ gcloud_FigureRemoteUsername() { # instance is reported as RUNNING and when it's reachable over the network timeout 30s bash -c "set -o pipefail; until ping -c 3 $publicIp | tr - _; do echo .; done" - gcloud compute ssh "$name" --zone "$zone" -- "echo whoami:\$USER:iamwho" | tr -d $'\r '| tee /tmp/whoami-$$ + # Try to ssh in a couple times, sshd may not yet be up even though the + # machine can be pinged... + set -o pipefail + for i in $(seq 1 10); do + if gcloud compute ssh "$name" \ + --zone "$zone" -- "echo whoami:\$USER:iamwho" \ + | tr -d $'\r '| tee /tmp/whoami-$$; then + break + fi + sleep 1 + echo "Retry $i..." + done ) while IFS=: read -r whoami gcloud_username iamwho ; do [[ $whoami == "whoami" && $iamwho == "iamwho" ]] && break;