stock-ai-agent/ecosystem.config.js
2026-02-20 22:31:31 +08:00

99 lines
3.6 KiB
JavaScript
Raw 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.

module.exports = {
apps: [{
// ============================================
// 应用基本配置
// ============================================
name: 'stock-agent',
// 直接运行 Python 模块
script: 'python3',
args: '-m app.main', // 使用 -m 模块方式运行
// ============================================
// 工作目录配置
// ============================================
// PM2 启动时的工作目录,必须在 backend 目录下
cwd: process.cwd() + '/backend',
// ============================================
// 实例配置
// ============================================
instances: 1, // 单实例FastAPI + asyncio 不支持多实例)
exec_mode: 'fork', // fork 模式
// ============================================
// 自动重启配置
// ============================================
autorestart: true, // 崩溃后自动重启
watch: false, // 关闭文件监控(生产环境必须关闭)
max_restarts: 10, // 最大重启次数
min_uptime: '10s', // 最小运行时间10秒内崩溃不计入重启次数
// ============================================
// 内存管理
// ============================================
max_memory_restart: '2G', // 内存超过 2G 自动重启
// Python 应用 + FastAPI + asyncio + LLM 分析需要较多内存
// 20 只美股分析 + 加密货币监控 + 模拟交易
// ============================================
// 日志配置
// ============================================
error_file: './logs/pm2-error.log',
out_file: './logs/pm2-out.log',
log_file: './logs/pm2-combined.log',
time: true, // 日志带时间戳
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
merge_logs: false, // 关闭日志合并(避免重复日志)
// ============================================
// 进程管理
// ============================================
kill_timeout: 8000, // 优雅关闭超时时间8秒
wait_ready: true, // 等待应用就绪
listen_timeout: 10000, // 监听超时10秒
// ============================================
// 环境变量配置
// ============================================
env: {
// 默认环境(开发)
PYTHONUNBUFFERED: '1', // Python 无缓冲输出(等同于 -u 参数)
LANG: 'en_US.UTF-8', // 字符编码
LC_ALL: 'en_US.UTF-8',
},
env_production: {
// 生产环境
NODE_ENV: 'production',
DEBUG: 'False',
PYTHONUNBUFFERED: '1',
},
env_development: {
// 开发环境
NODE_ENV: 'development',
DEBUG: 'True',
PYTHONUNBUFFERED: '1',
},
// ============================================
// 健康检查
// ============================================
// PM2 会定期检查应用是否存活
// 如果应用在指定时间内没有响应,会重启
kill_retry_time: 100, // 杀死进程前的等待时间
restart_delay: 4000, // 重启延迟4秒
// ============================================
// 进程 ID 文件
// ============================================
pid_file: './logs/pm2.pid', // PID 文件位置
// ============================================
// 其他配置
// ============================================
source_map_support: false, // Python 不需要 source map
disable_trace: false, // 启用堆栈跟踪
}]
};