Skip to content
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

adding logic to handle cloud-init error code 2 #28598

Merged
merged 13 commits into from
Nov 22, 2024
18 changes: 16 additions & 2 deletions enos/modules/install_packages/scripts/synchronize-repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,26 @@ synchronize_repos() {
esac
}

# Function to check cloud-init status and retry on failure
# Before we start to modify repositories and install packages we'll wait for cloud-init to finish
# so it doesn't race with any of our package installations.
# We run as sudo becase Amazon Linux 2 throws Python 2.7 errors when running `cloud-init status` as
# We run as sudo because Amazon Linux 2 throws Python 2.7 errors when running `cloud-init status` as
# non-root user (known bug).
sudo cloud-init status --wait
wait_for_cloud_init() {
sudo cloud-init status --wait
exit_code=$?
# We are not failing exit status 2 because cloud-init is up to date
if [ "$exit_code" -ne 0 ] && [ "$exit_code" -ne 2 ]; then
tvo0813 marked this conversation as resolved.
Show resolved Hide resolved
tvo0813 marked this conversation as resolved.
Show resolved Hide resolved
echo "cloud-init did not complete successfully. Exit code: $exit_code" 1>&2
echo "Here are the logs for the failure:"
cat /var/log/cloud-init-*
fi
}

# Wait for cloud-init
wait_for_cloud_init

# Synchronizing repos
begin_time=$(date +%s)
end_time=$((begin_time + TIMEOUT_SECONDS))
while [ "$(date +%s)" -lt "$end_time" ]; do
Expand Down
Loading