#!/bin/bash
# Usage:
# You can use this as a wrapper script as in the previous example,
# by setting entrypoint: ./waitfor.sh db
set -e
host="$1"
shift
cmd="$@"
until psql -h "$host" -U "postgres" -c '\l'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd