@@ -52,13 +52,38 @@ for host in "${hosts[@]}"; do
5252 fi
5353done
5454
55- # Test container status
55+ # Test container status - prioritize existing namespace containers
5656container_name=" snapshotter-lite-local-collector-${FULL_NAMESPACE} "
5757if ! docker ps | grep -q " $container_name " ; then
5858 echo " ❌ Collector container not found: $container_name "
59+ test_namespace=false
5960else
60- echo " ✅ Collector container running: $container_name "
61+ echo " ✅ Collector container already running for namespace ${FULL_NAMESPACE} : $container_name "
6162 test_namespace=true
63+
64+ # If namespace container exists, use it regardless of port configuration
65+ if [ " $test_ping " = false ]; then
66+ echo " ℹ️ Existing collector container found for namespace ${FULL_NAMESPACE} but not reachable on configured port ${LOCAL_COLLECTOR_PORT} "
67+ echo " ℹ️ Detecting actual port used by running collector $container_name ..."
68+
69+ # Get all port mappings from the running container to find the actual port
70+ actual_port=$( docker port " $container_name " 2> /dev/null | grep ' /tcp' | head -1 | cut -d' :' -f2)
71+
72+ if [ -n " $actual_port " ] && [ " $actual_port " != " $LOCAL_COLLECTOR_PORT " ]; then
73+ echo " ℹ️ Collector $container_name is running on port $actual_port , updating env file"
74+ sed -i" .backup" " s/^LOCAL_COLLECTOR_PORT=.*/LOCAL_COLLECTOR_PORT=${actual_port} /" " ${ENV_FILE} "
75+ export LOCAL_COLLECTOR_PORT=" $actual_port "
76+ elif [ -z " $actual_port " ]; then
77+ echo " ❌ FATAL: Could not detect port for existing collector container ${container_name} "
78+ echo " ❌ Cannot proceed: snapshotter won't know which port to connect to, and spawning a new collector will cause container name conflicts"
79+ echo " ❌ Please manually stop the existing collector or fix its port configuration"
80+ exit 1
81+ else
82+ echo " ℹ️ Collector $container_name confirmed running on configured port ${LOCAL_COLLECTOR_PORT} "
83+ fi
84+ fi
85+ echo " ✅ Using existing collector container for namespace ${FULL_NAMESPACE} on port ${LOCAL_COLLECTOR_PORT} "
86+ exit 100
6287fi
6388
6489# Final status check
0 commit comments