当我永远使用时,为什么我的节点应用程序进程会一直停止?

Bra*_*don 13 amazon-ec2 amazon-web-services node.js forever

在免费的Amazon EC2实例上,我设置了一个在express上运行的简单node.js Hello World应用程序.

如果我运行npm start,我的应用运行正常,我可以从我的浏览器点击它,我看到以下输出:

> myappname@0.0.0 start /home/ec2-user/app
> node ./bin/www
Run Code Online (Sandbox Code Playgroud)

我在全球范围内安装了永久工具.当我跑步时forever start app.js,我看到:

warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: app/app.js
Run Code Online (Sandbox Code Playgroud)

但是,当我检查时forever list,我发现该进程已停止:

info:    Forever processes running
data:        uid  command             script forever pid  id logfile                          uptime  
data:    [0] 2v0J /usr/local/bin/node app.js 2455    2457    /home/ec2-user/.forever/2v0J.log STOPPED 
Run Code Online (Sandbox Code Playgroud)

这是日志中唯一的消息: error: Forever detected script was killed by signal: null

我无法找到任何其他日志信息.为什么它会立即停止?

编辑:我尝试运行它,nohup forever start app.js并得到了同样的问题.我在一个接一个的同一个ssh会话中运行forever start和运行forever list.该应用程序的过程似乎立即停止.

Dan*_*iel 6

我猜你从ssh断开连接后进程停止了吗?

首先尝试永远运行nohup.

nohup forever start app.js
Run Code Online (Sandbox Code Playgroud)

当您从ssh断开连接时,服务器会终止所有shell的子进程. nohup断开进程与其父shell的连接.


Bra*_*don 4

由于类似问题的答案,我能够解决我的问题: /sf/answers/1744044151/

forever start ./bin/www当我使用而不是传递 app.js时,进程保持运行

这是否会给未来带来任何麻烦还有待观察。