Skip to content

Commit

Permalink
[api dist doc] Updated docs, package.json and small options handling
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Sep 28, 2010
1 parent f8912b9 commit 9f08ad1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
66 changes: 66 additions & 0 deletions README.md
@@ -0,0 +1,66 @@
# forever

A simple CLI tool for ensuring that a given script runs continuously (i.e. forever).

## Installation

### Installing npm (node package manager)
<pre>
curl http://npmjs.org/install.sh | sh
</pre>

### Installing http-agent
<pre>
[sudo] npm install forever
</pre>

## Usage
There are two distinct ways to use forever: through the command line interface, or by requiring the forever module in your own code.

### 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:

<pre>
usage: forever [FILE, ...] [options]

options:
-m MAX Only run the specified script MAX times
-s, --silent Run the child script silencing stdout and stderr
-h, --help You're staring at it
</pre>

There are several samples designed to test the fault tolerance of forever. Here's a simple example:

<pre>
forever samples/error-on-timer.js -m 5
</pre>

### Using forever from node.js
You can also use forever from inside your own node.js code.

<pre>
var forever = require('forever');

var child = new (forever.Forever)('your-filename.js'), {
max: 3,
silent: true,
options: []
});

child.on('exit', this.callback);
child.run();
</pre>

Each forever object is an instance of the node.js core EventEmitter. There are several core events that you can listen for:

* restart [err, forever]: Raised each time the target script is restarted
* exit [err, forever]: Raised when the call to forever.run() completes
* stdout [err, data]: Raised when data is received from the child process' stdout
* stderr [err, data]: Raised when data is received from the child process' stderr

## Run Tests
<pre>
vows test/*-test.js --spec
</pre>

#### Author: [Charlie Robbins](http://www.charlierobbins.com);
2 changes: 2 additions & 0 deletions lib/forever.js
Expand Up @@ -16,6 +16,8 @@ var Forever = function (file, options) {

this.times = 0;
options.options.unshift(path.join(__dirname, file));
options.silent = options.silent || false;
options.forever = options.forever || false;
this.options = options;
};

Expand Down
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -9,7 +9,8 @@
},
"keywords": ["cli", "fault tolerant", "sysadmin", "tools"],
"dependencies": {
"optimist": ">= 0.0.3"
"optimist": ">= 0.0.3",
"vows": ">= 0.5.1"
},
"bin": { "forever": "./bin/forever" },
"main": "./lib/forever",
Expand Down

0 comments on commit 9f08ad1

Please sign in to comment.