【发布时间】:2021-08-06 22:54:18
【问题描述】:
我尝试在我的应用程序上安装 PM2,它在 localhost 上运行良好。但是,当我将应用程序移动到 docker 容器中并尝试在 Linux 机器上运行时,就会出现问题。
我正在运行命令 npm run production,它执行以下代码:
pm2 start ecosystem.config.js --env production --no-autorestart
之后,在命令行中,我看到了 PM2 如何在所有可用内核上启动和启动我的应用程序。
app | [PM2] PM2 Successfully daemonized
app | [PM2][WARN] Applications App not running, starting...
app | [PM2] App [App] launched (2 instances)
app | ┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
app | │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
app | ├─────┼───────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
app | │ 0 │ App │ default │ 1.0.0 │ cluster │ 36 │ 0s │ 0 │ online │ 0% │ 38.0mb │ root │ disabled │
app | │ 1 │ App │ default │ 1.0.0 │ cluster │ 43 │ 0s │ 0 │ online │ 0% │ 25.0mb │ root │ disabled │
app | └─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
然后它返回一条消息:
app exited with code 0
整个过程一次又一次地结束...... 我尝试在 'fork' 上的 'cluster_mode' 上运行它,我尝试使用 --no-autorestart 运行它,但它仍然不断重启。
我真的不知道我做错了什么?
@@EDIT,添加了生态系统.config.js
module.exports = {
apps : [{
name: 'App',
script: './build/server/index.js',
// Options reference: https://pm2.keymetrics.io/docs/usage/application-declaration/
exec_mode: 'cluster_mode',
args: 'none',
instances: os.cpus().length,
autorestart: false,
watch: false,
// max_memory_restart: '3G',
env: {
NODE_ENV:'development',
},
env_production: {
NODE_ENV:'production',
}
}],
deploy : {
production : {
user : 'szygendab',
host : '212.83.163.1',
ref : 'origin/master',
repo : 'git@github.com:repo.git',
path : '/var/www/production',
'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production'
}
}
};
【问题讨论】:
-
日志中有什么内容吗?你能分享你的生态系统.config.js 吗?您可以编辑您的问题以包含详细信息。
-
退出代码不是错误代码,因此启动命令可能有问题。
-
我在问题中添加了生态系统文件