Repository navigation
Expand file tree
/
Copy pathentrypoint.sh
More file actions
44 lines (36 loc) · 1.61 KB
/
Copy pathentrypoint.sh
File metadata and controls
44 lines (36 loc) · 1.61 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
#!/bin/bash
set -euo pipefail
# Start Pi SDK sidecar in background with lifecycle coupling
if [ -f "$APP_DIR/sidecar-helper/dist/server.js" ]; then
export SIDECAR_PORT="${SIDECAR_PORT:-9100}"
node "$APP_DIR/sidecar-helper/dist/server.js" &
SIDECAR_PID=$!
echo "[sidecar] Started Pi SDK sidecar (PID $SIDECAR_PID) on port $SIDECAR_PORT"
# Kill sidecar when main process exits
trap 'kill $SIDECAR_PID 2>/dev/null; wait $SIDECAR_PID 2>/dev/null' EXIT
# Monitor sidecar — if it dies, kill the main process too
# TERM trap prevents misleading "died" message on normal shutdown
(trap 'exit 0' TERM; while kill -0 $SIDECAR_PID 2>/dev/null; do sleep 5; done; echo "[sidecar] Sidecar died, shutting down container"; kill 1 2>/dev/null) &
# Wait for sidecar to be ready (up to 15s)
for i in $(seq 1 30); do
if curl -sf http://127.0.0.1:$SIDECAR_PORT/health > /dev/null 2>&1; then
echo "[sidecar] Health check passed"
break
fi
sleep 0.5
done
if ! curl -sf http://127.0.0.1:$SIDECAR_PORT/health > /dev/null 2>&1; then
echo "[sidecar] ERROR: sidecar failed to become healthy within 15s" >&2
exit 1
fi
# Run app in background + wait — ensures SIGTERM/SIGINT forwarding
# and EXIT trap fires to clean up sidecar
uv run entrypoint.py &
APP_PID=$!
trap 'kill -TERM $APP_PID 2>/dev/null || true' TERM
trap 'kill -INT $APP_PID 2>/dev/null || true' INT
wait $APP_PID
else
echo "[sidecar] WARNING: sidecar-helper/dist/server.js not found, AI features will not be available"
exec uv run entrypoint.py
fi