From 07d97d55c7e31d21ec29c70a0ed09e246ca7b465 Mon Sep 17 00:00:00 2001 From: Abhijeet <41686026+abhvsn@users.noreply.github.com> Date: Mon, 14 Oct 2024 14:09:43 +0530 Subject: [PATCH] chore: Add polling for embedded pg start to create appsmith DB (#36854) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description PR to add the polling for `pg_isready` signal for embedded postgres DB. This will fix the infinite loop where postgres refuse to come up. We have seen this failure earlier with `openshift` setup. Current PR will make sure when the embedded postgres fails to startup we are not copying the postgres.conf file as well so supervisor won't have to start the postgres process at all. Ref: https://theappsmith.slack.com/archives/C0341RERY4R/p1728565913269689?thread_ts=1728544650.663739&cid=C0341RERY4R /test Sanity ### :mag: Cypress test results > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: > Commit: df827906858747a0d9d134ae8ed04cc3b901811c > Cypress dashboard. > Tags: `@tag.Sanity` > Spec: >
Mon, 14 Oct 2024 08:17:55 UTC ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No ## Summary by CodeRabbit - **New Features** - Enhanced database initialization process with a maximum attempts mechanism for waiting on PostgreSQL to start. - Improved configuration handling for `APPSMITH_DB_URL` based on database type. - **Bug Fixes** - Ensured robust error handling if PostgreSQL fails to start within the specified attempts. - **Documentation** - Added comments for improved clarity in the deployment script. (cherry picked from commit 348a58f695aee46e78ba1b748ac9ef5a49884ea1) --- deploy/docker/fs/opt/appsmith/entrypoint.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/deploy/docker/fs/opt/appsmith/entrypoint.sh b/deploy/docker/fs/opt/appsmith/entrypoint.sh index 685c0b8fd0a..221be8379a5 100644 --- a/deploy/docker/fs/opt/appsmith/entrypoint.sh +++ b/deploy/docker/fs/opt/appsmith/entrypoint.sh @@ -467,8 +467,15 @@ create_appsmith_pg_db() { # Start the postgres , wait for it to be ready and create a appsmith db su postgres -c "env PATH='$PATH' pg_ctl -D $POSTGRES_DB_PATH -l $POSTGRES_DB_PATH/logfile start" echo "Waiting for Postgres to start" + local max_attempts=100 + local attempt=0 + until su postgres -c "env PATH='$PATH' pg_isready -d postgres"; do - tlog "Waiting for Postgres to be ready..." + if (( attempt >= max_attempts )); then + echo "Postgres failed to start within 100 seconds." + return 1 + fi + tlog "Waiting for Postgres to be ready... Attempt $((++attempt))/$max_attempts" sleep 1 done # Check if the appsmith DB is present