-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.sh
More file actions
executable file
·63 lines (53 loc) · 2.05 KB
/
start.sh
File metadata and controls
executable file
·63 lines (53 loc) · 2.05 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
#!/usr/bin/env bash
# start.sh — Activate the virtual environment and launch the Control Center.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
VENV="$SCRIPT_DIR/venv"
PYTHON="$VENV/bin/python"
SEND="$SCRIPT_DIR/src/controlcenter_send.py"
CONFIG="$SCRIPT_DIR/config/controlcenter.yaml"
PIDFILE="$SCRIPT_DIR/controlcenter.pid"
# ── 1. Verify the virtual environment exists ───────────────────────────────────
if [[ ! -x "$PYTHON" ]]; then
echo "ERROR: virtual environment not found. Run ./bootstrap.sh first." >&2
exit 1
fi
source "$VENV/bin/activate"
# ── 2. Launch the application in the background ────────────────────────────────
echo "Starting Control Center..."
python "$SCRIPT_DIR/src/controlcenter.py" --config "$CONFIG" &
APP_PID=$!
echo "$APP_PID" > "$PIDFILE"
echo " PID: $APP_PID"
# ── 3. Wait for the status server to accept connections ────────────────────────
HOST="127.0.0.1"
PORT=9876
MAX_WAIT=15 # seconds
WAITED=0
echo "Waiting for status server on $HOST:$PORT..."
until python -c "
import socket, sys
try:
s = socket.create_connection(('$HOST', $PORT), timeout=1)
s.close()
sys.exit(0)
except OSError:
sys.exit(1)
" 2>/dev/null; do
if (( WAITED >= MAX_WAIT )); then
echo "ERROR: status server did not start within ${MAX_WAIT}s" >&2
kill "$APP_PID" 2>/dev/null || true
exit 1
fi
sleep 1
(( WAITED += 1 ))
done
echo " Server ready (${WAITED}s)."
# ── 4. Ping each status indicator ─────────────────────────────────────────────
INDICATORS=("DAQ" "Trigger" "Misc" "Storage")
echo "Pinging status indicators..."
for indicator in "${INDICATORS[@]}"; do
echo -n " $indicator: "
python "$SEND" ping && echo "ok" || echo "FAILED"
done
echo "Control Center is running (PID $APP_PID)."