From 20cc4b93a99b1628921247e1cd5fddaf5b50bd3f Mon Sep 17 00:00:00 2001 From: MaxJa4 <74194322+MaxJa4@users.noreply.github.com> Date: Mon, 7 Feb 2022 18:13:19 +0100 Subject: [PATCH] Add max amount of retries for web container boot --- boot.sh | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/boot.sh b/boot.sh index af72a7b9..7e2f05fa 100644 --- a/boot.sh +++ b/boot.sh @@ -1,13 +1,33 @@ #!/bin/sh source venv/bin/activate -echo "Updating database" -while python manage.py migrate ; status=$? ; [ $status -eq 1 ]; do - echo "Migration failed (error #${status})! Database may not be ready yet, retrying in 5 seconds..." - sleep 5 +echo "Migrating database" + +attempt=0 +max_attempts=20 +while python manage.py migrate; \ + status=$?; \ + attempt=$((attempt+1)); \ + [ $status -eq 1 ] \ + && [ $attempt -le $max_attempts ]; do + echo -e "\n!!! Migration failed (error ${status}, attempt ${attempt}/${max_attempts})." + echo "!!! Database may not be ready yet or system is misconfigured." + echo -e "!!! Retrying in 5 seconds...\n" + sleep 5 done + +if [ $attempt -gt $max_attempts ]; then + echo -e "\n!!! Migration failed. Maximum attempts exceeded." + echo "!!! Please check logs above - misconfiguration is very likely." + echo "!!! Shutting down container." + exit 1 # exit with error to make the container stop +fi + +echo "Generating static files" + python manage.py collectstatic_js_reverse python manage.py collectstatic --noinput + echo "Done" chmod -R 755 /opt/recipes/mediafiles