auto_trade_sys/backend/start_recommendations.sh
薇薇安 4ccf067b24 fix(start_recommendations): 优化虚拟环境激活逻辑
更新 `start_recommendations.sh` 脚本,优先使用 `trading_system/.venv` 激活虚拟环境,确保与服务器部署一致。增强错误提示信息,提升用户体验与环境配置的准确性。
2026-02-23 19:24:33 +08:00

40 lines
1.2 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 启动推荐服务recommendations_main
# 优先使用 trading_system/.venv与服务器实际部署一致其次 backend/.venv
cd "$(dirname "$0")"
BACKEND_DIR="$(pwd)"
PROJECT_ROOT="$(cd .. && pwd)"
TRADING_VENV="${PROJECT_ROOT}/trading_system/.venv"
# 激活虚拟环境:优先 trading_system/.venv其次 backend 下
if [ -d "${TRADING_VENV}" ]; then
source "${TRADING_VENV}/bin/activate"
elif [ -d ".venv" ]; then
source .venv/bin/activate
elif [ -d "../.venv" ]; then
source ../.venv/bin/activate
else
echo "错误: 找不到虚拟环境trading_system/.venv、.venv 或 ../.venv"
exit 1
fi
# 设置环境变量
export PYTHONPATH="${PROJECT_ROOT}"
export DB_HOST=${DB_HOST:-localhost}
export DB_PORT=${DB_PORT:-3306}
export DB_USER=${DB_USER:-autosys}
export DB_PASSWORD=${DB_PASSWORD:-}
export DB_NAME=${DB_NAME:-auto_trade_sys}
export LOG_LEVEL=${LOG_LEVEL:-INFO}
# 创建日志目录
mkdir -p "${PROJECT_ROOT}/logs"
# 启动推荐服务(后台运行)
cd "${PROJECT_ROOT}"
nohup python -m trading_system.recommendations_main > logs/recommendations.log 2>&1 &
PID=$!
echo "推荐服务已启动PID: $PID"
echo "日志: tail -f ${PROJECT_ROOT}/logs/recommendations.log"