From b4b67536e95e5e594272727db095c8fd6ec77488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Petazzoni?= Date: Tue, 3 May 2022 11:33:12 +0200 Subject: [PATCH] =?UTF-8?q?=E2=8C=9A=20=EF=B8=8FAdd=20retry=20logic=20for?= =?UTF-8?q?=20linode=20provisioning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It looks like Linode now enforces something like 10 requests / 10 seconds. We need to add some retry logic when provisioning more than 10 VMs. --- prepare-vms/lib/infra/linode.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/prepare-vms/lib/infra/linode.sh b/prepare-vms/lib/infra/linode.sh index df5a28ef..c541963c 100644 --- a/prepare-vms/lib/infra/linode.sh +++ b/prepare-vms/lib/infra/linode.sh @@ -26,12 +26,24 @@ infra_start() { info " Name: $NAME" info " Instance type: $LINODE_TYPE" ROOT_PASS="$(base64 /dev/urandom | cut -c1-20 | head -n 1)" - linode-cli linodes create \ + MAX_TRY=5 + TRY=1 + WAIT=1 + while ! linode-cli linodes create \ --type=${LINODE_TYPE} --region=${LINODE_REGION} \ --image=linode/ubuntu18.04 \ --authorized_keys="${LINODE_SSHKEY}" \ --root_pass="${ROOT_PASS}" \ - --tags=${TAG} --label=${NAME} + --tags=${TAG} --label=${NAME}; do + warning "Failed to create VM (attempt $TRY/$MAX_TRY)." + if [ $TRY -ge $MAX_TRY ]; then + die "Giving up." + fi + info "Waiting $WAIT seconds and retrying." + sleep $WAIT + TRY=$(($TRY+1)) + WAIT=$(($WAIT*2)) + done done sep