wait-until-healthy.sh 441 B

123456789101112131415161718192021
  1. #!/usr/bin/env bash
  2. if [ "$#" -ne 1 ]; then
  3. >&2 echo "Please provide the container name or hash"
  4. exit 1
  5. fi
  6. for _ in {1..10}
  7. do
  8. state=$(docker inspect -f '{{ .State.Health.Status }}' $1 2>&1)
  9. return_code=$?
  10. if [ ${return_code} -eq 0 ] && [ "$state" == "healthy" ]; then
  11. echo "$1 is healthy!"
  12. sleep 15
  13. exit 0
  14. fi
  15. sleep 15
  16. done
  17. >&2 echo "Timeout of 150s exceeded when waiting for container to be healthy: $1"
  18. exit 1