-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathserver-status.sh
More file actions
executable file
·71 lines (64 loc) · 1.73 KB
/
server-status.sh
File metadata and controls
executable file
·71 lines (64 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Check V25 demo server status
# Usage: bash server-status.sh [options] [port]
# -w, --wait Wait for server to be ready (HTTP 200)
# -t, --timeout Timeout in seconds for wait mode (default: 60)
PID_FILE="/tmp/erte-server.pid"
# Parse arguments
WAIT_MODE=false
TIMEOUT=60
PORT=8080
while [[ $# -gt 0 ]]; do
case $1 in
-w|--wait)
WAIT_MODE=true
shift
;;
-t|--timeout)
TIMEOUT="$2"
shift 2
;;
[0-9]*)
PORT="$1"
shift
;;
*)
echo "Unknown option: $1"
exit 1
;;
esac
done
# Wait mode: poll until server is ready
if [ "$WAIT_MODE" = true ]; then
echo "Waiting for server on port $PORT (timeout: ${TIMEOUT}s)..."
for i in $(seq 1 $TIMEOUT); do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${PORT}/" 2>/dev/null)
if [ "$STATUS" = "200" ]; then
echo "Server ready (HTTP 200)"
exit 0
fi
sleep 1
done
echo "Timeout: Server not ready after ${TIMEOUT}s"
exit 1
fi
# Normal status check
echo "=== ERTE V25 Demo Server Status ==="
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
if kill -0 $PID 2>/dev/null; then
echo "PID: $PID (running)"
else
echo "PID: $PID (stale)"
fi
else
echo "PID: no pid file"
fi
PID_ON_PORT=$(ss -tlpn 2>/dev/null | grep ":${PORT} " | sed -n 's/.*pid=\([0-9]*\).*/\1/p')
if [ -n "$PID_ON_PORT" ]; then
echo "Port $PORT: in use (PID: $PID_ON_PORT)"
else
echo "Port $PORT: free"
fi
STATUS=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${PORT}/" 2>/dev/null)
echo "HTTP: ${STATUS:-not reachable}"