Skip to content

Instantly share code, notes, and snippets.

@7error
Forked from nicerobot/wait-for-postgres.sh
Created April 25, 2020 14:42
Show Gist options
  • Save 7error/79a5bc54603d6b10f598f0056fb5fa13 to your computer and use it in GitHub Desktop.
Save 7error/79a5bc54603d6b10f598f0056fb5fa13 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 ${@}