From f964d140022b34981a3e6057fe98d445e2ae2582 Mon Sep 17 00:00:00 2001 From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com> Date: Sun, 10 Sep 2023 12:37:08 +0800 Subject: [PATCH] chore: kill the appflowy_cloud instance if it already exist (#25) --- build/run_local_server.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/build/run_local_server.sh b/build/run_local_server.sh index 986496f0..a7eeee93 100755 --- a/build/run_local_server.sh +++ b/build/run_local_server.sh @@ -9,11 +9,27 @@ DB_PASSWORD="${POSTGRES_PASSWORD:=password}" DB_PORT="${POSTGRES_PORT:=5433}" DB_HOST="${POSTGRES_HOST:=localhost}" +# Stop and remove any existing containers to avoid conflicts +docker-compose --file ./docker-compose-dev.yml down + +# Start the Docker Compose setup docker-compose --file ./docker-compose-dev.yml up -d --build # Keep pinging Postgres until it's ready to accept commands -until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q'; do +ATTEMPTS=0 +MAX_ATTEMPTS=30 # Adjust this value based on your needs +until PGPASSWORD="${DB_PASSWORD}" psql -h "${DB_HOST}" -U "${DB_USER}" -p "${DB_PORT}" -d "postgres" -c '\q' || [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; do >&2 echo "Postgres is still unavailable - sleeping" sleep 1 + ATTEMPTS=$((ATTEMPTS+1)) done + +if [ $ATTEMPTS -eq $MAX_ATTEMPTS ]; then + >&2 echo "Failed to connect to Postgres after $MAX_ATTEMPTS attempts, exiting." + exit 1 +fi + +# Kill any existing instances +pkill -f appflowy_cloud || true + cargo run