forever 
A simple CLI tool for ensuring that a given script runs continuously (i.e. forever).
Installation
Note: If you are using forever programatically you should install forever-monitor.
Usage
There are two distinct ways to use forever: through the command line interface, or by requiring the forever module in your own code. Note: If you are using forever programatically you should install forever-monitor.
Using forever from the command line
You can use forever to run any kind of script continuously (whether it is written in node.js or not). The usage options are simple:
There are several examples designed to test the fault tolerance of forever. Here's a simple usage example:
Using forever module from node.js
In addition to using a Forever object, the forever module also exposes some useful methods. Each method returns an instance of an EventEmitter which emits when complete. See the forever cli commands for sample usage.
Remark: As of [email protected]
processes will not automatically be available in forever.list()
. In order to get your processes into forever.list()
or forever list
you must instantiate the forever
socket server:
forever.load (config)
Synchronously sets the specified configuration (config) for the forever module. There are two important options:
root: Directory to put all default forever log files
pidPath: Directory to put all forever *.pid files
forever.start (file, options)
Starts a script with forever.
forever.startDaemon (file, options)
Starts a script with forever as a daemon. WARNING: Will daemonize the current process.
forever.stop (index)
Stops the forever daemon script at the specified index. These indices are the same as those returned by forever.list(). This method returns an EventEmitter that raises the 'stop' event when complete.
forever.stopAll (format)
Stops all forever scripts currently running. This method returns an EventEmitter that raises the 'stopAll' event when complete.
forever.list (format, callback)
Returns a list of metadata objects about each process that is being run using forever. This method is synchronous and will return the list of metadata as such. Only processes which have invoked forever.startServer()
will be available from forever.list()
forever.tail (target, [length,] callback)
Responds with the logs from the target script(s) from tail
. If length
is provided it is used as the -n
parameter to tail
.
forever.cleanUp ()
Cleans up any extraneous forever *.pid files that are on the target system. This method returns an EventEmitter that raises the 'cleanUp' event when complete.
forever.cleanLogsSync (processes)
Removes all log files from the root forever directory that do not belong to current running forever processes.