setup-postgres.sh 793 B

123456789101112131415161718192021222324252627282930
  1. #!/bin/bash
  2. ######################################################################
  3. # This script sets up a new Postgres instance in a CI environment
  4. ######################################################################
  5. # Install dependencies
  6. sudo apt-get update
  7. sudo apt-get -y install postgresql-client
  8. # Wait for the DB service to be up.
  9. statusFile=/tmp/postgres-status
  10. while [[ true ]]; do
  11. telnet $PGHOST $PGPORT &> ${statusFile}
  12. status=$(grep "Connection refused" ${statusFile} | wc -l)
  13. echo "Status: $status"
  14. if [[ "${status}" -eq 1 ]]; then
  15. echo "Postgres not running, waiting."
  16. sleep 1
  17. else
  18. rm ${statusFile}
  19. echo "Postgres running, ready to proceed."
  20. break;
  21. fi
  22. done
  23. psql -h $PGHOST -p $PGPORT --file ci/load-psql-extensions.sql -U $PGUSER $PGDB;