moby/contrib
David Röthlisberger f42c0a53a3 upstart: Don't emit "started" event until docker.sock is available
Fixes #6647: Other upstart jobs that depend on docker by specifying
"start on started docker" would often start before the docker daemon was
ready, so they'd fail with "Cannot connect to the Docker daemon" or
"dial unix /var/run/docker.sock: no such file or directory".

This is because "docker -d" doesn't daemonize, it runs in the
foreground, so upstart can't know when the daemon is ready to receive
incoming connections. (Traditionally, a daemon will create all necessary
sockets and then fork to signal that it's ready; according to @tianon
this "isn't possible in Go"[1]. See also [2].)

Presumably this isn't a problem with systemd init with its socket
activation. The SysV init scripts may or may not suffer from this
problem but I have no motivation to fix them.

This commit adds a "post-start" stanza to the upstart configuration
that waits for the socket to be available. Upstart won't emit the
"started" event until the "post-start" script completes.[3]

Note that the system administrator might have specified a different path
for the socket, or a tcp socket instead, by customising
/etc/default/docker. In that case we don't try to figure out what the
new socket is, but at least we don't wait in vain for
/var/run/docker.sock to appear.

If the main script (`docker -d`) fails to start, the `initctl status
$UPSTART_JOB | grep -q "stop/"` line ensures that we don't loop forever.
I stole this idea from Steve Langasek.[4]

If for some reason we *still* end up in an infinite loop --I guess
`docker -d` must have hung-- then at least we'll be able to see the
"Waiting for /var/run/docker.sock" debug output in
/var/log/upstart/docker.log.

I considered using inotifywait instead of sleep, but it isn't worth
the complexity & the extra dependency.

[1] https://github.com/docker/docker/issues/6647#issuecomment-47001613
[2] https://code.google.com/p/go/issues/detail?id=227
[3] http://upstart.ubuntu.com/cookbook/#post-start
[4] https://lists.ubuntu.com/archives/upstart-devel/2013-April/002492.html

Signed-off-by: David Röthlisberger <david@rothlis.net>
2014-12-16 21:25:01 +00:00
..
completion Refactor completion for docker run and docker create 2014-12-15 21:08:49 +01:00
desktop-integration DOCKER_VERSION and docker-version havn't been implemented. 2014-10-21 16:04:11 +10:00
docker-device-tool contrib: fix the docker-device-tool 2014-11-24 13:49:09 -05:00
host-integration DOCKER_VERSION and docker-version havn't been implemented. 2014-10-21 16:04:11 +10:00
init upstart: Don't emit "started" event until docker.sock is available 2014-12-16 21:25:01 +00:00
mkimage Allow for custom debootstrap wrappers like qemu-debootstrap in contrib/mkimage/debootstrap 2014-11-18 15:13:35 -07:00
syntax Added Syntax highlighting file for the KDE Kate Editor 2014-08-27 11:16:51 -07:00
udev Add udev rules files for hiding the docker loopback devices from udisks 2013-12-02 09:11:06 -07:00
vagrant-docker IANA allocated Docker port: 2375 2014-06-04 06:54:19 +10:00
check-config.sh Rename the overlay storage driver 2014-12-03 13:57:23 +01:00
MAINTAINERS Remove @KSid from contrib maintainers for now 2013-10-15 00:58:34 -06:00
mkimage-alpine.sh Standardize "curl" arguments across the repo to be or include "-sSL" 2014-07-07 10:35:38 -06:00
mkimage-arch-pacman.conf mkimage-arch: provide and use own pacman.conf 2014-01-21 14:22:56 +01:00
mkimage-arch.sh Fix #9462 2014-12-12 03:25:14 +01:00
mkimage-busybox.sh mkimage: use /var/tmp by default instead of /tmp 2014-06-27 14:43:12 +02:00
mkimage-crux.sh mkimage: use /var/tmp by default instead of /tmp 2014-06-27 14:43:12 +02:00
mkimage-debootstrap.sh update go import path and libcontainer 2014-07-24 22:19:50 +00:00
mkimage-rinse.sh mkimage: use /var/tmp by default instead of /tmp 2014-06-27 14:43:12 +02:00
mkimage-unittest.sh mkimage: use /var/tmp by default instead of /tmp 2014-06-27 14:43:12 +02:00
mkimage-yum.sh add --releasever=/ to mkimage-yum.sh 2014-07-12 12:15:42 -07:00
mkimage.sh fix help message for mkimage debootstrap with components 2014-10-01 23:18:23 +02:00
mkseccomp.pl Update to double-dash everywhere 2014-03-13 11:46:02 -06:00
mkseccomp.sample added capabilities needed by new sysinit 2014-01-14 19:27:31 +01:00
nuke-graph-directory.sh Fix a bashism and some minor bugs in nuke-graph-directory.sh 2014-12-12 11:51:12 -07:00
README Add contrib/ directory, README, and script to create a basic busybox image 2013-03-14 03:16:42 +00:00

The `contrib` directory contains scripts, images, and other helpful things
which are not part of the core docker distribution. Please note that they
could be out of date, since they do not receive the same attention as the
rest of the repository.