34 lines
879 B
Bash
Executable File
34 lines
879 B
Bash
Executable File
#!/usr/bin/env bash
|
|
# Start the AICC capsule testbed bridge over WebSocket (headless).
|
|
# Usage: scripts/run_bridge.sh [port] (default 8765)
|
|
# Note: the bridge keeps running until interrupted (Ctrl-C).
|
|
set -euo pipefail
|
|
|
|
# Load API keys from the project .env file (if present)
|
|
if [ -f .env ]; then
|
|
set -a
|
|
# shellcheck disable=SC1091
|
|
. ./.env
|
|
set +a
|
|
fi
|
|
cd "$(dirname "$0")/.."
|
|
PORT="${1:-8765}"
|
|
|
|
if python3 - "$PORT" <<'EOF'
|
|
import socket, sys
|
|
port = int(sys.argv[1])
|
|
s = socket.socket()
|
|
if s.connect_ex(("127.0.0.1", port)) == 0:
|
|
print(f"port {port} is already in use")
|
|
sys.exit(1)
|
|
EOF
|
|
then
|
|
:
|
|
else
|
|
echo "error: a bridge may already be running on port $PORT." >&2
|
|
echo "stop it first, e.g.: fuser -k ${PORT}/tcp (or kill the run_bridge.sh process)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
exec testbed/.venv/bin/python -m testbed.bridge --host 127.0.0.1 --port "$PORT"
|