salt-bootstrap icon indicating copy to clipboard operation
salt-bootstrap copied to clipboard

salt-cloud minion bootstrap fails due to dpkg lock

Open ripesensor opened this issue 8 years ago • 9 comments

Description of Issue/Question

Same issue as #1163 when bootstrapping an Amazon Deep Learning AMI with salt-cloud.

Error:


 *  INFO: Running version: 2018.08.15
 *  INFO: Executed by: /bin/sh
 *  INFO: Command line: '/tmp/.saltcloud-64aafe3b-1eff-47e5-a70c-4d58e2c227b0/deploy.sh -c /tmp/.saltcloud-64aafe3b-1eff-47e5-a70c-4d58e2c227b0 -D'

 *  INFO: System Information:
 *  INFO:   CPU:          GenuineIntel
 *  INFO:   CPU Arch:     x86_64
 *  INFO:   OS Name:      Linux
 *  INFO:   OS Version:   4.4.0-1066-aws
 *  INFO:   Distribution: Ubuntu 16.04

 * DEBUG: Binaries will be searched using the following $PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
 *  INFO: Installing minion
 * DEBUG: install_ubuntu_16_stable_deps not found....
 * DEBUG: install_ubuntu_16_04_stable_deps not found....
 * DEBUG: install_ubuntu_16_deps not found....
 * DEBUG: install_ubuntu_16_04_deps not found....
 *  INFO: Found function install_ubuntu_stable_deps
 * DEBUG: DEPS_INSTALL_FUNC=install_ubuntu_stable_deps
 * DEBUG: config_ubuntu_16_stable_salt not found....
 * DEBUG: config_ubuntu_16_04_stable_salt not found....
 * DEBUG: config_ubuntu_16_salt not found....
 * DEBUG: config_ubuntu_16_04_salt not found....
 * DEBUG: config_ubuntu_stable_salt not found....
 * DEBUG: config_ubuntu_salt not found....
 *  INFO: Found function config_salt
 * DEBUG: CONFIG_SALT_FUNC=config_salt
 * DEBUG: preseed_ubuntu_16_stable_master not found....
 * DEBUG: preseed_ubuntu_16_04_stable_master not found....
 * DEBUG: preseed_ubuntu_16_master not found....
 * DEBUG: preseed_ubuntu_16_04_master not found....
 * DEBUG: preseed_ubuntu_stable_master not found....
 * DEBUG: preseed_ubuntu_master not found....
 *  INFO: Found function preseed_master
 * DEBUG: PRESEED_MASTER_FUNC=preseed_master
 * DEBUG: install_ubuntu_16_stable not found....
 * DEBUG: install_ubuntu_16_04_stable not found....
 *  INFO: Found function install_ubuntu_stable
 * DEBUG: INSTALL_FUNC=install_ubuntu_stable
 * DEBUG: install_ubuntu_16_stable_post not found....
 * DEBUG: install_ubuntu_16_04_stable_post not found....
 * DEBUG: install_ubuntu_16_post not found....
 * DEBUG: install_ubuntu_16_04_post not found....
 *  INFO: Found function install_ubuntu_stable_post
 * DEBUG: POST_INSTALL_FUNC=install_ubuntu_stable_post
 * DEBUG: install_ubuntu_16_stable_restart_daemons not found....
 * DEBUG: install_ubuntu_16_04_stable_restart_daemons not found....
 * DEBUG: install_ubuntu_16_restart_daemons not found....
 * DEBUG: install_ubuntu_16_04_restart_daemons not found....
 * DEBUG: install_ubuntu_stable_restart_daemons not found....
 *  INFO: Found function install_ubuntu_restart_daemons
 * DEBUG: STARTDAEMONS_INSTALL_FUNC=install_ubuntu_restart_daemons
 * DEBUG: daemons_running_ubuntu_16_stable not found....
 * DEBUG: daemons_running_ubuntu_16_04_stable not found....
 * DEBUG: daemons_running_ubuntu_16 not found....
 * DEBUG: daemons_running_ubuntu_16_04 not found....
 * DEBUG: daemons_running_ubuntu_stable not found....
 * DEBUG: daemons_running_ubuntu not found....
 *  INFO: Found function daemons_running
 * DEBUG: DAEMONS_RUNNING_FUNC=daemons_running
 * DEBUG: install_ubuntu_16_stable_check_services not found....
 * DEBUG: install_ubuntu_16_04_stable_check_services not found....
 * DEBUG: install_ubuntu_16_check_services not found....
 * DEBUG: install_ubuntu_16_04_check_services not found....
 * DEBUG: install_ubuntu_stable_check_services not found....
 *  INFO: Found function install_ubuntu_check_services
 * DEBUG: CHECK_SERVICES_FUNC=install_ubuntu_check_services
 *  INFO: Running install_ubuntu_stable_deps()
 * DEBUG: Checking if apt process is currently running.
 * DEBUG: No apt processes are currently running.
Hit:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get:3 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
Hit:5 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu xenial InRelease
Get:6 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main Sources [321 kB]
Get:7 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe Sources [222 kB]
Get:8 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/multiverse Sources [8,388 B]
Get:9 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [849 kB]
Get:10 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [347 kB]
Get:11 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [691 kB]
Get:12 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [279 kB]
Get:13 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.4 kB]
Get:14 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-backports/universe Sources [6,740 B]
Get:15 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7,568 B]
Get:16 http://us-east-1.ec2.archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [4,048 B]
Get:17 http://security.ubuntu.com/ubuntu xenial-security/main Sources [134 kB]
Get:18 https://nvidia.github.io/libnvidia-container/ubuntu16.04/amd64  InRelease [1,106 B]
Get:19 https://nvidia.github.io/nvidia-container-runtime/ubuntu16.04/amd64  InRelease [1,136 B]
Get:20 https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64  InRelease [1,129 B]
Get:21 https://nvidia.github.io/libnvidia-container/ubuntu16.04/amd64  Packages [5,536 B]
Get:22 http://security.ubuntu.com/ubuntu xenial-security/universe Sources [75.8 kB]
Get:23 http://security.ubuntu.com/ubuntu xenial-security/multiverse Sources [2,088 B]
Get:24 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [556 kB]
Get:25 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [235 kB]
Get:26 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [379 kB]
Get:27 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [144 kB]
Get:28 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3,460 B]
Fetched 4,613 kB in 1s (2,400 kB/s)
Reading package lists...
Connection to 10.10.1.154 closed.
 * DEBUG: Checking if apt process is currently running.
 * DEBUG: No apt processes are currently running.
E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)
E: Unable to lock the administration directory (/var/lib/dpkg/), is another process using it?
 * ERROR: Failed to run install_ubuntu_stable_deps()!!!
 * DEBUG: Removing the logging pipe /tmp/bootstrap-salt.logpipe
 * DEBUG: Killing logging pipe tee's with pid(s): 2174

Setup

gpu: extends: private_16.04_config image: ami-0466e26ccc0e752c1 size: p3.2xlarge script_args: -D

Steps to Reproduce Issue

salt-cloud -p gpu gpu

Versions and Systems

Salt Version: Salt: 2018.3.2

Dependency Versions: cffi: Not Installed cherrypy: Not Installed dateutil: 2.7.3 docker-py: Not Installed gitdb: Not Installed gitpython: Not Installed ioflo: Not Installed Jinja2: 2.10 libgit2: Not Installed libnacl: Not Installed M2Crypto: Not Installed Mako: 1.0.3 msgpack-pure: Not Installed msgpack-python: 0.4.6 mysql-python: Not Installed pycparser: Not Installed pycrypto: 2.6.1 pycryptodome: Not Installed pygit2: Not Installed Python: 2.7.12 (default, Dec 4 2017, 14:50:18) python-gnupg: 0.3.8 PyYAML: 3.13 PyZMQ: 17.1.2 RAET: Not Installed smmap: Not Installed timelib: Not Installed Tornado: 5.1.1 ZMQ: 4.2.5

System Versions: dist: Ubuntu 16.04 xenial locale: UTF-8 machine: x86_64 release: 4.4.0-1067-aws system: Linux version: Ubuntu 16.04 xenial

Bootstrap Version: __ScriptVersion="2018.08.15"

ripesensor avatar Sep 26 '18 15:09 ripesensor

This seems to work better, but it's still not perfect:


diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh
index 0f5eace..5a576f7 100755
--- a/bootstrap-salt.sh
+++ b/bootstrap-salt.sh
@@ -1802,7 +1802,7 @@ __wait_for_apt(){
     # Timeout set at 15 minutes
     WAIT_TIMEOUT=900

-    while ps -C apt,apt-get,aptitude,dpkg >/dev/null; do
+    while fuser -s /var/lib/apt/lists/lock || fuser -s /var/lib/dpkg/lock; do
         sleep 1
         WAIT_TIMEOUT=$((WAIT_TIMEOUT - 1))
                                    

ripesensor avatar Oct 04 '18 15:10 ripesensor

Hi @ripesensor - My apologies for the late reply here. I agree that your solution above looks better. Would you be willing to submit a PR?

rallytime avatar Nov 01 '18 14:11 rallytime

No worries. I'd submit a PR.

It doesn't fix the locking issue, but I'm not sure of the best way to accomplish this task. The hammer method may be to stop the apt-daily and apt-daily-upgrade systemd services, then politely start them again at the end of the run. Sounds gross. Don't like it.

Another way would be to see if the exit code is 100 (which seems to be locking or lock permission errors), and loop on that rather than the while fuser bits. This would break if we're not root, but you check for that in the script anyway:


__wait_for_apt() {
# ...
  (exit 100)
  while [ $? -eq 100 ]; do
    # sleep first, otherwise our return code will be 0
    sleep 1
    WAIT_TIMEOUT=$((WAIT_TIMEOUT - 1))
    $@
  done
# ...
}

Then pass your apt commands to the function:


 __wait_for_apt apt-get ...

Which may be a way to get around another apt process sneaking in? Would also require a bit of code rewrite.

ripesensor avatar Nov 01 '18 16:11 ripesensor

This works well. Will PR it.

ripesensor avatar Nov 01 '18 16:11 ripesensor

@ripesensor are you okay to close this as it looks like your PR resolves the issue here?

Ch3LL avatar Nov 19 '18 16:11 Ch3LL

Apt returns 100 when a release file doesn't exist. This condition causes the script to loop all the way til the end with the guarantee that it never continues.

Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease
Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease
Ign:3 https://repo.saltstack.com/apt/ubuntu/18.04/amd64/archive/2017.7.2 bionic InRelease
Err:4 https://repo.saltstack.com/apt/ubuntu/18.04/amd64/archive/2017.7.2 bionic Release
  404  Not Found [IP: 138.197.226.47 443]
Hit:5 http://archive.ubuntu.com/ubuntu bionic-updates InRelease
Hit:6 http://archive.ubuntu.com/ubuntu bionic-backports InRelease
Reading package lists...
E: The repository 'https://repo.saltstack.com/apt/ubuntu/18.04/amd64/archive/2017.7.2 bionic Release' does not have a Release file.
+ APT_RETURN=100

jc-rob avatar Mar 19 '19 21:03 jc-rob

That's too bad. Another way we could attempt checking for a lock would be to redirect stderr to stdout and grep for the lock errors. E.g.:

apt-get install stuff 2>&1 | grep -q "E: Could not get lock"

If we return an exit code of 0, then we know the grep matched and we can try again. This blocks any exit codes from apt, however, and that leaves another problem.

ripesensor avatar Mar 20 '19 13:03 ripesensor

Looks like we could use ${PIPESTATUS[0]} to get at the apt-exit code in my example.

ripesensor avatar Mar 20 '19 15:03 ripesensor

@ripesensor The $PIPESTATUS is specific to bash. However, the script could (and usually) run with /bin/sh, which is dash on Debian/Ubuntu.

vutny avatar Mar 20 '19 15:03 vutny