Skip to content

Instantly share code, notes, and snippets.

@rjbaker
Forked from nicerobot/wait-for-postgres.sh
Last active September 29, 2021 14:04
Show Gist options
  • Save rjbaker/390c1a2fd18768c54c160d4568bd3dba to your computer and use it in GitHub Desktop.
Save rjbaker/390c1a2fd18768c54c160d4568bd3dba to your computer and use it in GitHub Desktop.

Revisions

  1. @nicerobot nicerobot created this gist Jun 27, 2017.
    13 changes: 13 additions & 0 deletions wait-for-postgres.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    #!/bin/bash -e
    # wait-for-postgres.sh
    # Adapted from https://docs.docker.com/compose/startup-order/

    # Expects the necessary PG* variables.

    until psql -c '\l'; do
    echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is unavailable - sleeping"
    sleep 1
    done
    echo >&2 "$(date +%Y%m%dt%H%M%S) Postgres is up - executing command"

    exec ${@}