I've been posting a lot about node.js lately. As I was organizing and sharing some of the things I used on the
Side Effect Studio
site that I built a while ago, it seems like the posts have been focused exclusively on node.js. I need to finish organizing everything quickly and look into other things as well. Haha.
Last year, I posted an article titled
Serving node.js Applications with Upstart and Monit
, which is quite useful, but it can be rather annoying from a management perspective. Tasks like creating Upstart scripts and applying rules in Monit are a bit tedious. Since I wasn't aware of any other alternatives, I had been using Upstart and Monit, but after that post, a tool called
forever
, which manages instances of node apps, was released.
forever
can be easily installed using npm with the command
npm install forever
, and it is a tool that manages node.js apps by running them with very simple commands, restarting them if they unexpectedly terminate, and saving stdout to log files.
Having used it, while it does have some minor bugs, it is so much more convenient than the existing Upstart and Monit combination that I have switched entirely to
forever
for managing all my node.js apps.
usage: forever [start | stop | stopall | list | cleanlogs] [options] SCRIPT [script options]
options:
start start SCRIPT as a daemon
stop stop the daemon SCRIPT
stopall stop all running forever scripts
list list all running forever scripts
cleanlogs [CAREFUL] Deletes all historical forever log files
The usage of
forever
is as shown above.
To register a script you want to run, simply execute it like
forever start app.js
.
If you check the processes, you will see a separate process for
forever
, which will automatically restart the
app.js
process if it dies. To see the scripts currently running, you can execute
forever list
.
To terminate a process, you can use
forever stop [index]
using the index shown in the list.
It is very convenient to use because you can grasp which processes are currently running at a glance, and it automatically connects log files.
Based on my brief experience, it seems fairly stable. (Since I don't have that much traffic, the probability of a fatal error is low, so this isn't definitive, just a feeling.. ㅡㅡ;;) However, there seems to be a minor bug where an app registered with
forever start
successfully spawns the process, but it isn't registered in
forever
and doesn't appear in the list. I tested this several times but couldn't find a pattern. In such cases, you must forcibly terminate the corresponding script and the
forever
process and register it again. Other than this, it's really great because both management and usage are very convenient.
Source : http://blog.outsider.ne.kr/590