问题
I am trying to run my nodejs app on an Amazon EC2 instance using forever. I installed nodejs npm, and then ran sudo npm install forever -g
.
The installation didn't return any errors, so i go ahead and try running my app using forever start server.js
, but it won't do anything - no output what-so-ever, not even an error.
I also tried forever --help
and just forever
, but none of them giving me any response...
When running my app regularly using nodejs - nodejs init.js
then it works as expected, but i need to get it running using forever
so it won't shut down when i disconnect from the server.
Edit :
Since the only problem i was having was that nodejs was closing when i closed the terminal session to my EC2 server, I solved this by using the linux nohup
command like this :nohup sudo nodejs server.js &
This kept nodejs running in a child process even after I closed the terminal window.
Thanks for the help though! :)
回答1:
I was also not receiving any stdout
input from any forever
command and this fix nailed it:
sudo ln -s /usr/bin/nodejs /usr/local/bin/node
Hope that helps someone.
回答2:
I don't know if this will help, but as an alternative, you can use upstart
. Create a script like this:
#this is the upstart service task. move it to /etc/init/nodeapp.conf
description "server for Node App"
author "Neels Grobler"
chdir /root/servers/nodeapp
exec node init.js 1>stdout.log 2>stderr.log
respawn
And run it by typing start nodeapp
. To stop type stop nodeapp
. You can also change the script so that the node app starts on system boot etc. More info at upstart.ubuntu.com
回答3:
You should be using forever start server.js
not just forever server.js
回答4:
On windows, when you run forever like:
forever start app.js
you can find generated log file in file system at:
C:\Users\USERNAME\.forever\SomeLogFileHere.txt
The log files are regenerated for every running script with unique identicator of each file. You can always check which file belongs to which process by:
forever list
回答5:
Several guesses.
- If you install using
sudo npm install forever -g
, you might need tosudo
to run forever. - Put a full path of server.js when you run forever such as
forever start /home/you/source/server.js
orsudo forever start /home/you/source/server.js
来源:https://stackoverflow.com/questions/14861197/nodejs-forever-just-doesnt-do-anything