Skip to content

Commit 725d11d

Browse files
committed
[doc] Update README.md
1 parent 5a8b32e commit 725d11d

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

README.md

Lines changed: 60 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@ A simple CLI tool for ensuring that a given script runs continuously (i.e. forev
55
## Installation
66

77
### Installing npm (node package manager)
8-
```
8+
``` bash
99
curl http://npmjs.org/install.sh | sh
1010
```
1111

1212
### Installing forever
13+
``` bash
14+
$ [sudo] npm install forever -g
1315
```
14-
[sudo] npm install forever -g
16+
17+
**Note:** If you are using forever _programatically_ you should not install it globally.
18+
19+
``` bash
20+
$ cd /path/to/your/project
21+
$ [sudo] npm install forever
1522
```
1623

1724
## Usage
@@ -64,14 +71,14 @@ You can use forever to run any kind of script continuously (whether it is writte
6471

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

67-
<pre>
68-
forever samples/error-on-timer.js -m 5
69-
</pre>
74+
``` bash
75+
$ forever samples/error-on-timer.js -m 5
76+
```
7077

7178
### Using an instance of Forever from node.js
7279
You can also use forever from inside your own node.js code.
7380

74-
```javascript
81+
``` js
7582
var forever = require('forever');
7683

7784
var child = new (forever.Monitor)('your-filename.js', {
@@ -88,7 +95,7 @@ You can also use forever from inside your own node.js code.
8895
You can spawn non-node processes too. Either set the `command` key in the
8996
`options` hash or pass in an `Array` in place of the `file` argument like this:
9097

91-
```javascript
98+
``` js
9299
var forever = require('forever');
93100
var child = forever.start([ 'perl', '-le', 'print "moo"' ], {
94101
max : 1,
@@ -97,34 +104,57 @@ You can spawn non-node processes too. Either set the `command` key in the
97104
```
98105

99106
### Options available when using Forever in node.js
100-
There are several options that you should be aware of when using forever:
107+
There are several options that you should be aware of when using forever. Most of this configuration is optional.
101108

102-
```javascript
109+
``` js
103110
{
104-
'max': 10, // Sets the maximum number of times a given script should run
111+
//
112+
// Basic configuration options
113+
//
114+
'silent': false, // Silences the output from stdout and stderr in the parent process
105115
'forever': true, // Indicates that this script should run forever
106-
107-
'silent': true, // Silences the output from stdout and stderr in the parent process
108-
109-
'minUptime': 2000, // Minimum time a child process has to be up. Forever will 'exit' otherwise.
110-
'spinSleepTime': 1000, // Interval between restarts if a child is spinning (i.e. alive < minUptime).
111-
112-
'logFile': 'path/to/file', // Path to log output from forever process (when in daemon)
113-
'pidFile': 'path/to/file', // Path to put pid information for the process(es) started
114-
'outFile': 'path/to/file', // Path to log output from child stdout
115-
'errFile': 'path/to/file', // Path to log output from child stderr
116-
117116
'uid': 'your-UID' // Custom uid for this forever process. (default: autogen)
117+
'pidFile': 'path/to/a.pid', // Path to put pid information for the process(es) started
118118
'fvrFile': 'some-file.fvr' // Custom file to save the child process information (default uid.fvr)
119-
120-
'command': 'perl', // Binary to run (default: 'node')
121-
'options': ['foo','bar'], // Additional arguments to pass to the script,
122-
119+
'max': 10, // Sets the maximum number of times a given script should run
120+
121+
//
122+
// These options control how quickly forever restarts a child process
123+
// as well as when to kill a "spinning" process
124+
//
125+
'minUptime': 2000, // Minimum time a child process has to be up. Forever will 'exit' otherwise.
126+
'spinSleepTime': 1000, // Interval between restarts if a child is spinning (i.e. alive < minUptime).
127+
128+
//
129+
// Command to spawn as well as options and other vars
130+
// (env, cwd, etc) to pass along
131+
//
132+
'command': 'perl', // Binary to run (default: 'node')
133+
'options': ['foo','bar'], // Additional arguments to pass to the script,
134+
'sourceDir': 'script/path' // Directory that the source script is in
135+
136+
//
137+
// All or nothing options passed along to `child_process.spawn`.
138+
//
123139
'spawnWith': {
124-
env: process.env, // Information passed along to the child process
125-
customFds: [-1, -1, -1], // that forever spawns.
140+
env: process.env, // Information passed along to the child process
141+
customFds: [-1, -1, -1], // that forever spawns.
126142
setsid: false
127-
}
143+
},
144+
145+
//
146+
// More specific options to pass along to `child_process.spawn` which
147+
// will override anything passed to the `spawnWith` option
148+
//
149+
'env': { 'ADDITIONAL': 'CHILD ENV VARS' }
150+
'cwd': '/path/to/child/working/directory'
151+
152+
//
153+
// Log files and associated logging options for this instance
154+
//
155+
'logFile': 'path/to/file', // Path to log output from forever process (when daemonized)
156+
'outFile': 'path/to/file', // Path to log output from child stdout
157+
'errFile': 'path/to/file' // Path to log output from child stderr
128158
}
129159
```
130160

@@ -134,7 +164,7 @@ Each forever object is an instance of the node.js core EventEmitter. There are s
134164
* error [err]: Raised when an error occurs
135165
* start [process, fvrFile, data]: Raise when the target script is first started.
136166
* stop [process]: Raised when the target script is stopped by the user
137-
* save [path, data]: Raised when the target Forever object persists the pid information to disk.
167+
* save [path, data]: Raised when the target Monitor saves the pid information to disk.
138168
* restart [forever]: Raised each time the target script is restarted
139169
* exit [forever]: Raised when the target script actually exits (permenantly).
140170
* stdout [data]: Raised when data is received from the child process' stdout
@@ -173,7 +203,7 @@ Removes all log files from the root forever directory that do not belong to curr
173203
## Run Tests
174204

175205
``` bash
176-
$ vows test/*-test.js --spec
206+
$ npm test
177207
```
178208

179209
#### Author: [Charlie Robbins][0]

0 commit comments

Comments
 (0)