github.com/amylindburg/docker@v1.7.0/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  # intentionally open a couple bogus file descriptors to help test that they get scrubbed in containers
    13  exec 41>&1 42>&2
    14  
    15  export DOCKER_GRAPHDRIVER=${DOCKER_GRAPHDRIVER:-vfs}
    16  export DOCKER_EXECDRIVER=${DOCKER_EXECDRIVER:-native}
    17  export DOCKER_USERLANDPROXY=${DOCKER_USERLANDPROXY:-true}
    18  
    19  # example usage: DOCKER_STORAGE_OPTS="dm.basesize=20G,dm.loopdatasize=200G"
    20  storage_params=""
    21  if [ -n "$DOCKER_STORAGE_OPTS" ]; then
    22  	IFS=','
    23  	for i in ${DOCKER_STORAGE_OPTS}; do
    24  		storage_params="--storage-opt $i $storage_params"
    25  	done
    26  	unset IFS
    27  fi
    28  
    29  if [ -z "$DOCKER_TEST_HOST" ]; then
    30  	# Start apparmor if it is enabled
    31  	if [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then
    32  		# reset container variable so apparmor profile is applied to process
    33  		# see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16
    34  		export container=""
    35  		(
    36  			set -x
    37  			/etc/init.d/apparmor start
    38  		)
    39  	fi
    40  
    41  	export DOCKER_HOST="unix://$(cd "$DEST" && pwd)/docker.sock" # "pwd" tricks to make sure $DEST is an absolute path, not a relative one
    42  	( set -x; exec \
    43  		docker --daemon --debug \
    44  		--host "$DOCKER_HOST" \
    45  		--storage-driver "$DOCKER_GRAPHDRIVER" \
    46  		--exec-driver "$DOCKER_EXECDRIVER" \
    47  		--pidfile "$DEST/docker.pid" \
    48  		--userland-proxy="$DOCKER_USERLANDPROXY" \
    49  		$storage_params \
    50  			&> "$DEST/docker.log"
    51  	) &
    52  	trap "source '${MAKEDIR}/.integration-daemon-stop'" EXIT # make sure that if the script exits unexpectedly, we stop this daemon we just started
    53  else
    54  	export DOCKER_HOST="$DOCKER_TEST_HOST"
    55  fi
    56  
    57  # give it a second to come up so it's "ready"
    58  tries=10
    59  while ! docker version &> /dev/null; do
    60  	(( tries-- ))
    61  	if [ $tries -le 0 ]; then
    62  		if [ -z "$DOCKER_HOST" ]; then
    63  			echo >&2 "error: daemon failed to start"
    64  			echo >&2 "  check $DEST/docker.log for details"
    65  		else
    66  			echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':"
    67  			docker version >&2 || true
    68  		fi
    69  		false
    70  	fi
    71  	sleep 2
    72  done