Skip to content

feat(runners): add retry logic to default install and start script for dnf operations #3787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 14, 2024
Merged
Changes from 2 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
39 changes: 35 additions & 4 deletions modules/runners/templates/user-data.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
#!/bin/bash -e

install_with_retry() {
max_attempts=5
attempt_count=0
success=false
while [ $success = false ] && [ $attempt_count -le $max_attempts ]; do
echo "Attempting $attempt_count/$max_attempts: Installing $*"
dnf install -y $*
if [ $? -eq 0 ]; then
success=true
else
echo "Failed to install $1 - retrying"
attempt_count=$(( attempt_count + 1 ))
sleep 5
fi
done
}

exec > >(tee /var/log/user-data.log | logger -t user-data -s 2>/dev/console) 2>&1

# AWS suggest to create a log for debug purpose based on https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-log-user-data/
Expand All @@ -15,15 +32,29 @@ set -x

${pre_install}

dnf upgrade-minimal -y
max_attempts=5
attempt_count=0
success=false
while [ $success = false ] && [ $attempt_count -le $max_attempts ]; do
echo "Attempting $attempt_count/$max_attempts: upgrade-minimal"
dnf upgrade-minimal -y
if [ $? -eq 0 ]; then
success=true
else
echo "Failed to run `dnf upgrad-minimal -y` - retrying"
attempt_count=$(( attempt_count + 1 ))
sleep 5
fi
done

# Install docker
dnf install -y docker
install_with_retry docker

service docker start
usermod -a -G docker ec2-user

dnf install -y amazon-cloudwatch-agent jq git
dnf install -y --allowerasing curl
install_with_retry amazon-cloudwatch-agent jq git
install_with_retry --allowerasing curl

user_name=ec2-user

Expand Down