github.com/ojongerius/docker@v1.11.2/hack/make/.integration-daemon-start (about)

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