为什么PM2无法启动我的Node进程? [英] Why is PM2 not launching my Node process?
问题描述
以前,我已经成功实现了PM2,但目前还没有.
Previously I have had success implementing PM2, but not currently.
如果手动启动我的节点应用程序 可以正常运行,但是即使PM2 出现却无法启动,我也无法通过PM2运行它.这就是我的意思:
My node app does run just fine if I start it manually, but nothing I do gets it to run via PM2, even though PM2 appears to be starting it up. Here's what I mean:
如果我运行pm2 start server/index.js,则终端中的响应显示为:
If I run pm2 start server/index.js, the response in the terminal reads:
$ pm2 start server/index.js
[PM2] Spawning PM2 daemon with pm2_home=c:\pm2_system\.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting D:\Program Files\nodeApps\service-management-api\server\index.js in fork_mode (1 instance)
[PM2] Done.*
然后,终端将打印出带有应用信息的表格.它看起来不太好粘贴在这里,所以我将其列出:
Then the terminal prints out a table with App info. It doesn't look pretty pasted here so I'll list it out:
App Name: index
id: 0
version: 1.0.0
mode: fork
pid: 8984
status: online
restart: 0
update 0s
cpu: 0%
mem: 26.0 MB
user: ME
watching: disabled
看来节点进程应该正在运行.但是,如果我立即输入 pm2列表,则表明没有进程在运行.如果我输入pm2停止索引,它会显示:
It appears that the node process should be running. But if I immediately enter pm2 list it shows no processes running. If I enter pm2 stop index, it says:
$ pm2 stop index
[PM2] Spawning PM2 daemon with pm2_home=c:\pm2_system\.pm2
[PM2] PM2 Successfully daemonized
[PM2][ERROR] Process index not found
或者,如果我尝试在命令中使用生态系统.config.js,则会得到类似的结果.这是尝试的命令:
Alternatively, if I try using ecosystem.config.js in the commands, I get similar results. Here are the commands tried:
pm2 reload ecosystem.config.js
pm2 start ecosystem.config.js
运行这些命令的示例结果:
Example result of running those commmands:
$ pm2 start ecosystem.config.js
[PM2] Spawning PM2 daemon with pm2_home=c:\pm2_system\.pm2
[PM2] PM2 Successfully daemonized
[PM2][WARN] Applications sm_api not running, starting...
[PM2] App [sm_api] launched (2 instances)
CLI会打印表格,显示两个实例的状态为在线",并处于启用"状态.但是,应用程序未运行(通过浏览器进行测试时),并且"pm2 show"返回:
And CLI prints table showing two instances with status "online" and watching "enabled". And yet, app isn't running (when tested from browser) and "pm2 show " returns:
[PM2] Spawning PM2 daemon with pm2_home=c:\pm2_system\.pm2
[PM2] PM2 Successfully daemonized
[PM2][WARN] <app name> doesn't exist
任何提示我的pm2出了什么问题吗?
Any clues what's gone awry with my pm2?
这是我的ecosystem.config.js文件:
Heres my ecosystem.config.js file:
module.exports = {
apps : [{
name: 'sm_api',
script: 'server/index.js',
"log_date_format" : "YYYY-MM-DD HH:mm Z",
// Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
args: 'one two',
instances: 'max',
error_file : "C:\\pm2_system\\.pm2\\logs\\sm-api-error",
out_file: "C:\\pm2_system\\.pm2\\logs\\sm-api-out",
autorestart: true,
watch: "../",
max_restarts: 10,
max_memory_restart: '1G',
env: {
NODE_ENV: 'development'
},
env_production: {
NODE_ENV: 'production'
},
exec_mode: 'cluster'
}],
};
在Windows Server 2012环境中运行.请注意,我打算在pm2工作后添加pm2-windows-service软件包.
Running in Windows Server 2012 environment. Note that I intend to add pm2-windows-service package after I get pm2 working.
推荐答案
好,在将问题发布到pm2 github问题页面后,我得到了答案.
Ok, I got the answer after posting an issue to the pm2 github issues page.
在这里共享它,以防其他任何人遇到这种情况:
Sharing it here in case anyone else finds themselves in this situation:
https://github.com/Unitech/pm2/issues/4113
(基本上pm2 3.2.5引入了一个错误,该错误在Windows中导致此问题.我的开发安装为3.2.4.此问题已通过在生产环境中恢复为3.2.4来解决.简单的过程,请参见上面的链接中的说明.)
(Basically pm2 3.2.5 introduced a bug that causes this issue in Windows. My dev install was 3.2.4. The issue was resolved by reverting to 3.2.4 in production. Simple process, see instructions at link above.)
这篇关于为什么PM2无法启动我的Node进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!