evetool / scripts /entrypoint.sh
hunian
添加 Dockerfile、docker-compose.yml 和多个配置文件,设置 evetool 项目的基础结构
5d85019
Raw
History Blame Contribute Delete
2.04 kB
#!/usr/bin/env bash
# evetool 启动链: iii 引擎 (后台) -> browser-worker (后台) -> mcp-gateway (前台)
# 任何进程挂了整体退出, docker 会按 restart policy 重启
set -uo pipefail
III_URL="${III_URL:-ws://127.0.0.1:49134}"
III_CONFIG="${III_CONFIG:-/opt/evetool/iii-config.yaml}"
LOG_DIR="/opt/evetool/data"
mkdir -p "$LOG_DIR"
echo "[entrypoint] starting iii engine (config=$III_CONFIG)"
iii --config "$III_CONFIG" >"$LOG_DIR/iii.log" 2>&1 &
III_PID=$!
# 等 49134 端口起来 (最多 30s)
echo "[entrypoint] waiting for iii engine ws port 49134..."
for i in $(seq 1 30); do
if (echo > /dev/tcp/127.0.0.1/49134) 2>/dev/null; then
echo "[entrypoint] iii engine up (pid=$III_PID)"
break
fi
if ! kill -0 "$III_PID" 2>/dev/null; then
echo "[entrypoint] FATAL: iii engine died, log tail:" >&2
tail -50 "$LOG_DIR/iii.log" >&2
exit 1
fi
sleep 1
done
# 拉起 browser-worker
echo "[entrypoint] starting browser-worker"
(
cd /opt/evetool/workers/browser
# 第一次跑前先 sync 依赖, 然后用 uv run 启动
uv sync 2>>"$LOG_DIR/browser-worker.log"
exec uv run python worker.py
) >"$LOG_DIR/browser-worker.log" 2>&1 &
BW_PID=$!
echo "[entrypoint] browser-worker pid=$BW_PID"
# 拉起 mcp-gateway
echo "[entrypoint] starting mcp-gateway"
(
cd /opt/evetool/mcp-gateway
uv sync 2>>"$LOG_DIR/mcp-gateway.log"
exec uv run python server.py
) >"$LOG_DIR/mcp-gateway.log" 2>&1 &
GW_PID=$!
echo "[entrypoint] mcp-gateway pid=$GW_PID"
# 收尸: 任何一个挂了整体退出
cleanup() {
echo "[entrypoint] shutting down (iii=$III_PID browser=$BW_PID gateway=$GW_PID)"
kill -TERM "$GW_PID" 2>/dev/null || true
kill -TERM "$BW_PID" 2>/dev/null || true
kill -TERM "$III_PID" 2>/dev/null || true
wait 2>/dev/null || true
exit 0
}
trap cleanup SIGTERM SIGINT
# 主进程阻塞等, 任意子进程死了就一起退
wait -n "$III_PID" "$BW_PID" "$GW_PID"
EXIT_CODE=$?
echo "[entrypoint] one of (iii/browser/gateway) exited with $EXIT_CODE, killing others" >&2
cleanup
exit 1