github.com/jiasir/docker@v1.3.3-0.20170609024000-252e610103e7/hack/make/.integration-daemon-start (about)

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