Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # **install_docker.sh** - Do the initial Docker installation and configuration |
| 4 | |
| 5 | # install_docker.sh |
| 6 | # |
| 7 | # Install docker package and images |
| 8 | # * downloads a base busybox image and a glance registry image if necessary |
| 9 | # * install the images in Docker's image cache |
| 10 | |
| 11 | |
| 12 | # Keep track of the current directory |
| 13 | SCRIPT_DIR=$(cd $(dirname "$0") && pwd) |
| 14 | TOP_DIR=$(cd $SCRIPT_DIR/../..; pwd) |
| 15 | |
| 16 | # Import common functions |
| 17 | source $TOP_DIR/functions |
| 18 | |
| 19 | # Load local configuration |
| 20 | source $TOP_DIR/stackrc |
| 21 | |
| 22 | FILES=$TOP_DIR/files |
| 23 | |
| 24 | # Get our defaults |
| 25 | source $TOP_DIR/lib/nova_plugins/hypervisor-docker |
| 26 | |
| 27 | SERVICE_TIMEOUT=${SERVICE_TIMEOUT:-60} |
| 28 | |
| 29 | |
| 30 | # Install Docker Service |
| 31 | # ====================== |
| 32 | |
| 33 | # Stop the auto-repo updates and do it when required here |
| 34 | NO_UPDATE_REPOS=True |
| 35 | |
| 36 | # Set up home repo |
| 37 | curl https://get.docker.io/gpg | sudo apt-key add - |
| 38 | install_package python-software-properties && \ |
| 39 | sudo sh -c "echo deb $DOCKER_APT_REPO docker main > /etc/apt/sources.list.d/docker.list" |
| 40 | apt_get update |
Sam Alba | 5a77d03 | 2013-10-21 16:17:30 -0700 | [diff] [blame] | 41 | install_package --force-yes lxc-docker socat |
Dean Troyer | 2aa2a89 | 2013-08-04 19:53:19 -0500 | [diff] [blame] | 42 | |
| 43 | # Start the daemon - restart just in case the package ever auto-starts... |
| 44 | restart_service docker |
| 45 | |
| 46 | echo "Waiting for docker daemon to start..." |
| 47 | DOCKER_GROUP=$(groups | cut -d' ' -f1) |
| 48 | CONFIGURE_CMD="while ! /bin/echo -e 'GET /v1.3/version HTTP/1.0\n\n' | socat - unix-connect:$DOCKER_UNIX_SOCKET | grep -q '200 OK'; do |
| 49 | # Set the right group on docker unix socket before retrying |
| 50 | sudo chgrp $DOCKER_GROUP $DOCKER_UNIX_SOCKET |
| 51 | sudo chmod g+rw $DOCKER_UNIX_SOCKET |
| 52 | sleep 1 |
| 53 | done" |
| 54 | if ! timeout $SERVICE_TIMEOUT sh -c "$CONFIGURE_CMD"; then |
| 55 | die $LINENO "docker did not start" |
| 56 | fi |
| 57 | |
| 58 | |
| 59 | # Get Docker image |
| 60 | if [[ ! -r $FILES/docker-ut.tar.gz ]]; then |
| 61 | (cd $FILES; curl -OR $DOCKER_IMAGE) |
| 62 | fi |
| 63 | if [[ ! -r $FILES/docker-ut.tar.gz ]]; then |
| 64 | die $LINENO "Docker image unavailable" |
| 65 | fi |
| 66 | docker import - $DOCKER_IMAGE_NAME <$FILES/docker-ut.tar.gz |
| 67 | |
| 68 | # Get Docker registry image |
| 69 | if [[ ! -r $FILES/docker-registry.tar.gz ]]; then |
| 70 | (cd $FILES; curl -OR $DOCKER_REGISTRY_IMAGE) |
| 71 | fi |
| 72 | if [[ ! -r $FILES/docker-registry.tar.gz ]]; then |
| 73 | die $LINENO "Docker registry image unavailable" |
| 74 | fi |
| 75 | docker import - $DOCKER_REGISTRY_IMAGE_NAME <$FILES/docker-registry.tar.gz |