devservices-healthcheck.sh 999 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. # This is used for healthchecking because docker running healthchecks
  3. # keeps the CPU too warm and if a container becomes unhealthy, there's no
  4. # notification system or anything that would make it more easily visible.
  5. # In the future, more healthchecks should be added to make it more helpful
  6. # as a troubleshooting script. Right now this is just used by CI.
  7. # TODO: iterate through all sentry_ containers,
  8. # and warn on anything that's expected to run but isn't running.
  9. # TODO: spawn subprocess for each container,
  10. # specify distinct retries and other parameters.
  11. # would also be nice to have a single ^C work.
  12. try=1
  13. to=3
  14. start=0
  15. delay=5
  16. sleep "$start"
  17. while (( $try <= $to )); do
  18. echo "Checking health of postgres (try ${try} of ${to})..."
  19. if docker exec sentry_postgres pg_isready -U postgres; then
  20. break
  21. fi
  22. if (( $try == $to )); then
  23. echo "Exceeded retries."
  24. exit 1
  25. fi
  26. try=$(($try + 1))
  27. sleep "$delay"
  28. done