wait-until-healthy.sh 551 B

12345678910111213141516171819202122232425262728
  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..50}
  7. do
  8. state=$(docker inspect -f '{{ .State.Health.Status }}' $1 2>&1)
  9. echo -ne "$state.\r"
  10. sleep 1
  11. echo -ne "$state..\r"
  12. sleep 1
  13. echo -ne "$state...\r"
  14. sleep 1
  15. echo -ne '\033[K'
  16. return_code=$?
  17. if [ ${return_code} -eq 0 ] && [ "$state" == "healthy" ]; then
  18. echo "$1 is healthy!"
  19. exit 0
  20. fi
  21. sleep 0.4
  22. done
  23. >&2 echo "Timeout of 20s exceeded when waiting for container to be healthy: $1"
  24. exit 1