为什么我永远使用的时候,我的节点应用程序进程总是停止?

时间:2022-10-30 07:17:16

On a free-tier Amazon EC2 instance, I set up a simple node.js Hello World app running on express.

在一个*层的Amazon EC2实例上,我设置了一个简单的节点。运行在express上的Hello World应用程序。

If I run npm start, my app runs fine and I can hit it from my browser, and I see the following output:

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

> myappname@0.0.0 start /home/ec2-user/app
> node ./bin/www

I have installed the forever tool globally. When I run forever start app.js, I see:

我在全球安装了forever工具。当我永远运行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

However, when I check forever list, I see that the process has stopped:

但是,当我查看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 

This is the only message in the log: error: Forever detected script was killed by signal: null

这是日志中唯一的消息:error:永远检测到的脚本被signal: null杀死

I'm unable to find any other log information. Why does it keep immediately stopping?

我找不到其他日志信息。为什么它会立即停止?

EDIT: I tried running it as nohup forever start app.js and got the same problem. I'm running the forever start and the forever list in the same ssh session, one after the other. The app's process seems to stop immediately.

编辑:我试着把它作为nohup forever start app.js来运行,得到了同样的问题。我在同一个ssh会话中运行一个接一个的forever start和forever列表。这个应用程序的过程似乎马上就停止了。

3 个解决方案

#1


6  

I'm guessing the process stops after you disconnect from ssh?

我猜在您断开与ssh的连接后进程将停止?

Try running forever with nohup first.

试着永远和nohup一起跑步。

nohup forever start app.js

When you disconnect from ssh the server kills all your shell's child processes. nohup disconnects a process from its parent shell.

当断开与ssh的连接时,服务器将杀死shell的所有子进程。nohup将进程从其父shell中断开连接。

#2


4  

I was able to resolve my problem thanks to this answer on a similar question: https://*.com/a/24914916/1791634

我能够解决我的问题,多亏了这个类似问题的答案:https://*.com/a/24914916/1791634

The process kept running when I used forever start ./bin/www instead of passing app.js

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

It remains to be seen whether this causes any trouble down the road.

这是否会在未来造成任何麻烦,还有待观察。

#3


1  

For me, I had to use "sudo forever" for it to work.

对我来说,我必须用“sudo forever”才能让它发挥作用。

#1


6  

I'm guessing the process stops after you disconnect from ssh?

我猜在您断开与ssh的连接后进程将停止?

Try running forever with nohup first.

试着永远和nohup一起跑步。

nohup forever start app.js

When you disconnect from ssh the server kills all your shell's child processes. nohup disconnects a process from its parent shell.

当断开与ssh的连接时,服务器将杀死shell的所有子进程。nohup将进程从其父shell中断开连接。

#2


4  

I was able to resolve my problem thanks to this answer on a similar question: https://*.com/a/24914916/1791634

我能够解决我的问题,多亏了这个类似问题的答案:https://*.com/a/24914916/1791634

The process kept running when I used forever start ./bin/www instead of passing app.js

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

It remains to be seen whether this causes any trouble down the road.

这是否会在未来造成任何麻烦,还有待观察。

#3


1  

For me, I had to use "sudo forever" for it to work.

对我来说,我必须用“sudo forever”才能让它发挥作用。