48 lines
1.0 KiB
JavaScript
48 lines
1.0 KiB
JavaScript
// PM2 进程守护配置
|
||
// 使用方式:
|
||
// pm2 start ecosystem.config.cjs
|
||
// pm2 save
|
||
// pm2 startup
|
||
|
||
module.exports = {
|
||
apps: [
|
||
{
|
||
name: 'chuanqi-server',
|
||
script: 'index.js',
|
||
cwd: './module/server',
|
||
|
||
// 使用 Node.js ESM(package.json type:module)
|
||
interpreter: 'node',
|
||
interpreter_args: '--env-file=.env',
|
||
|
||
// 实例数量:cluster 模式多核利用(生产推荐)
|
||
// 单核服务器改为 instances: 1, exec_mode: 'fork'
|
||
instances: 1,
|
||
exec_mode: 'fork',
|
||
|
||
// 自动重启
|
||
watch: false,
|
||
autorestart: true,
|
||
max_restarts: 10,
|
||
restart_delay: 3000,
|
||
|
||
// 内存超出 512MB 自动重启
|
||
max_memory_restart: '512M',
|
||
|
||
// 日志配置
|
||
out_file: './logs/pm2-out.log',
|
||
error_file: './logs/pm2-error.log',
|
||
merge_logs: true,
|
||
log_date_format: 'YYYY-MM-DD HH:mm:ss',
|
||
|
||
// 环境变量
|
||
env: {
|
||
NODE_ENV: 'production',
|
||
},
|
||
env_development: {
|
||
NODE_ENV: 'development',
|
||
},
|
||
}
|
||
]
|
||
}
|