Why does my node app process keep getting stopped when I use forever?

元气小坏坏 提交于 2019-12-30 04:01:08

问题


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

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

> 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:

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:

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

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.


回答1:


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

Try running forever with nohup first.

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.




回答2:


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

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

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




回答3:


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



来源:https://stackoverflow.com/questions/26694100/why-does-my-node-app-process-keep-getting-stopped-when-i-use-forever

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!