Skip to content

Commit 5feeabc

Browse files
thePanzdunglas
andauthored
fix: do not check DB availability if code errors (#110)
* fix: do not check DB availability if code errors Do not wait for the DB to be available if there are other errors blocking the access to it. * Update docker-entrypoint.sh Co-authored-by: Kévin Dunglas <dunglas@gmail.com>
1 parent 3445aac commit 5feeabc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

docker/php/docker-entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,20 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then
3232
if grep -q ^DATABASE_URL= .env; then
3333
echo "Waiting for db to be ready..."
3434
ATTEMPTS_LEFT_TO_REACH_DATABASE=60
35-
until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || bin/console doctrine:query:sql "SELECT 1" >/dev/null 2>&1; do
35+
until [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ] || DATABASE_ERROR=$(bin/console doctrine:query:sql "SELECT 1" 2>&1); do
36+
if [ $? -eq 255 ]; then
37+
# If the Doctrine command exits with 255, an unrecoverable error occurred
38+
ATTEMPTS_LEFT_TO_REACH_DATABASE=0
39+
break
40+
fi
3641
sleep 1
3742
ATTEMPTS_LEFT_TO_REACH_DATABASE=$((ATTEMPTS_LEFT_TO_REACH_DATABASE - 1))
3843
echo "Still waiting for db to be ready... Or maybe the db is not reachable. $ATTEMPTS_LEFT_TO_REACH_DATABASE attempts left"
3944
done
4045

4146
if [ $ATTEMPTS_LEFT_TO_REACH_DATABASE -eq 0 ]; then
42-
echo "The db is not up or not reachable"
47+
echo "The database is not up or not reachable:"
48+
echo "$DATABASE_ERROR"
4349
exit 1
4450
else
4551
echo "The db is now ready and reachable"

0 commit comments

Comments
 (0)