wait-db 368 B

1234567891011121314
  1. #!/bin/bash
  2. ### psql configuration parameters must be received as environ vars
  3. ### (PGHOST, PGDATABASE, PGUSER, PGPASSWORD)
  4. timeout=60
  5. for _ in $(seq 1 "$timeout"); do
  6. if psql -w -c "" -q 2> /dev/null; then
  7. echo "DB ready"
  8. exec "$@"
  9. fi
  10. echo "Waiting..." >&2
  11. sleep 1
  12. done
  13. echo "Timeout! postgresql wasn't ready in 60 seconds" >&2
  14. exit 1