aws-codedeploy-agent
aws-codedeploy-agent copied to clipboard
CodeDeploy agent install fails with Could not get lock /var/lib/dpkg/lock
I am trying to install the agent on Ubuntu 16.04 LTS
Like this:
wget https://aws-codedeploy-us-west-2.s3.amazonaws.com/latest/install chmod +x ./install sudo ./install auto
It fails to install. Looking at /tmp/codedeploy-agent.update.log I see that it is failing to install gdebi with this message:
Could not get lock /var/lib/dpkg/lock
This is running during cloud-init.
If I run it manually once cloud-init is done it installs fine.
I think I worked around this.
If I manually do a:
apt-get update apt-get install -y -q gdebi-core
prior to running the codedeploy agent install it runs to completion.
Even with this I get occasional failures like this from /tmp/codedeploy-agent.update.log
I, [2017-01-08T20:09:18.898661 #2373] INFO -- : Downloading package from bucket aws-codedeploy-us-west-2
and key releases/codedeploy-agent_1.0-1.1067_all.deb...
I, [2017-01-08T20:09:19.004921 #2373] INFO -- : Executing /usr/bin/gdebi -n -o Dpkg::Options::=--force-c onfdef -o Dkpg::Options::=--force-confold /tmp/codedeploy-agent_1.0-1.1067_all.tmp-20170108-2373-n4ed0f.de b
...
^MReading state information... Done E, [2017-01-08T20:09:22.220315 #2373] ERROR -- : Error installing /tmp/codedeploy-agent_1.0-1.1067_all.tmp-20170108-2373-n4ed0f.deb.
The host agent has auto-update functions, and it'll periodically check from the s3 bucket, and see if there is a new version of host agent has been released or not. The codedeploy-agent.update.log is mainly for this logging information. Are you running the host agent on one of the EC2 instances? If it's public, do you mind share with me the instance AMI? The log doesn't provide much information, I'd like to try and see if I can reproduce. Or is there any more logs before/after the ERROR message?
Thanks, Binbin
This is a new Ubuntu 16.04 LTS instance installing codedeploy-agent during cloud-init.
It does not currently have the agent on it.
Is the host agent the codedeploy-agent or something different?
Hi,
The install script and the updater download a deb and try to install it. So something else is already running some apt operations, the installation will fail with the "could not get lock" error.
As far as as the updater is concerned, if it fails to install the deb, it will try again an hour later. But as far as failures in the cloud init script is concerned, you need to find out what is holding the lock on the /var/lib/dpkg/lock
Thanks, Amartya Datta Gupta
This is the initial install. So when it fails there is nothing to run and update later.
The lock is not taken by anything in my script. It must be something that Ubuntu 16.04 is updating behind the schenes or something pre-installed in the AMI updating.
Finally got past the issue with this trick:
until service codedeploy-agent status >/dev/null 2>&1; do
sleep 60
rm -f install
wget https://aws-codedeploy-us-west-2.s3.amazonaws.com/latest/install
chmod +x ./install
sudo ./install auto
service codedeploy-agent restart
done
Seems like I shouldn't have to do the above. The install script should just handle it.
This is a good suggestion. I will add a feature backlog for the install script to wait out the locks on the package management. Thanks a lot for the input!
Thanks, Amartya
@amartyag is this feature added?, I'm having the exact same problem with Ubuntu 16.04 I will try @chriskinsman suggestion
just fyi: stumbled across a similar issue. Could only be solved by following instructions @chriskinsman provided. Took me 3 hours to figure out sigh :)
This is also an issue when running aws opsworks register
, which installs the opsworks agent (very similar process as the codedeploy agent). I think a better approach is to check the lock file before running the installer (avoids the download and all the other stuff the script does before it actually runs dpkg
).
Here's my bash function that checks the lock file before running the installer:
#!/bin/bash
function wait_for_dpkg_lock {
# check for a lock on dpkg (another installation is running)
lsof /var/lib/dpkg/lock > /dev/null
dpkg_is_locked="$?"
if [ "$dpkg_is_locked" == "0" ]; then
echo "Waiting for another installation to finish"
sleep 5
wait_for_dpkg_lock
fi
}
wait_for_dpkg_lock
# now it's safe to run the codedeploy install script or `aws opsworks register`
is this not fixed yet???