marshmello
marshmello

Reputation: 101

AWS Ubuntu 18.04 AMI package installation failed

Whenever an AWS autoscaling group launches new ubuntu instance and I try to install any package on that instance it gives me the following error:

[stderr]E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
[stderr]E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend),

Is there another process using it?

I tried to find a solution and manually fixed it but I don't know why whenever the autoscaling group launches a new ubuntu instance it gives the following error.

Upvotes: 1

Views: 905

Answers (2)

shariqmaws
shariqmaws

Reputation: 8890

SSH into the instance before/while the UserData is running and check which process has acquired the lock:

$ lsof /var/lib/dpkg/lock-frontend

Also, try to enable CodeDeploy agent at the last step after performing all other steps in UserData, like:

Upvotes: 0

vik
vik

Reputation: 151

When any command updates the Ubuntu or installs a new application, it locks the dpkg(Debian Package Manager). To identify the problem, please look at the logs

  1. If your system is installing some updates you may find journalctl logs journalctl -u apt-daily.service. This usually happend when the system is set to update itslef and you will notice such activity with this ps -ef | grep apt.systemd.daily and you can check these setting in the file /etc/apt/apt.conf.d/20auto-upgrades
  2. /var/log/dpkg.log*(as it may get rotated) check these logs to find which all services were trying to get installed

Once you have identified the problem, you can solve with these methods:

  1. If system is updating, then try to wait by executing sleep command in the --user-dataof your bootstrapping script
  2. If your 1st installation of an service/application is blocking other one, then put a condition to wait/sleep until the first service is up and so on with rest of the services you are installing. This was a common problem in Ubuntu 16.04 LTS as per, and you can find the same with the solution code https://forums.aws.amazon.com/thread.jspa?threadID=251663

A snippet of code from the referenced link: 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

Upvotes: 1

Related Questions