From 6668e1af4faa122aeef30eaafc57d669a69dc8b7 Mon Sep 17 00:00:00 2001 From: Finley Ghosh Date: Sun, 7 Dec 2025 16:15:36 +1100 Subject: [PATCH] Adding check for existing ssh tunnel --- scripts/deploy/scripts/run_migrations.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/deploy/scripts/run_migrations.sh b/scripts/deploy/scripts/run_migrations.sh index 775e2b75..9d4933de 100755 --- a/scripts/deploy/scripts/run_migrations.sh +++ b/scripts/deploy/scripts/run_migrations.sh @@ -29,10 +29,14 @@ else SSH_PORT=13308 fi -# Create SSH tunnel -echo "Creating SSH tunnel to $TARGET database on localhost:$SSH_PORT..." -ssh -f -N -L $SSH_PORT:localhost:$DB_PORT cmc -sleep 2 +# Create SSH tunnel if not already running +if ! lsof -ti:$SSH_PORT > /dev/null 2>&1; then + echo "Creating SSH tunnel to $TARGET database on localhost:$SSH_PORT..." + ssh -f -N -L $SSH_PORT:localhost:$DB_PORT cmc + sleep 2 +else + echo "SSH tunnel already exists on localhost:$SSH_PORT, reusing it..." +fi # Load goose.env and override the port GOOSE_ENV_FILE="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../go" && pwd)/goose.env"