From 3756b0c5656c5c267375725a489ab1502bedde48 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 18 Jul 2021 23:48:43 +1000 Subject: [PATCH] Wait for the DB before running server in init-php --- init-php.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/init-php.sh b/init-php.sh index 8bc8490..59f138d 100755 --- a/init-php.sh +++ b/init-php.sh @@ -4,6 +4,17 @@ set -e BASE_DIR=storage/app +# If DB_HOST not set, source the env file +[ -z "${DB_HOST}" -a -r .env ] && . .env + +if [ -n "${DB_HOST}" -a -n "${DB_PORT}" ]; then + while ! wait-for-it -h ${DB_HOST} -p ${DB_PORT} -t 5 -q; do + echo "? Waiting for database at ${DB_HOST}:${DB_PORT}" + sleep 1; + done + echo "- DB is active on ${DB_HOST}:${DB_PORT}" +fi + # If FIDO_DIR not set, source the env file [ -z "${FIDO_DIR}" -a -r .env ] && . .env