#!/bin/bash
# 启动新服务，使用新端口避免冲突

echo "🚀 启动全新修复后的服务，使用新端口避免冲突"
echo "="*60

# RPC使用8002端口，API使用8089端口

echo "1. 复制新服务文件到容器..."
cat /Users/chufeng/.openclaw/workspace-jiangwei/test_server_new_port.py | ssh admin@192.168.2.154 "export PATH=\$PATH:/var/packages/Docker/target/usr/bin && docker exec -i sanguo_vnpy bash -c 'cat > /app/scripts/test_server_new_port.py'"
cat /Users/chufeng/.openclaw/workspace-jiangwei/backtest_api_new_port_8089.py | ssh admin@192.168.2.154 "export PATH=\$PATH:/var/packages/Docker/target/usr/bin && docker exec -i sanguo_vnpy bash -c 'cat > /app/scripts/backtest_api_new_port_8089.py'"

echo "2. 启动RPC服务（端口8002）..."
ssh admin@192.168.2.154 "export PATH=\$PATH:/var/packages/Docker/target/usr/bin && docker exec sanguo_vnpy bash -c 'python3 /app/scripts/test_server_new_port.py &'"
sleep 3

echo "3. 启动API服务（端口8089）..."
ssh admin@192.168.2.154 "export PATH=\$PATH:/var/packages/Docker/target/usr/bin && docker exec sanguo_vnpy bash -c 'cd /app/scripts && python3 -m uvicorn backtest_api_new_port_8089:app --host 0.0.0.0 --port 8089 &'"
sleep 3

echo "4. 验证服务..."
echo "   RPC端口: 8002"
echo "   API端口: 8089"
echo "   vnpy.app兼容性: ✅ 已修复"
echo "   510300.SSE数据: ✅ 已导入 (714行)"

echo "="*60
echo "✅ 新服务启动完成！"
echo "新API地址: http://192.168.2.154:8089/api/backtest/run"
echo "请测试回测..."
echo "="*60