github.com/bdwilliams/libcompose@v0.3.1-0.20160826154243-d81a9bdacff0/script/.integration-daemon-start (about)

     1  #!/bin/bash
     2  # see test-integration-cli for example usage of this script
     3  
     4  export PATH="$ABS_DEST/../binary:/usr/local/bin/docker-${DOCKER_DAEMON_VERSION}:$PATH"
     5  
     6  if ! command -v docker &> /dev/null; then
     7      echo >&2 'error: docker binary should be present to be able to run test-integration'
     8      false
     9  fi
    10  
    11  # intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers
    12  exec 41>&1 42>&2
    13  
    14  export DOCKER_GRAPH=/var/lib/docker/${DOCKER_DAEMON_VERSION}
    15  export DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
    16  export DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true}
    17  
    18  # example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
    19  storage_params=""
    20  if [ -n "$DOCKER_STORAGE_OPTS" ]; then
    21      IFS=','
    22      for i in ${DOCKER_STORAGE_OPTS}; do
    23          storage_params="--storage-opt $i $storage_params"
    24      done
    25      unset IFS
    26  fi
    27  
    28  if [ -z "$DOCKER_TEST_HOST" ]; then
    29      export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one
    30      ( set -x; exec \
    31                    docker daemon --debug \
    32                    --host "$DOCKER_HOST" \
    33                    --storage-driver "$DOCKER_GRAPHDRIVER" \
    34                    --pidfile "$DEST/docker.pid" \
    35                    --userland-proxy="$DOCKER_USERLANDPROXY" \
    36                    --graph="$DOCKER_GRAPH" \
    37                    $storage_params \
    38        &> "$DEST/docker.log"
    39      ) &
    40      # make sure that if the script exits unexpectedly, we stop this daemon we just started
    41      trap 'bundle .integration-daemon-stop' EXIT
    42  else
    43      export DOCKER_HOST="$DOCKER_TEST_HOST"
    44  fi
    45  
    46  # give it a second to come up so it's "ready"
    47  tries=5
    48  while ! docker version &> /dev/null; do
    49      (( tries-- ))
    50      if [ $tries -le 0 ]; then
    51          if [ -z "$DOCKER_HOST" ]; then
    52              echo >&2 "error: daemon failed to start"
    53              echo >&2 "  check $DEST/docker.log for details"
    54          else
    55              echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':"
    56              docker version >&2 || true
    57          fi
    58          false
    59      fi
    60      sleep 2
    61  done
    62  
    63  docker version