diff --git a/k8s/apps/pasarguard/daemonset.yaml b/k8s/apps/pasarguard/daemonset.yaml index b27cfd4..0bd5044 100644 --- a/k8s/apps/pasarguard/daemonset.yaml +++ b/k8s/apps/pasarguard/daemonset.yaml @@ -279,26 +279,24 @@ spec: mv /tmp/v2ray-exporter /usr/local/bin/v2ray-exporter chmod +x /usr/local/bin/v2ray-exporter - # Wait for xray to start - echo "Waiting for xray process to start..." - sleep 10 - - # Find xray API port + # Wait for xray API port file from pasarguard-node container + echo "Waiting for xray API port file..." while true; do - echo "Looking for xray API port..." - API_PORT=$(ss -tlpn | grep xray | grep 127.0.0.1 | awk '{print $4}' | cut -d: -f2 | head -1) - - if [ -n "$API_PORT" ]; then - echo "Found potential API port: $API_PORT" - - # Verify it's the correct port - if curl -s -o /dev/null -w "%{http_code}" "127.0.0.1:$API_PORT" 2>&1 | grep -q "Received HTTP/0.9"; then - echo "Verified API port: $API_PORT" - break + if [ -f /shared/xray-api-port ]; then + API_PORT=$(cat /shared/xray-api-port) + if [ -n "$API_PORT" ]; then + echo "Got xray API port from shared volume: $API_PORT" + + # Verify the port is working + if curl -s -o /dev/null -w "%{http_code}" --max-time 2 "127.0.0.1:$API_PORT" 2>&1 | grep -q "Received HTTP/0.9"; then + echo "Verified API port: $API_PORT" + break + else + echo "Port verification failed, waiting..." + fi fi fi - - echo "API port not found or not verified, retrying in 5 seconds..." + echo "Waiting for valid xray API port... retrying in 5 seconds" sleep 5 done @@ -332,6 +330,10 @@ spec: limits: memory: "128Mi" cpu: "100m" + volumeMounts: + - name: shared-data + mountPath: /shared + readOnly: true - name: pasarguard-node image: 'pasarguard/node:v0.1.1' imagePullPolicy: Always @@ -348,7 +350,29 @@ spec: fi cd /app - exec ./main + + # Start main process in background + ./main & + MAIN_PID=$! + + # Wait a bit for xray to start + sleep 10 + + # Find xray API port and save to shared volume + echo "Looking for xray API port..." + for i in {1..60}; do + API_PORT=$(ss -tlpn | grep xray | grep 127.0.0.1 | awk '{print $4}' | cut -d: -f2 | head -1) + if [ -n "$API_PORT" ]; then + echo "Found xray API port: $API_PORT" + echo -n "$API_PORT" > /shared/xray-api-port + break + fi + echo "Waiting for xray API port... ($i/60)" + sleep 1 + done + + # Continue running main process + wait $MAIN_PID ports: - name: api containerPort: 62050 @@ -400,7 +424,7 @@ spec: volumeMounts: - name: shared-data mountPath: /shared - readOnly: true + readOnly: false volumes: - name: shared-data emptyDir: {}