.integration-daemon-start 3.5 KB

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