Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have apt-get wait for a lock rather than erroring #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ianconsolata
Copy link

Per the suggestion in this article (https://blog.sinjakli.co.uk/2021/10/25/waiting-for-apt-locks-without-the-hacky-bash-scripts/), this setting tells apt-get to wait for the package lock. Our packer builds have been breaking because this script is conflicting with some internal ubuntu update process which is also using apt-get. We recently updated all out internal scripts to use this setting, and we were able to get around the issue. However, this digitalocean provided script is still erroring.

==> digitalocean.lotus: + bash
==> digitalocean.lotus: + curl -L https://raw.githubusercontent.com/digitalocean/marketplace-partners/master/scripts/90-cleanup.sh
==> digitalocean.lotus:   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
==> digitalocean.lotus:                                  Dload  Upload   Total   Spent    Left  Speed
==> digitalocean.lotus: 100  1506  100  1506    0     0   8140      0 --:--:-- --:--:-- --:--:--  8140
    digitalocean.lotus: Reading package lists...
==> digitalocean.lotus: E: Could not get lock /var/lib/apt/lists/lock. It is held by process 2770 (apt-get)
==> digitalocean.lotus: E: Unable to lock directory /var/lib/apt/lists/
==> digitalocean.lotus: Provisioning step had errors: Running the cleanup provisioner, if present...
==> digitalocean.lotus: Destroying droplet...
==> digitalocean.lotus: Deleting temporary ssh key...
Build 'digitalocean.lotus' errored after 2 minutes 10 seconds: Script exited with non-zero exit status: 100. Allowed exit codes are: [0]

According to that article, the two options are either:

  1. Set the DPkg::Lock::Timeout value to a reasonable timeout.
  2. Use apt, which automatically sets this value. However, apt comes with the following warning: WARNING : apt does not have a stable CLI interface. Use with caution in scripts.

The former seemed more robust, so it's what we used, and what I would recommend using here.

apt-get -o Dpkg::Options::="--force-confold" upgrade -q -y --force-yes
apt-get -y autoremove
apt-get -y autoclean
apt-get -o DPkg::Lock::Timeout=3 -y update
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you feel 3s will be good enough for the timeout value?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants