taylorzr
6/8/2018 - 7:23 PM

Wait for Postgres...

Wait for Postgres...

#!/usr/bin/env bash

set -e

host="${1:-postgres}"

trap 'kill -INT -$pid' INT

timeout 30 bash <<EOF &
  function wait_for_postgres() {
    until psql -h "$host" -U "postgres" -c '\l'; do
      >&2 echo "Postgres is unavailable - sleeping"
      sleep 1
    done
  }
  wait_for_postgres
EOF

pid=$!

wait $pid