- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
Is this happening at the update step, or installing EPEL, or both?
It appears that, as part of the first boot sequence, cloud-init will ensure that any important and critical security issues are addressed (for vulnerabilities that will have come out since the AMI was released). This can be seen by picking through /var/log/cloud-init.log
, the following is from an AL2 instance in my account:
Feb 18 12:02:00 cloud-init[2261]: util.py[DEBUG]: Running command ['yum', '-t', '-y', '--exclude=kernel', '--exclude=nvidia*', '--exclude=cuda*', '--security', '--sec-severity=critical', '--sec-severity=important', 'upgrade'] with allowed return codes [0] (shell=False, capture=False)
Feb 18 12:02:57 cloud-init[2261]: handlers.py[DEBUG]: finish: modules-config/config-package-update-upgrade-install: SUCCESS: config-package-update-upgrade-install ran successfully
You can see what changes are made in /var/log/yum.log
This should finish before the User Data script runs, but it's possible that it hasn't quite finished cleaning up after itself, and the lock file still exists on disk even though cloud-init thinks it's been deleted.
If you put the while
loop before the yum update -y
in your User Data script (as well as the place it's already in) then this should guard against it.
It seems like you're encountering issues with concurrent access to the package manager (yum) on your EC2 instance, resulting in a lock conflict. This typically happens when multiple processes are trying to access yum simultaneously.
To address this issue, you can implement a retry mechanism in your user-data script to wait for the lock to be released before attempting to install packages again. Here's a simple approach using a loop to wait for the lock to be released:
#!/bin/bash
# Function to check if yum is locked
is_yum_locked() {
[ -f /var/run/yum.pid ]
}
# Wait for yum lock to be released
while is_yum_locked; do
echo "Yum lock is present, waiting for release..."
sleep 5 # Adjust the sleep duration as needed
done
# Install your packages here
yum install -y package1 package2 package3
# Additional commands...
This script checks if the yum lock file /var/run/yum.pid exists. If it does, it waits for a few seconds and checks again until the lock is released. Once the lock is released, it proceeds with the installation of packages.
Make sure to adjust the sleep duration according to your specific use case. You might also want to implement a maximum retry limit to prevent infinite looping in case the lock is held for an extended period.
Additionally, consider checking if there are any other processes or scripts running concurrently that might be accessing yum, as these could also contribute to the lock conflicts.
Giovanni, Like I mentioned I already have While loop to check lock before each instruction, but still it's failing in few cases.
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor einem Jahr
- AWS OFFICIALAktualisiert vor einem Jahr
- AWS OFFICIALAktualisiert vor 3 Jahren
Thank you Steve, I added 2 min pause before starting my user-data and have while loop to check for lock. So far it worked fine with no issues. But can u suggest if there any way to start user-data script once cloud-init process is complete? I am creating ec2 using boto3.
I think it's just a peculiarity of
yum
, as you've seen it doesn't happen every time. I've also seen it on the odd occasion on the command line, if you run twoyum
commands one after the other the second one will sometimes complain that the first one hasn't finished (even though it has). It usually fixes itself.If I've got a User Data script that runs
yum
as its first command, I always put in a check like yours to make sure it will run properly. Or I do some other stuff in the script before it, which I know will take a few seconds to run.