github.com/duglin/docker@v1.13.1/hack/make/.integration-daemon-start (about) 1 #!/bin/bash 2 3 # see test-integration-cli for example usage of this script 4 5 base="$ABS_DEST/.." 6 export PATH="$base/binary-client:$base/binary-daemon:$base/dynbinary-client:$base/dynbinary-daemon:$PATH" 7 8 if ! command -v docker &> /dev/null; then 9 echo >&2 'error: binary-client or dynbinary-client must be run before .integration-daemon-start' 10 false 11 fi 12 13 # This is a temporary hack for split-binary mode. It can be removed once 14 # https://github.com/docker/docker/pull/22134 is merged into docker master 15 if [ "$(go env GOOS)" = 'windows' ]; then 16 return 17 fi 18 19 if [ -z "$DOCKER_TEST_HOST" ]; then 20 if docker version &> /dev/null; then 21 echo >&2 'skipping daemon start, since daemon appears to be already started' 22 return 23 fi 24 fi 25 26 if ! command -v dockerd &> /dev/null; then 27 echo >&2 'error: binary-daemon or dynbinary-daemon must be run before .integration-daemon-start' 28 false 29 fi 30 31 # intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers 32 exec 41>&1 42>&2 33 34 export DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs} 35 export DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true} 36 37 # example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G" 38 storage_params="" 39 if [ -n "$DOCKER_STORAGE_OPTS" ]; then 40 IFS=',' 41 for i in ${DOCKER_STORAGE_OPTS}; do 42 storage_params="--storage-opt $i $storage_params" 43 done 44 unset IFS 45 fi 46 47 # example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G" 48 extra_params="" 49 if [ "$DOCKER_REMAP_ROOT" ]; then 50 extra_params="--userns-remap $DOCKER_REMAP_ROOT" 51 fi 52 53 if [ "$DOCKER_EXPERIMENTAL" ]; then 54 echo >&2 '# DOCKER_EXPERIMENTAL is set: starting daemon with experimental features enabled! ' 55 extra_params="$extra_params --experimental" 56 fi 57 58 if [ -z "$DOCKER_TEST_HOST" ]; then 59 # Start apparmor if it is enabled 60 if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then 61 # reset container variable so apparmor profile is applied to process 62 # see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16 63 export container="" 64 ( 65 set -x 66 /etc/init.d/apparmor start 67 ) 68 fi 69 70 export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one 71 ( set -x; exec \ 72 dockerd --debug \ 73 --host "$DOCKER_HOST" \ 74 --storage-driver "$DOCKER_GRAPHDRIVER" \ 75 --pidfile "$DEST/docker.pid" \ 76 --userland-proxy="$DOCKER_USERLANDPROXY" \ 77 $storage_params \ 78 $extra_params \ 79 &> "$DEST/docker.log" 80 ) & 81 # make sure that if the script exits unexpectedly, we stop this daemon we just started 82 trap 'bundle .integration-daemon-stop' EXIT 83 else 84 export DOCKER_HOST="$DOCKER_TEST_HOST" 85 fi 86 87 # give it a little time to come up so it's "ready" 88 tries=60 89 echo "INFO: Waiting for daemon to start..." 90 while ! docker version &> /dev/null; do 91 (( tries-- )) 92 if [ $tries -le 0 ]; then 93 printf "\n" 94 if [ -z "$DOCKER_HOST" ]; then 95 echo >&2 "error: daemon failed to start" 96 echo >&2 " check $DEST/docker.log for details" 97 else 98 echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':" 99 docker version >&2 || true 100 # Additional Windows CI debugging as this is a common error as of 101 # January 2016 102 if [ "$(go env GOOS)" = 'windows' ]; then 103 echo >&2 "Container log below:" 104 echo >&2 "---" 105 # Important - use the docker on the CI host, not the one built locally 106 # which is currently in our path. 107 ! /c/bin/docker -H=$MAIN_DOCKER_HOST logs docker-$COMMITHASH 108 echo >&2 "---" 109 fi 110 fi 111 false 112 fi 113 printf "." 114 sleep 2 115 done 116 printf "\n"