37 lines
1.1 KiB
Bash
37 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# MCPletA2A — VPS startup script (used by systemd)
|
|
set -euo pipefail
|
|
|
|
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
REF_DIR="$BASE_DIR/reference_impl"
|
|
PLATFORM_DIR="$BASE_DIR/platform_impl"
|
|
|
|
export REF_IMPL_DIST="$REF_DIR/dist"
|
|
export MCPLET_CONFIG="$REF_DIR/config/reference.yaml"
|
|
export MCPLET_AGENT_MODULE="file://$REF_DIR/dist/agents/register.js"
|
|
|
|
# Start Mock Service in background
|
|
node "$REF_DIR/dist/mock-services/server.js" &
|
|
MOCK_PID=$!
|
|
|
|
# Wait until mock service is ready (max 10s)
|
|
for i in $(seq 1 20); do
|
|
if node -e "
|
|
const net = require('net');
|
|
const s = net.createConnection(5100, '127.0.0.1');
|
|
s.on('connect', () => { s.destroy(); process.exit(0); });
|
|
s.on('error', () => { s.destroy(); process.exit(1); });
|
|
" 2>/dev/null; then
|
|
echo "[vps] Mock Service ready (pid $MOCK_PID)"
|
|
break
|
|
fi
|
|
sleep 0.5
|
|
if [ "$i" -eq 20 ]; then
|
|
echo "[vps] ERROR: Mock Service did not start" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Start Platform Host (foreground — systemd monitors this)
|
|
exec node "$PLATFORM_DIR/dist/index.js"
|