.integration-daemon-start 3.8 KB

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