#!/bin/bash # Garante que o túnel SSH até o Postgres da VPS (rag-hub-db) está aberto em # 127.0.0.1:55435. Idempotente: se já estiver escutando, não faz nada. # Mesmo container compartilhado usado por rag_doza/rag_tigre/jhonny-rag. HOST="root@179.197.228.240" LOCAL_PORT=55435 REMOTE_PORT=55435 if nc -z 127.0.0.1 "$LOCAL_PORT" 2>/dev/null; then echo "[rag] tunel ja aberto em 127.0.0.1:$LOCAL_PORT" exit 0 fi echo "[rag] abrindo tunel SSH ate $HOST ($LOCAL_PORT -> $REMOTE_PORT)..." ssh -f -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 \ -L "127.0.0.1:${LOCAL_PORT}:127.0.0.1:${REMOTE_PORT}" "$HOST" for _ in $(seq 1 10); do if nc -z 127.0.0.1 "$LOCAL_PORT" 2>/dev/null; then echo "[rag] tunel ativo." exit 0 fi sleep 0.5 done echo "[rag] AVISO: nao foi possivel confirmar o tunel." >&2 exit 1