.integration-daemon-start 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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:$base/gccgo:$base/dyngccgo:$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 [ -z "$DOCKER_TEST_HOST" ]; then
  43. # Start apparmor if it is enabled
  44. if [ -e "/sys/module/apparmor/parameters/enabled" ] && [ "$(cat /sys/module/apparmor/parameters/enabled)" == "Y" ]; then
  45. # reset container variable so apparmor profile is applied to process
  46. # see https://github.com/docker/libcontainer/blob/master/apparmor/apparmor.go#L16
  47. export container=""
  48. (
  49. set -x
  50. /etc/init.d/apparmor start
  51. )
  52. fi
  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. dockerd --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. # give it a little time to come up so it's "ready"
  70. tries=60
  71. echo "INFO: Waiting for daemon to start..."
  72. while ! docker version &> /dev/null; do
  73. (( tries-- ))
  74. if [ $tries -le 0 ]; then
  75. printf "\n"
  76. if [ -z "$DOCKER_HOST" ]; then
  77. echo >&2 "error: daemon failed to start"
  78. echo >&2 " check $DEST/docker.log for details"
  79. else
  80. echo >&2 "error: daemon at $DOCKER_HOST fails to 'docker version':"
  81. docker version >&2 || true
  82. # Additional Windows CI debugging as this is a common error as of
  83. # January 2016
  84. if [ "$(go env GOOS)" = 'windows' ]; then
  85. echo >&2 "Container log below:"
  86. echo >&2 "---"
  87. # Important - use the docker on the CI host, not the one built locally
  88. # which is currently in our path.
  89. ! /c/bin/docker -H=$MAIN_DOCKER_HOST logs docker-$COMMITHASH
  90. echo >&2 "---"
  91. fi
  92. fi
  93. false
  94. fi
  95. printf "."
  96. sleep 2
  97. done
  98. printf "\n"