2020-01-07 14:06:31 +03:00
|
|
|
#!/bin/bash
|
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-06-27 23:36:06 +03:00
|
|
|
{% if cookiecutter.use_celery == 'y' %}
|
|
|
|
# N.B. If only .env files supported variable expansion...
|
|
|
|
export CELERY_BROKER_URL="${REDIS_URL}"
|
|
|
|
{% endif %}
|
|
|
|
|
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
|
|
|
|
|
|
|
python << END
|
|
|
|
import sys
|
2022-07-27 01:17:45 +03:00
|
|
|
import time
|
2018-03-08 16:59:41 +03:00
|
|
|
|
2023-06-28 16:19:56 +03:00
|
|
|
import psycopg
|
2018-03-08 16:59:41 +03:00
|
|
|
|
2022-07-27 01:17:45 +03:00
|
|
|
suggest_unrecoverable_after = 30
|
|
|
|
start = time.time()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
try:
|
2023-06-28 16:19:56 +03:00
|
|
|
psycopg.connect(
|
2022-07-27 01:17:45 +03:00
|
|
|
dbname="${POSTGRES_DB}",
|
|
|
|
user="${POSTGRES_USER}",
|
|
|
|
password="${POSTGRES_PASSWORD}",
|
|
|
|
host="${POSTGRES_HOST}",
|
|
|
|
port="${POSTGRES_PORT}",
|
|
|
|
)
|
|
|
|
break
|
2023-06-28 16:19:56 +03:00
|
|
|
except psycopg.OperationalError as error:
|
2022-07-27 01:17:45 +03:00
|
|
|
sys.stderr.write("Waiting for PostgreSQL to become available...\n")
|
|
|
|
|
|
|
|
if time.time() - start > suggest_unrecoverable_after:
|
|
|
|
sys.stderr.write(" This is taking longer than expected. The following exception may be indicative of an unrecoverable error: '{}'\n".format(error))
|
|
|
|
|
|
|
|
time.sleep(1)
|
2016-08-16 22:20:41 +03:00
|
|
|
END
|
2022-07-27 01:17:45 +03:00
|
|
|
|
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 "$@"
|