ruk·si

Bash
Download a file with backoff

Updated at 2016-06-19 08:42
#!/bin/bash
set -x # Print command traces before executing the command.

function sleep_delay
{
  if (( $SLEEP_TIME < $SLEEP_TIME_MAX )); then
    echo Sleeping $SLEEP_TIME
    sleep $SLEEP_TIME
    SLEEP_TIME=$(($SLEEP_TIME * 2))
  else
    echo Sleeping $SLEEP_TIME_MAX
    sleep $SLEEP_TIME_MAX
  fi
}

SLEEP_TIME=10
SLEEP_TIME_MAX=319
while true; do
  curl https:///example.com/UserDataScript.sh > /tmp/ebbootstrap.sh
  RESULT=$?
  if [[ "$RESULT" -ne 0 ]]; then
    sleep_delay
  else
    /bin/bash /tmp/ebbootstrap.sh 'param1' 'param2' && exit 0
  fi
done

Source

  • AWS Elastic Beanstalk Bootstrap