Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

automatically restarting service via forever for nodejs [duplicate]

I found that forever can run nodejs server forever. Is forever supports this feautre?

-- If the nodejs script is modified changed, the server shld restarted automatically.

How can I enable this feature using forever? or I need something else?

like image 479
coure2011 Avatar asked Jan 21 '12 06:01

coure2011


3 Answers

In case someone else, like myself, comes to find this through google.

I have to run it thusly:

forever --watch ./start/file

For me, at least, it defaults to watching the current directory I'm running the command in for changes. ./start/file is the file that "npm start" hits up from your package.json.

If you need to watch a different directory from where you're pwd shows you to be, try:

forever --watch --watchDirectory ./path/to/dir ./start/file

For some reason "forever start xxxxxxxxx" only brings up the help information for me, but this works. /me shrugs.

like image 72
CrimsonKissaki Avatar answered Nov 12 '22 17:11

CrimsonKissaki


From the forever readme. Use the -w flag to watch file for changes.

like image 23
fent Avatar answered Nov 12 '22 18:11

fent


Again just another example of its usage (and it does work :D)

forever -w --watchDirectory . --watchIgnore *.log -o ./log/out.log -e ./log/err.log index.js

That will launch the app in the same process with output to stdout/stderr (but also written to the logs)

To launch it in prod watching is obviously not a good idea and running it as a deamon is probably what you are after so drop the -w flags and add the "start" command

forever -o ./log/out.log -e ./log/err.log start index.js
like image 39
mikgan Avatar answered Nov 12 '22 18:11

mikgan