@@ -5,13 +5,20 @@ A simple CLI tool for ensuring that a given script runs continuously (i.e. forev
5
5
## Installation
6
6
7
7
### Installing npm (node package manager)
8
- ```
8
+ ``` bash
9
9
curl http://npmjs.org/install.sh | sh
10
10
```
11
11
12
12
### Installing forever
13
+ ``` bash
14
+ $ [sudo] npm install forever -g
13
15
```
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
15
22
```
16
23
17
24
## Usage
@@ -64,14 +71,14 @@ You can use forever to run any kind of script continuously (whether it is writte
64
71
65
72
There are several samples designed to test the fault tolerance of forever. Here's a simple example:
66
73
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
+ ```
70
77
71
78
### Using an instance of Forever from node.js
72
79
You can also use forever from inside your own node.js code.
73
80
74
- ``` javascript
81
+ ``` js
75
82
var forever = require (' forever' );
76
83
77
84
var child = new (forever .Monitor )(' your-filename.js' , {
@@ -88,7 +95,7 @@ You can also use forever from inside your own node.js code.
88
95
You can spawn non-node processes too. Either set the ` command ` key in the
89
96
` options ` hash or pass in an ` Array ` in place of the ` file ` argument like this:
90
97
91
- ``` javascript
98
+ ``` js
92
99
var forever = require (' forever' );
93
100
var child = forever .start ([ ' perl' , ' -le' , ' print "moo"' ], {
94
101
max : 1 ,
@@ -97,34 +104,57 @@ You can spawn non-node processes too. Either set the `command` key in the
97
104
```
98
105
99
106
### 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.
101
108
102
- ``` javascript
109
+ ``` js
103
110
{
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
105
115
' 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
-
117
116
' 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
118
118
' 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
+ //
123
139
' 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.
126
142
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
128
158
}
129
159
```
130
160
@@ -134,7 +164,7 @@ Each forever object is an instance of the node.js core EventEmitter. There are s
134
164
* error [ err] : Raised when an error occurs
135
165
* start [ process, fvrFile, data] : Raise when the target script is first started.
136
166
* 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.
138
168
* restart [ forever] : Raised each time the target script is restarted
139
169
* exit [ forever] : Raised when the target script actually exits (permenantly).
140
170
* 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
173
203
## Run Tests
174
204
175
205
``` bash
176
- $ vows test/ * -test.js --spec
206
+ $ npm test
177
207
```
178
208
179
209
#### Author: [ Charlie Robbins] [ 0 ]
0 commit comments