13

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.

Brandon
  • 249
  • 1
  • 3
  • 13

4 Answers4

6

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.

Daniel
  • 38,041
  • 11
  • 92
  • 73
  • 1
    I'm running `forever start app.js` and `forever list` in the same ssh session, and it is always immediately stopped. I just tried running it as `nohup forever start app.js` and got the same result: the forever process was stopped as soon as I checked it. – Brandon Nov 01 '14 at 23:30
  • Check the log file. Is your node process dying from a script error? – Daniel Nov 02 '14 at 00:59
  • 1
    If I check the logfile shown in `forever list`, all I see is the error listed in the above question. Is there another log file I can check? – Brandon Nov 02 '14 at 01:35
  • I believe `&` it's missing on nohup command.. ie: `nohup forever start app.js &` – Roberto14 May 17 '16 at 14:09
  • You have to invoke "forever start ". In your case (as seen when you do npm start) the file is located at ./bin/www , not at "app.js". Regards – Hbas Aug 08 '18 at 14:47
4

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.

Community
  • 1
  • 1
Brandon
  • 249
  • 1
  • 3
  • 13
  • 1
    why should they even allow `forever ./bin/www` if the objective to use forever is achieved only if `forever start ./bin/www` is used – suku Jan 30 '17 at 06:19
  • without the start , you can see the log on the SSH console – Diptox Mar 26 '17 at 11:22
  • But why do I `forever myscript.js` if I can just `node myscript.js` without using forever? – Gherman Sep 14 '17 at 08:21
1

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

Erik Villegas
  • 954
  • 13
  • 29
0

If you are starting the server after updating the code. Pull the latest code and run

npm install

Now run

forever start app.js

This will fix the issue

dpacman
  • 3,683
  • 2
  • 20
  • 35