diff --git a/start.sh b/start.sh index 0a0fdcf1..860527c1 100644 --- a/start.sh +++ b/start.sh @@ -2,8 +2,18 @@ SSR_PATH=/opt/sqlbot/g2-ssr APP_PATH=/opt/sqlbot/app /usr/local/bin/docker-entrypoint.sh postgres & -sleep 5 -wait-for-it 127.0.0.1:5432 --timeout=120 --strict -- echo -e "\033[1;32mPostgreSQL started.\033[0m" +MAX_WAIT=120 +WAIT_COUNT=0 +echo "Waiting for PostgreSQL to complete crash recovery and accept connections (max ${MAX_WAIT}s)..." +until pg_isready -h 127.0.0.1 -p 5432 -U postgres -q; do + if [ $WAIT_COUNT -ge $MAX_WAIT ]; then + echo -e "\033[1;31mError: PostgreSQL failed to become ready within ${MAX_WAIT} seconds. Exiting to avoid hanging.\033[0m" + exit 1 + fi + sleep 2 + WAIT_COUNT=$((WAIT_COUNT + 2)) +done +echo -e "\033[1;32mPostgreSQL is fully ready and accepting connections (took ${WAIT_COUNT}s).\033[0m" nohup /usr/bin/supervisord -c /etc/supervisor/supervisord.conf &