chore: remove legacy startup paths

This commit is contained in:
2026-04-03 13:45:57 +08:00
parent 2027635efe
commit dc0b250adc
36 changed files with 598 additions and 1923 deletions

View File

@@ -5,22 +5,16 @@
#
# 启动模式说明:
# -------------
# 本脚本支持两种启动模式:
#
# 1. 微服务模式 (默认) - 启动 4 个独立服务 + Gateway
# 这是推荐的开发模式,各服务独立运行,便于单独调试和重启
# - agent_service (端口 8000): Agent 生命周期管理
# - runtime_service (端口 8003): 运行时配置和 Pipeline 执行
# - trading_service (端口 8001): 市场数据和交易操作
# - news_service (端口 8002): 新闻采集和富化
# - gateway (端口 8765): WebSocket 网关,前端连接入口
#
# 2. 独立模式 (--standalone) - 仅启动 Gateway
# Gateway 内部会自行管理服务,适合快速验证或资源受限环境
# 本脚本支持当前开发主路径:
# 启动 4 个独立服务 + 由 runtime_service 托管的 Gateway
# - agent_service (端口 8000): Agent 生命周期管理
# - runtime_service (端口 8003): 运行时配置和 Pipeline 执行
# - trading_service (端口 8001): 市场数据和交易操作
# - news_service (端口 8002): 新闻采集和富化
# - gateway (端口 8765): 由 runtime_service 拉起的 WebSocket 网关
#
# 用法:
# ./start-dev.sh # 启动微服务模式
# ./start-dev.sh --standalone # 启动独立模式
# ./start-dev.sh # 启动开发环境
# ./start-dev.sh --help # 显示帮助信息
#
@@ -51,9 +45,6 @@ readonly NC='\033[0m' # No Color
# 进程 ID 数组
PIDS=()
# 启动模式: "microservices" 或 "standalone"
MODE="microservices"
# ============================================
# 工具函数
# ============================================
@@ -87,25 +78,18 @@ show_help() {
大时代 Development Startup Script
用法:
./start-dev.sh [选项]
./start-dev.sh [选项]
选项:
--standalone 以独立模式启动(仅启动 Gateway内部管理服务
--help, -h 显示此帮助信息
模式说明:
微服务模式 (默认):
启动 4 个独立微服务 + Gateway各服务独立进程便于单独调试
- agent_service: http://localhost:8000 (Agent 生命周期)
- trading_service: http://localhost:8001 (市场数据)
- news_service: http://localhost:8002 (新闻服务)
- runtime_service: http://localhost:8003 (运行时管理)
- gateway: ws://localhost:8765 (WebSocket 网关)
独立模式 (--standalone):
仅启动 Gateway由 Gateway 内部自行管理服务
适合快速验证或资源受限环境
开发模式:
启动 4 个独立微服务 + 托管 Gateway各服务独立进程便于单独调试
- agent_service: http://localhost:8000 (Agent 生命周期)
- trading_service: http://localhost:8001 (市场数据)
- news_service: http://localhost:8002 (新闻服务)
- runtime_service: http://localhost:8003 (运行时管理)
- gateway: ws://localhost:8765 (由 runtime_service 托管)
环境要求:
- Python 3.9+
@@ -113,8 +97,7 @@ show_help() {
- .env 文件 (可选但推荐)
示例:
./start-dev.sh # 启动微服务模式
./start-dev.sh --standalone # 启动独立模式
./start-dev.sh # 启动开发环境
EOF
}
@@ -125,10 +108,6 @@ EOF
parse_args() {
while [[ $# -gt 0 ]]; do
case "$1" in
--standalone)
MODE="standalone"
shift
;;
--help|-h)
show_help
exit 0
@@ -249,13 +228,7 @@ check_env_file() {
check_ports() {
log_step "检查端口占用情况..."
local ports=()
if [[ "$MODE" == "microservices" ]]; then
ports=($AGENT_SERVICE_PORT $TRADING_SERVICE_PORT $NEWS_SERVICE_PORT $RUNTIME_SERVICE_PORT $GATEWAY_PORT)
else
ports=($GATEWAY_PORT)
fi
local ports=($AGENT_SERVICE_PORT $TRADING_SERVICE_PORT $NEWS_SERVICE_PORT $RUNTIME_SERVICE_PORT $GATEWAY_PORT)
local occupied=()
for port in "${ports[@]}"; do
@@ -340,16 +313,88 @@ start_service() {
PIDS+=($!)
}
start_gateway() {
log_step "启动 Gateway (WebSocket 服务)..."
log_info "Gateway 将作为子进程启动 (端口 ${GATEWAY_PORT})"
log_info "前端连接地址: ws://localhost:${GATEWAY_PORT}"
wait_for_runtime_service() {
log_step "等待 runtime_service 就绪..."
SERVICE_NAME="gateway" python -m backend.main \
--mode live \
--host 0.0.0.0 \
--port "$GATEWAY_PORT" &
PIDS+=($!)
local runtime_url="http://127.0.0.1:${RUNTIME_SERVICE_PORT}/health"
local attempts=30
for ((i=1; i<=attempts; i++)); do
if python - <<PY >/dev/null 2>&1; then
import urllib.request
with urllib.request.urlopen("${runtime_url}", timeout=1.5) as resp:
raise SystemExit(0 if resp.status == 200 else 1)
PY
log_info "runtime_service 已就绪: ${runtime_url}"
return 0
fi
sleep 1
done
log_error "runtime_service 未在预期时间内就绪"
return 1
}
start_managed_runtime() {
log_step "通过 runtime_service 创建默认运行时..."
local runtime_api="http://127.0.0.1:${RUNTIME_SERVICE_PORT}/api/runtime/start"
if ! python - <<PY; then
import json
import os
import sys
import urllib.request
tickers_env = os.getenv("TICKERS", "")
tickers = [item.strip().upper() for item in tickers_env.split(",") if item.strip()]
if not tickers:
tickers = ["AAPL", "MSFT", "GOOGL", "AMZN", "NVDA", "META", "TSLA", "AMD", "NFLX", "AVGO", "PLTR", "COIN"]
def _env_int(name: str, default: int) -> int:
value = os.getenv(name, "").strip()
return int(value) if value else default
def _env_float(name: str, default: float) -> float:
value = os.getenv(name, "").strip()
return float(value) if value else default
payload = {
"launch_mode": "fresh",
"tickers": tickers,
"schedule_mode": os.getenv("SCHEDULE_MODE", "daily").strip() or "daily",
"interval_minutes": _env_int("INTERVAL_MINUTES", 60),
"trigger_time": os.getenv("TRIGGER_TIME", "09:30").strip() or "09:30",
"max_comm_cycles": _env_int("MAX_COMM_CYCLES", 2),
"initial_cash": _env_float("INITIAL_CASH", 100000.0),
"margin_requirement": _env_float("MARGIN_REQUIREMENT", 0.0),
"enable_memory": os.getenv("ENABLE_MEMORY", "").strip().lower() in {"1", "true", "yes", "on"},
"mode": os.getenv("RUNTIME_MODE", "live").strip() or "live",
"poll_interval": _env_int("POLL_INTERVAL", 10),
}
data = json.dumps(payload).encode("utf-8")
req = urllib.request.Request(
"${runtime_api}",
data=data,
headers={"Content-Type": "application/json"},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=30) as resp:
body = json.loads(resp.read().decode("utf-8"))
except Exception as exc:
print(f"FAILED: {exc}", file=sys.stderr)
raise
print(json.dumps(body, ensure_ascii=False))
PY
log_error "通过 runtime_service 创建运行时失败"
return 1
fi
log_info "默认运行时已创建Gateway 将由 runtime_service 托管"
}
# ============================================
@@ -366,7 +411,7 @@ start_microservices_mode() {
echo -e " runtime_service: http://localhost:${RUNTIME_SERVICE_PORT}"
echo -e " trading_service: http://localhost:${TRADING_SERVICE_PORT}"
echo -e " news_service: http://localhost:${NEWS_SERVICE_PORT}"
echo -e " gateway: ws://localhost:${GATEWAY_PORT}"
echo -e " gateway: ws://localhost:${GATEWAY_PORT} (由 runtime_service 拉起)"
echo -e "${CYAN}==========================================${NC}"
echo ""
@@ -390,8 +435,8 @@ start_microservices_mode() {
start_service "trading_service" "backend.apps.trading_service:app" "$TRADING_SERVICE_PORT"
start_service "news_service" "backend.apps.news_service:app" "$NEWS_SERVICE_PORT"
# 启动 Gateway作为子进程
start_gateway
wait_for_runtime_service
start_managed_runtime
echo ""
log_info "所有服务已启动"
@@ -399,30 +444,6 @@ start_microservices_mode() {
echo ""
}
# ============================================
# 独立模式启动
# ============================================
start_standalone_mode() {
log_step "启动独立模式..."
echo ""
echo -e "${CYAN}==========================================${NC}"
echo -e "${CYAN} 独立模式 ${NC}"
echo -e "${CYAN}==========================================${NC}"
echo -e " gateway: ws://localhost:${GATEWAY_PORT}"
echo -e "${CYAN}==========================================${NC}"
echo ""
log_info "Gateway 将内部管理服务"
# 启动 Gateway独立模式
start_gateway
echo ""
log_info "Gateway 已启动(独立模式)"
log_info "按 Ctrl+C 停止服务"
echo ""
}
# ============================================
# 清理与信号处理
# ============================================
@@ -480,12 +501,7 @@ main() {
echo -e "${GREEN}==========================================${NC}"
echo ""
# 根据模式启动服务
if [[ "$MODE" == "standalone" ]]; then
start_standalone_mode
else
start_microservices_mode
fi
start_microservices_mode
# 等待所有后台进程
wait