Thursday, January 6, 2022

[SOLVED] how to kill process holding the apt lock

Issue

I'm updating apt and installing mysql-client at run time to a ubuntu 18.04 aws instance. My shell command are like,

        - apt-get update
        - apt-get install -y mysql-client
        - apt-get install -y unzip

But 'apt-get install -y mysql-client' hang and lock apt. Therefor 'apt-get install -y unzip' get fail. So to proceed this, I have to manually kill the process and unclock the apt from following commands.

Step 01. ps -ef | grep apt

Step 02. kill -9

Step 03. sudo dpkg --configure -a

Step 04. Yes the below message

restarts will be done for you automatically so you can avoid being asked questions on each library upgrade. │ Restart services during package upgrades without asking?

Step 05. apt-get install -y mysql-client

My question is how I implement following from shell script or is there a any way to install mysql-client at run time?


Solution

Try to set DEBIAN_FRONTEND=noninteractive and the -q parameter to avoid apt from opening interactive prompts.

e.g: DEBIAN_FRONTEND=noninteractive apt-get install -yq mysql-client



Answered By - Alberto Pau