diff --git a/utils/build/ssi/base/download_with_retry.sh b/utils/build/ssi/base/download_with_retry.sh index c06e6249595..a9a9e7dc680 100644 --- a/utils/build/ssi/base/download_with_retry.sh +++ b/utils/build/ssi/base/download_with_retry.sh @@ -1,20 +1,44 @@ #!/bin/bash -download_with_retry() { - local url="$1" - local output - output="$(basename "$url")" +run_with_retry() { + local description="$1" + local max_attempts="$2" + local retry_delay="$3" + shift 3 - local max_attempts=5 local attempt for (( attempt = 1; attempt <= max_attempts; attempt++ )); do - echo "[TRACE] downloading ${output} (attempt ${attempt}/${max_attempts})" - if curl --fail --retry 3 -sSL -o "$output" "$url" && [ -s "$output" ]; then + echo "[TRACE] running ${description} (attempt ${attempt}/${max_attempts})" + if "$@"; then return 0 fi - rm -f "$output" + + if (( attempt < max_attempts )); then + echo "[WARN] ${description} failed; retrying in ${retry_delay} seconds" >&2 + sleep "$retry_delay" + fi done - echo "[ERROR] ${output} is missing or empty after ${max_attempts} attempts" >&2 + echo "[ERROR] ${description} failed after ${max_attempts} attempts" >&2 return 1 } + +_download_once() { + local url="$1" + local output="$2" + + if curl --fail --retry 3 -sSL -o "$output" "$url" && [ -s "$output" ]; then + return 0 + fi + + rm -f "$output" + return 1 +} + +download_with_retry() { + local url="$1" + local output + output="$(basename "$url")" + + run_with_retry "download ${output}" 5 0 _download_once "$url" "$output" +} diff --git a/utils/build/ssi/base/install_script_ssi.sh b/utils/build/ssi/base/install_script_ssi.sh index 1bac8e44551..71f239d0526 100755 --- a/utils/build/ssi/base/install_script_ssi.sh +++ b/utils/build/ssi/base/install_script_ssi.sh @@ -54,7 +54,18 @@ if [ ! -s "install_script_agent7.sh" ]; then exit 1 fi -DD_REPO_URL=${DD_injection_repo_url} DD_INSTALL_ONLY=true DD_APM_INSTRUMENTATION_ENABLED=host bash ./install_script_agent7.sh +if ! run_with_retry \ + "Datadog Agent installer" \ + 3 \ + 5 \ + env \ + "DD_REPO_URL=${DD_injection_repo_url}" \ + DD_INSTALL_ONLY=true \ + DD_APM_INSTRUMENTATION_ENABLED=host \ + bash ./install_script_agent7.sh; then + echo "[ERROR] aborting SSI install after Datadog Agent installer failure" >&2 + exit 1 +fi if [ -f /etc/debian_version ] || [ "$DISTRIBUTION" == "Debian" ] || [ "$DISTRIBUTION" == "Ubuntu" ]; then OS="Debian" diff --git a/utils/build/ssi/base/install_script_ssi_installer.sh b/utils/build/ssi/base/install_script_ssi_installer.sh index 336bda6ede2..9a2abe30633 100755 --- a/utils/build/ssi/base/install_script_ssi_installer.sh +++ b/utils/build/ssi/base/install_script_ssi_installer.sh @@ -5,4 +5,14 @@ source ./download_with_retry.sh download_with_retry https://dd-agent.s3.amazonaws.com/scripts/install_script_agent7.sh || exit 1 -DD_INSTALL_ONLY=true DD_INSTALLER=true bash ./install_script_agent7.sh +if ! run_with_retry \ + "Datadog Agent installer" \ + 3 \ + 5 \ + env \ + DD_INSTALL_ONLY=true \ + DD_INSTALLER=true \ + bash ./install_script_agent7.sh; then + echo "[ERROR] aborting SSI install after Datadog Agent installer failure" >&2 + exit 1 +fi