Merge lp:~gnuoy/charms/precise/gunicorn/gunicorn-apt-lock-checking into lp:~charmers/charms/precise/gunicorn/trunk

Proposed by Liam Young on 2012-11-30
Status: Merged
Approved by: Mark Mims on 2013-01-03
Approved revision: 25
Merge reported by: Mark Mims
Merged at revision: not available
Proposed branch: lp:~gnuoy/charms/precise/gunicorn/gunicorn-apt-lock-checking
Merge into: lp:~charmers/charms/precise/gunicorn/trunk
Diff against target: 28 lines (+20/-1)
1 file modified
hooks/install (+20/-1)
To merge this branch: bzr merge lp:~gnuoy/charms/precise/gunicorn/gunicorn-apt-lock-checking
Reviewer Review Type Date Requested Status
Mark Mims (community) 2012-12-24 Approve on 2013-01-03
James Page 2012-11-30 Pending
Review via email: mp+137229@code.launchpad.net

Description of the change

Subordinate charms can run at the same time as each other subordinate charms on the same node. This causes issues with, among other things, apt locks.

This mp doesn't fix that but reduces the risk of hitting an apt lock failure by checking for a lock and retrying for up to 5 minutes.

To post a comment you must log in.
Mark Mims (mark-mims) wrote :

lgtm

a note... we'll be standardizing on an approach to deal with this issue across the board. Nothing's set yet, so I'll merge this in and include some details of the proposed soln in a separate comment below.

Thanks Liam!

Mark Mims (mark-mims) wrote :

notes on general soln to apt lock contention between primary and sub(s)...

------------------------8<---------------------------

Juan,

Just to follow up, I've been playing with aptdcon as an alternative to
apt-get. So we can definitely do this to install the dotdee and pwgen
packages.

$ echo y | DEBIAN_FRONTEND=3Dnoninteractive sudo aptdcon --install "dotde=
e
pwgen"

Setting DEBIAN_FRONTEND and using sudo are of course not necessary in a
hook; the yes command doesn't work, presumably because aptdcon is not
supporting SIGPIPE properly, so use echo y.

You can also add a repository using --add-repository or do an upgrade;
this is reasonably well documented in the man page.

I didn't see how to manage the package index update with aptdcon, but
it's certainly possible with a short Python fragment:

from aptdaemon import client

apt_client =3D client.AptClient()
apt_client.update_cache(wait=3DTrue) # implicitly runs, waits until
finished. Good for install hooks!

Lastly, we can combine these approaches together; call the following
file: install-some-packages.py

from aptdaemon import client

apt_client =3D client.AptClient()
apt_client.install_packages(package_names=3D["pwgen", "dotdee"], wait=3DT=
rue)

$ yes | DEBIAN_FRONTEND=3Dnoninteractive sudo python ./apt-update.py

In terms of a quick analysis of charms out there, the one other option I
saw in apt-get usage that's out there is --no-install-recommends. No
clear way to do this in aptdaemon/aptdcon, but perhaps possible. TBD.

- Jim

------------------------8<---------------------------

Mark Mims (mark-mims) wrote :

see MP comments

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/install'
2--- hooks/install 2012-07-06 16:06:15 +0000
3+++ hooks/install 2012-11-30 15:22:43 +0000
4@@ -1,5 +1,24 @@
5 #!/bin/bash
6 set -e
7
8-apt-get install --no-install-recommends -y gunicorn python-eventlet python-gevent python-tornado
9+# Suboridnate charm hooks can run in parallel with other charm hooks
10+# on the same unit Bug #1068624. So a hook may fail to get a apt-get lock.
11+COUNTER=0
12+APT_LOCKED=1
13+while true; do
14+ lsof /var/lib/dpkg/lock > /dev/null 2>&1 || APT_LOCKED=0
15+ if [[ $APT_LOCKED -eq 0 ]]; then
16+ apt-get install --no-install-recommends -q -y gunicorn \
17+ python-eventlet \
18+ python-gevent \
19+ python-tornado
20+ break
21+ fi
22+ if [[ $COUNTER -gt 5 ]]; then
23+ echo "Failed to obtain apt lock to install python-amqplib"
24+ exit 1
25+ fi
26+ sleep 60
27+ COUNTER=$[$COUNTER+1]
28+done
29

Subscribers

People subscribed via source and target branches

to all changes: