wait-for-postgres.sh 448 B

123456789101112131415161718
  1. #!/bin/sh
  2. # wait-for-postgres.sh
  3. # https://docs.docker.com/compose/startup-order/
  4. # https://gist.github.com/mihow/9c7f559807069a03e302605691f85572?permalink_comment_id=3709779#gistcomment-3709779
  5. # https://www.postgresql.org/docs/current/libpq-envars.html
  6. set -e
  7. until psql "postgres://$POSTGRES_URL/" -c '\q'; do
  8. >&2 echo "Postgres is unavailable - sleeping"
  9. sleep 1
  10. done
  11. echo "$@"
  12. >&2 echo "Postgres is up - executing command"
  13. exec "$@"