yum lock issue on amazon linux ec2

Viewed 819

I am using this shell commands on an amazon linux server (ami id- ami-0a887e401f7654935)launched by aws datapipeline.

#!/bin/bash

sudo yum install -y amazon-linux-extras
sudo amazon-linux-extras enable python3.8
sudo yum install -y python3.8
pip3.8 install --user pipenv
echo "PATH=$HOME/.local/bin:$PATH" >> ~/.bashrc
source ~/.bashrc
aws s3 cp s3://bucketname/datapipeline/scriptfolder/ /home/ec2-user/ --recursive
mkdir -p /home/ec2-user/input
cd /home/ec2-user/
pipenv install --ignore-pipfile
echo "installation done"
pipenv run python3 main.py

Everytime I am running after few minutes getting below error.

errorMsg :    Memory :  46 M RSS (262 MB VSZ)
    Started: Tue Mar 16 01:47:44 2021 - 00:01 ago
    State  : Running, pid: 3746
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory : 139 M RSS (430 MB VSZ)
    Started: Tue Mar 16 01:47:44 2021 - 00:03 ago
    State  : Running, pid: 3746

I tried with adding this rm -f /var/run/yum.pid after last echo command but it's giving me same error. Could you please help?

2 Answers

Get running PID for yum and kill the the PID if it is running;

ps aux|grep yum

and then

kill -9 PID

I struggled with this exact issue:

Existing lock /var/run/yum.pid: another copy is running as pid 3114. Another app is currently holding the yum lock; waiting for it to exit...   The other application is: yum
    Memory :  31 M RSS (247 MB VSZ)
    Started: Thu Sep 23 21:42:19 2021 - 00:02 ago
    State  : Running, pid: 3114

I even added debugging to my userdata:

#!/bin/bash
echo "## var run" > /tmp/yum.out 
ls -la /var/run/ >> /tmp/yum.out
echo "## contents of pid file" >> /tmp/yum.out 
cat /var/run/yum.pid >> /tmp/yum.out 
echo "## PS output" >> /tmp/yum.out 
ps -ef >> /tmp/yum.out
...

What I discovered via that output was that A> there was no /var/run/yum.pid file, and B> there was no pid 3114 in the output of ps -ef. Essentially a phantom pid.

Through a lot of trial and error, I ended up making one change in my userdata that fixed this issue completely for me. I altered /bin/bash to /bin/sh. All of a sudden everything started working fine.

Related