Added xray exporter
This commit is contained in:
@@ -172,31 +172,43 @@ data:
|
|||||||
mv /tmp/v2ray-exporter /usr/local/bin/v2ray-exporter
|
mv /tmp/v2ray-exporter /usr/local/bin/v2ray-exporter
|
||||||
chmod +x /usr/local/bin/v2ray-exporter
|
chmod +x /usr/local/bin/v2ray-exporter
|
||||||
|
|
||||||
# Wait for xray API port file from pasarguard-node container
|
# Wait for initial API port file
|
||||||
echo "Waiting for xray API port file..."
|
echo "Waiting for initial xray API port file..."
|
||||||
|
while [ ! -f /shared/xray-api-port ]; do
|
||||||
|
echo "Waiting for API port file..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
# Main loop - restart exporter if it crashes or port changes
|
||||||
while true; do
|
while true; do
|
||||||
if [ -f /shared/xray-api-port ]; then
|
if [ -f /shared/xray-api-port ]; then
|
||||||
API_PORT=$(cat /shared/xray-api-port)
|
API_PORT=$(cat /shared/xray-api-port)
|
||||||
if [ -n "$API_PORT" ]; then
|
if [ -n "$API_PORT" ]; then
|
||||||
echo "Got xray API port from shared volume: $API_PORT"
|
echo "Starting v2ray-exporter with endpoint 127.0.0.1:$API_PORT"
|
||||||
|
/usr/local/bin/v2ray-exporter --v2ray-endpoint "127.0.0.1:$API_PORT" --listen ":9550" &
|
||||||
|
EXPORTER_PID=$!
|
||||||
|
|
||||||
# Verify the port is working
|
# Wait for exporter to exit or port file to change
|
||||||
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
|
while kill -0 $EXPORTER_PID 2>/dev/null; do
|
||||||
echo "Verified API port: $API_PORT"
|
if [ -f /shared/xray-api-port ]; then
|
||||||
break
|
NEW_PORT=$(cat /shared/xray-api-port)
|
||||||
else
|
if [ "$NEW_PORT" != "$API_PORT" ]; then
|
||||||
echo "Port verification failed, waiting..."
|
echo "API port changed from $API_PORT to $NEW_PORT, restarting exporter"
|
||||||
fi
|
kill $EXPORTER_PID 2>/dev/null
|
||||||
|
wait $EXPORTER_PID 2>/dev/null
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
sleep 5
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Exporter stopped, restarting..."
|
||||||
|
wait $EXPORTER_PID 2>/dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
echo "Waiting for valid xray API port... retrying in 5 seconds"
|
sleep 2
|
||||||
sleep 5
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Start exporter
|
|
||||||
echo "Starting v2ray-exporter with endpoint 127.0.0.1:$API_PORT"
|
|
||||||
exec /usr/local/bin/v2ray-exporter --v2ray-endpoint "127.0.0.1:$API_PORT" --listen ":9550"
|
|
||||||
|
|
||||||
pasarguard-start.sh: |
|
pasarguard-start.sh: |
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# Read API_KEY from shared volume created by init container
|
# Read API_KEY from shared volume created by init container
|
||||||
@@ -213,21 +225,25 @@ data:
|
|||||||
./main &
|
./main &
|
||||||
MAIN_PID=$!
|
MAIN_PID=$!
|
||||||
|
|
||||||
# Wait a bit for xray to start
|
# Start continuous port monitoring in background
|
||||||
sleep 10
|
{
|
||||||
|
sleep 10 # Wait for xray to start initially
|
||||||
|
LAST_PORT=""
|
||||||
|
|
||||||
# Find xray API port and save to shared volume
|
while true; do
|
||||||
echo "Looking for xray API port..."
|
API_PORT=$(netstat -tlpn | grep xray | grep 127.0.0.1 | awk '{print $4}' | cut -d: -f2 | head -1)
|
||||||
for i in {1..60}; do
|
if [ -n "$API_PORT" ] && [ "$API_PORT" != "$LAST_PORT" ]; then
|
||||||
API_PORT=$(netstat -tlpn | grep xray | grep 127.0.0.1 | awk '{print $4}' | cut -d: -f2 | head -1)
|
echo "Found xray API port: $API_PORT"
|
||||||
if [ -n "$API_PORT" ]; then
|
echo -n "$API_PORT" > /shared/xray-api-port
|
||||||
echo "Found xray API port: $API_PORT"
|
LAST_PORT="$API_PORT"
|
||||||
echo -n "$API_PORT" > /shared/xray-api-port
|
fi
|
||||||
break
|
sleep 5 # Check every 5 seconds
|
||||||
fi
|
done
|
||||||
echo "Waiting for xray API port... ($i/60)"
|
} &
|
||||||
sleep 1
|
PORT_MONITOR_PID=$!
|
||||||
done
|
|
||||||
|
|
||||||
# Continue running main process
|
# Wait for main process to finish
|
||||||
wait $MAIN_PID
|
wait $MAIN_PID
|
||||||
|
|
||||||
|
# Clean up port monitor
|
||||||
|
kill $PORT_MONITOR_PID 2>/dev/null
|
||||||
|
|||||||
Reference in New Issue
Block a user