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
Related
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
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
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
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
I am trying to run node server using forever command.
I installed forever globally using:
npm install forever -g
After installing forever I try to run my node script by using below command:
node_modules\.bin\forever start app.js
Below is my console:
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up f
or at least 1000ms
info: Forever processing file: app.js
Please help me to resolve this issue!
There is no problem here other than warnings for configs forever recommends you declare. If you see the final message there it tells you it has processed your script. Just run forever list and you should see your script running.
I ran into this same thing when installing npm via yum repository ( yum install npm ) and then installing forever whereas when I install node and npm via shell scripts and then install forever it doesn't occur. It must have something to do with the formulas for the package installer or potentially missing alias with flags with installer to set those values behind the scene.
Those don't mean it's not working. See below I created a js file using sample code from node's site and ran it manually (I flushed firewall to open port for app temporarily but you don't need that):
[root#app1 ~]# vi example.js
[root#app1 ~]# apf -f
apf(23924): {glob} flushing & zeroing chain policies
apf(23924): {glob} firewall offline
[root#app1 ~]# node example.js
Server running at http://127.0.0.1:1337/
I then start app using forever:
^C[root#app1 ~]# forever start example.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: example.js
Now I check to see if my app is running:
[root#app1 ~]# forever list
info: Forever processes running
data: uid command script forever pid logfile uptime
data: [0] dan1 /usr/bin/node example.js 23976 23978 /root/.forever/dan1.log 0:0:0:27.320
[root#app1 ~]#
This solved my issue:
forever start -c node [path/to/app]
"-c" means - Run commnad; and then just run via nodejs
This way - you get the Respawn by default of min. 1000ms uptime
Taken from: https://github.com/nodejitsu/forever/issues/422, by "Basarat"
If you are using node js with express framework then script will not start using :
forever start app.js
First stop all running apps:
forever stopall
When this Express framework used it must be started with:
forever start ./bin/www
First stop all running apps:
forever stopall
then use this command. It works for me and solved my issue:
forever -w ./bin/www
and you should find this in package.json file:
"scripts": {
"start": "node ./bin/www"
}
I hope it helps you.
One thing that also produces same kind of output, but doesn't start the application is if forever is unable to write to the specified log file. I had a case where the log file had become too big and this prevented the process from starting.
Firstly change your package.json scripts like
"scripts": {
"start": "forever ./bin/www.js"
}
than start this command on linux console:sudo npm start
for windows just :npm start
I just ran into this today on an AWS Lightsail server, and NONE of the answers here or elsewhere had any effect. Everything worked fine until upgrading from NodeJS 10.x to 13.x. I tried removing and reinstalling forever, changing the permissions on the files and directories, etc, and I kept getting the EACCES error. The issue seemed to be that forever could not create directories within its .forever directory. The only thing that worked was to do the following:
1) Remove the .forever folder and all its subfolders and contents. For me, this was accomplished as follows:
sudo rm -rf /home/bitnami/.forever
2) Manually recreate the .forever folder:
sudo mkdir /home/bitnami/.forever
3) Manually set the permissions on the .forever folder:
sudo chmod -R o+rwx /home/bitnami/.forever
4) Manually recreate the .forever/pids folder:
sudo mkdir /home/bitnami/.forever/pids
5) Manually set the permissions on the .forever/pids folder:
sudo chmod -R o+rwx /home/bitnami/.forever/pids
6) Manually recreate the .forever/sock folder:
sudo mkdir /home/bitnami/.forever/sock
7) Manually set the permissions on the .forever/sock folder:
sudo chmod -R o+rwx /home/bitnami/.forever/sock
8) Run my NodeJS app via forever again with the sudo command.
9) List the processes forever is running, and verify that my app was there.
I'm not sure why I had to go through all of this, as setting the permissions recursively should have done the same thing, but after doing this, forever started running perfectly as it did before.
Hope this helps someone.
forever stopall
cd /<app-folder>
forever -w ./bin/www
This just worked for me in a Google Cloud Bitnami VM
If you setup a module globaly (-g option) "forever" is in the $path
forever start app.js
should work.