2018-02-22 18:01:05 +03:00
|
|
|
#!/bin/sh
|
2017-09-05 14:39:20 +03:00
|
|
|
|
|
|
|
set -o errexit
|
|
|
|
set -o pipefail
|
2018-03-08 16:59:41 +03:00
|
|
|
set -o nounset
|
2017-09-05 14:39:20 +03:00
|
|
|
|
|
|
|
|
2018-03-08 16:59:41 +03:00
|
|
|
if [ -z "${POSTGRES_USER}" ]; then
|
2018-04-04 11:43:39 +03:00
|
|
|
base_postgres_image_default_user='postgres'
|
|
|
|
export POSTGRES_USER="${base_postgres_image_default_user}"
|
2016-03-08 12:12:55 +03:00
|
|
|
fi
|
2018-05-09 12:58:37 +03:00
|
|
|
export DATABASE_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}"
|
2016-08-16 22:20:41 +03:00
|
|
|
|
2018-02-22 18:01:05 +03:00
|
|
|
postgres_ready() {
|
2016-08-16 22:20:41 +03:00
|
|
|
python << END
|
|
|
|
import sys
|
2018-03-08 16:59:41 +03:00
|
|
|
|
2016-08-16 22:20:41 +03:00
|
|
|
import psycopg2
|
2018-03-08 16:59:41 +03:00
|
|
|
|
2016-08-16 22:20:41 +03:00
|
|
|
try:
|
2018-03-08 16:59:41 +03:00
|
|
|
psycopg2.connect(
|
|
|
|
dbname="${POSTGRES_DB}",
|
|
|
|
user="${POSTGRES_USER}",
|
|
|
|
password="${POSTGRES_PASSWORD}",
|
2018-05-09 12:58:37 +03:00
|
|
|
host="${POSTGRES_HOST}",
|
|
|
|
port="${POSTGRES_PORT}",
|
2018-03-08 16:59:41 +03:00
|
|
|
)
|
2016-08-16 22:20:41 +03:00
|
|
|
except psycopg2.OperationalError:
|
|
|
|
sys.exit(-1)
|
|
|
|
sys.exit(0)
|
2018-03-08 16:59:41 +03:00
|
|
|
|
2016-08-16 22:20:41 +03:00
|
|
|
END
|
|
|
|
}
|
|
|
|
until postgres_ready; do
|
2018-05-21 15:03:37 +03:00
|
|
|
>&2 echo 'Waiting for PostgreSQL to become available...'
|
2016-08-16 22:20:41 +03:00
|
|
|
sleep 1
|
|
|
|
done
|
2018-05-21 15:03:37 +03:00
|
|
|
>&2 echo 'PostgreSQL is available'
|
2018-03-08 16:59:41 +03:00
|
|
|
|
2018-05-21 14:59:20 +03:00
|
|
|
exec "$@"
|