From c38db2c11838b319c7c31016e29f38d647aa8a32 Mon Sep 17 00:00:00 2001 From: Matthew Lopez <73856503+MatthewL246@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:31:33 +0000 Subject: [PATCH] Improve Postgres password update script error handling --- scripts/update-postgres-password.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/update-postgres-password.sh b/scripts/update-postgres-password.sh index 0c8deac..aed9570 100755 --- a/scripts/update-postgres-password.sh +++ b/scripts/update-postgres-password.sh @@ -14,8 +14,13 @@ fi docker compose up -d postgres while ! docker compose exec postgres psql -v ON_ERROR_STOP=1 -U "$POSTGRES_USER" -c "\l" >/dev/null 2>&1; do - echo "Waiting for PostgreSQL to start..." - sleep 1 + info "Waiting for PostgreSQL to start..." + sleep 2 done -docker compose exec postgres psql -U "$POSTGRES_USER" -c "ALTER USER $POSTGRES_USER PASSWORD '$POSTGRES_PASSWORD';" +# During the first run, this sometimes fails because the entrypoint script +# restarts the server after running the initdb scripts +while ! docker compose exec postgres psql -U "$POSTGRES_USER" -c "ALTER USER $POSTGRES_USER PASSWORD '$POSTGRES_PASSWORD';"; do + warning "Failed to change Postgres password, retrying..." + sleep 2 +done