Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions utils/build/ssi/base/download_with_retry.sh
Original file line number Diff line number Diff line change
@@ -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"
}
13 changes: 12 additions & 1 deletion utils/build/ssi/base/install_script_ssi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 11 additions & 1 deletion utils/build/ssi/base/install_script_ssi_installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading