error: Forever detected script exited with code: 1 - node.js

I am using forever to restart a nodejs-app in case it crashes. In some situations the app does not get restarted. Forever just displays the message:
error: Forever detected script exited with code: 1
I do not want to solve the issue within the app itself, I just need forever to restart over and over again. Maybe I am missing a paremeter?
The other questions concerning forever not restarting here on SO do not address my specific case.

I think I solved it:
As ist seems both parameters --minUptime and --spinSleepTime have to be set. Otherwise a so called "spinning" script will not be restarted.
So in order to restart a "spinning" script forever needs to have both parameters set like:
forever --minUptime 5000 --spinSleepTime 3000 app.js

Related

forever is not working as expected after closing terminal or console

I have installed forever on shared hosting Cpanel for node js application when I run forever start app.js, node js application works on the server.
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.js
But when I close terminal or console then node app stopped working. Any suggestions around it?
Closing the terminal will typically close the application running. Consider using tmux or screen to launch the app or also nohup.
Launching this way should be considered a short-term solution. You probably want to look at how your specific Linux distribution handles startup scripts and services.
like maldina said closing forever will stop your app consider
consider upstart (it runs tasks when the computer is started)
you basiclly create a conf file and place it in your init folder "var/etc/init"
the file content should look like this
#!upstart
description "my-app"
start on started mountall
stop on shutdown
# Automatically Respawn:
respawn
respawn limit 99 5
env NODE_ENV=production
exec node /somepath/myapp/server.js >> /var/log/myapp.log 2>&1
you can use the following commands to manage your app
sudo start my-app
sudo stop my-app
sudo restart my-app

forever with nodemon not working in node js

hello i am trying to run node server with forever like below
forever start -c nodemon app.js
when i run this command on terminal it shows below line and when i hit api path it gives server not running
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.js
and node does not work can anyone guide where i am missing
Thanks

Get status of forever app or pm2 app

I am currently using forever but am considering switching to pm2 because forever does not provide a status option.
I cannot do:
forever status myApp
To determine if my app is running or not I must do:
forever list | grep -i myApp
And even with this it is unreliable because myApp might be listed in a stopped state (I appreciate you could come up with some ugly grep solution to accomodate but I want something natural).
With pm2 the docs say you can do:
pm2 show myApp # Show all informations about application
pm2 seems far more natural.
Any thoughts on how to get app status using forever without grepping the forever list?
How does pm2 compare regarding getting app status?
Forever cannot do this without using forever list.
pm2 can and pm2 show works great with expected exit codes.
I tried pm2 for this sole reason and found it much better than Forever. It does everything Forever does but (unbelievable but true) even simpler than Forever.
The commands are the same with more.
Example:
forever start app.js
pm2 start app.js --name "api" // built in pidfile management here
pm2 start app.js -i 0 --name "api" // load balance your app on all cores! WOW!
pm2 list // same as forever list
pm2 show api // returns 0 or 1 return code as expected
pm2 restart api // if running on multiple cores, restarts all associated processes
Forever is dead, pm2 is the new king! PM2 forever!
No need for reboot crontab entries. pm2 handles that with:
pm2 startup
pm2 save
Done!

Running Node as a Service with Forever [duplicate]

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.
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.
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.
For me, I had to use "sudo forever" for it to work.
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

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

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.
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.
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.
For me, I had to use "sudo forever" for it to work.
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

Resources