@@ -281,6 +281,21 @@ action_deploy() {
281281 echo " ${BOLD}${GREEN} ✅ Deploying to Swarm Manager: $docker_swarm_manager ${RESET} "
282282 fi
283283
284+ # Clean up any orphaned SSH tunnels from previous runs
285+ echo " ${BOLD}${BLUE} 🧹 Checking for orphaned SSH tunnels...${RESET} "
286+ orphaned_pids=$( ps aux | grep " ssh -f -n -N -R ${registry_port} :127.0.0.1:${registry_port} " | grep -v grep | awk ' {print $2}' )
287+ if [ -n " $orphaned_pids " ]; then
288+ echo " ${BOLD}${YELLOW} ⚠️ Found orphaned SSH tunnel(s) from previous run. Cleaning up...${RESET} "
289+ for pid in $orphaned_pids ; do
290+ if ps -p " $pid " > /dev/null 2>&1 ; then
291+ kill " $pid " 2> /dev/null
292+ echo " Stopped tunnel process: $pid "
293+ fi
294+ done
295+ # Give it a moment to clean up
296+ sleep 1
297+ fi
298+
284299 # Create SSH tunnel to Docker registry
285300 echo " ${BOLD}${BLUE} 🚇 Creating SSH tunnel to Docker registry...${RESET} "
286301
@@ -308,8 +323,26 @@ action_deploy() {
308323 else
309324 ssh_exit_code=$?
310325 echo " ${BOLD}${RED} ❌ Failed to create SSH tunnel (Exit code: $ssh_exit_code )${RESET} "
311- echo " ${BOLD}${YELLOW} 🔧 Troubleshoot your connection by running:${RESET} "
312- echo " ${BOLD}${YELLOW} ssh -v -p ${ssh_port} ${ssh_user} @${docker_swarm_manager}${RESET} "
326+ echo " "
327+ echo " ${BOLD}${YELLOW} Common causes and solutions:${RESET} "
328+ echo " "
329+ echo " ${BOLD} 1. Port ${registry_port} may already be in use on the remote server${RESET} "
330+ echo " Check if another process is using the port:"
331+ echo " ${BLUE} ssh -p ${ssh_port} ${ssh_user} @${docker_swarm_manager} 'lsof -i :${registry_port} || ss -tuln | grep ${registry_port} '${RESET} "
332+ echo " "
333+ echo " ${BOLD} 2. A stale SSH tunnel may exist on the remote server${RESET} "
334+ echo " Kill any stale SSH processes on the remote server:"
335+ echo " ${BLUE} ssh -p ${ssh_port} ${ssh_user} @${docker_swarm_manager} 'pkill -f \" sshd.*${registry_port} \" '${RESET} "
336+ echo " "
337+ echo " ${BOLD} 3. GatewayPorts may not be enabled on the remote server${RESET} "
338+ echo " Check if GatewayPorts is enabled in sshd_config:"
339+ echo " ${BLUE} ssh -p ${ssh_port} ${ssh_user} @${docker_swarm_manager} 'sudo grep GatewayPorts /etc/ssh/sshd_config'${RESET} "
340+ echo " "
341+ echo " ${BOLD} 4. Firewall or network connectivity issues${RESET} "
342+ echo " Test the SSH connection with verbose output:"
343+ echo " ${BLUE} ssh -v -p ${ssh_port} ${ssh_user} @${docker_swarm_manager}${RESET} "
344+ echo " "
345+ echo " ${BOLD}${YELLOW} 💡 Tip: Try changing the registry port by setting SPIN_REGISTRY_PORT in your .env file${RESET} "
313346 exit 1
314347 fi
315348
0 commit comments