Reworked pasarguard nodes daemonset.
This commit is contained in:
@@ -135,10 +135,6 @@ data:
|
||||
port: 62050
|
||||
protocol: TCP
|
||||
targetPort: 62050
|
||||
- name: metrics
|
||||
port: 9550
|
||||
protocol: TCP
|
||||
targetPort: 9550
|
||||
EOF
|
||||
|
||||
echo "Service created: ${SERVICE_NAME}.${NAMESPACE}.svc.cluster.local"
|
||||
@@ -172,69 +168,6 @@ data:
|
||||
echo "IngressRouteTCP created: ${INGRESS_NAME}"
|
||||
echo "Traffic to ${DNS_NAME}:443 will be routed to ${SERVICE_NAME}:443"
|
||||
|
||||
exporter-start.sh: |
|
||||
#!/bin/sh
|
||||
# Install required tools
|
||||
apk add --no-cache wget curl iproute2-ss bash
|
||||
|
||||
# Download v2ray-exporter
|
||||
echo "Downloading v2ray-exporter..."
|
||||
ARCH=$(uname -m)
|
||||
case $ARCH in
|
||||
x86_64)
|
||||
BINARY_ARCH="amd64"
|
||||
;;
|
||||
aarch64|arm64)
|
||||
BINARY_ARCH="arm64"
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported architecture: $ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Detected architecture: $ARCH, using binary: v2ray-exporter_linux_$BINARY_ARCH"
|
||||
wget -L -O /tmp/v2ray-exporter "https://github.com/wi1dcard/v2ray-exporter/releases/download/v0.6.0/v2ray-exporter_linux_$BINARY_ARCH"
|
||||
mv /tmp/v2ray-exporter /usr/local/bin/v2ray-exporter
|
||||
chmod +x /usr/local/bin/v2ray-exporter
|
||||
|
||||
# Wait for initial 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
|
||||
if [ -f /shared/xray-api-port ]; then
|
||||
API_PORT=$(cat /shared/xray-api-port)
|
||||
if [ -n "$API_PORT" ]; then
|
||||
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=$!
|
||||
|
||||
# Wait for exporter to exit or port file to change
|
||||
while kill -0 $EXPORTER_PID 2>/dev/null; do
|
||||
if [ -f /shared/xray-api-port ]; then
|
||||
NEW_PORT=$(cat /shared/xray-api-port)
|
||||
if [ "$NEW_PORT" != "$API_PORT" ]; then
|
||||
echo "API port changed from $API_PORT to $NEW_PORT, restarting exporter"
|
||||
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
|
||||
sleep 2
|
||||
done
|
||||
|
||||
pasarguard-start.sh: |
|
||||
#!/bin/sh
|
||||
# Read API_KEY from shared volume created by init container
|
||||
@@ -246,46 +179,4 @@ data:
|
||||
fi
|
||||
|
||||
cd /app
|
||||
|
||||
# Start main process in background
|
||||
./main &
|
||||
MAIN_PID=$!
|
||||
|
||||
# Detect xray API port BEFORE starting monitoring loop
|
||||
echo "Detecting xray API port..."
|
||||
for i in $(seq 1 60); do
|
||||
API_PORT=$(netstat -tlnp 2>/dev/null | 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 to start... ($i/60)"
|
||||
sleep 1
|
||||
done
|
||||
|
||||
if [ -z "$API_PORT" ]; then
|
||||
echo "WARNING: Could not detect xray API port after 60 seconds"
|
||||
fi
|
||||
|
||||
# Start continuous port monitoring in background
|
||||
{
|
||||
LAST_PORT="$API_PORT"
|
||||
|
||||
while true; do
|
||||
API_PORT=$(netstat -tlnp 2>/dev/null | grep xray | grep 127.0.0.1 | awk '{print $4}' | cut -d: -f2 | head -1)
|
||||
if [ -n "$API_PORT" ] && [ "$API_PORT" != "$LAST_PORT" ]; then
|
||||
echo "API port changed from $LAST_PORT to $API_PORT"
|
||||
echo -n "$API_PORT" > /shared/xray-api-port
|
||||
LAST_PORT="$API_PORT"
|
||||
fi
|
||||
sleep 5 # Check every 5 seconds
|
||||
done
|
||||
} &
|
||||
PORT_MONITOR_PID=$!
|
||||
|
||||
# Wait for main process to finish
|
||||
wait $MAIN_PID
|
||||
|
||||
# Clean up port monitor
|
||||
kill $PORT_MONITOR_PID 2>/dev/null
|
||||
exec ./main
|
||||
|
||||
@@ -114,37 +114,6 @@ spec:
|
||||
- name: scripts
|
||||
mountPath: /scripts
|
||||
containers:
|
||||
- name: xray-exporter
|
||||
image: alpine:3.18
|
||||
imagePullPolicy: IfNotPresent
|
||||
command:
|
||||
- /bin/sh
|
||||
- /scripts/exporter-start.sh
|
||||
ports:
|
||||
- name: metrics
|
||||
containerPort: 9550
|
||||
protocol: TCP
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /scrape
|
||||
port: metrics
|
||||
initialDelaySeconds: 60
|
||||
periodSeconds: 30
|
||||
timeoutSeconds: 10
|
||||
failureThreshold: 3
|
||||
resources:
|
||||
requests:
|
||||
memory: "64Mi"
|
||||
cpu: "50m"
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
cpu: "150m"
|
||||
volumeMounts:
|
||||
- name: shared-data
|
||||
mountPath: /shared
|
||||
readOnly: true
|
||||
- name: scripts
|
||||
mountPath: /scripts
|
||||
- name: pasarguard-node
|
||||
image: 'pasarguard/node:v0.1.3'
|
||||
imagePullPolicy: Always
|
||||
|
||||
Reference in New Issue
Block a user