Skip to content

Commit

Permalink
[doc] Added example about running / listing multiple processes progra…
Browse files Browse the repository at this point in the history
…mmatically
  • Loading branch information
indexzero committed Aug 12, 2011
1 parent c3fe93a commit 9dc7bad
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/list-multiple.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var path = require('path'),
async = require('async'),
forever = require('../lib/forever');

function startServer (port, next) {
var child = new (forever.Monitor) (script, {
options: [ '--port', port],
silent: true
});

child.start();
child.on('start', function (_, data) {
console.log('Forever process running server.js on ' + port);
next(null, child);
});
}

// Array config data
var script = path.join(__dirname, 'server.js'),
ports = [8080, 8081, 8082];

async.map(ports, startServer, function (err, monitors) {
forever.startServer(monitors, function () {
//
// Now that the server has started, run `forever.list()`
//
forever.list(false, function (err, data) {
if (err) {
console.log('Error running `forever.list()`');
console.dir(err);
}

console.log('Data returned from `forever.list()`');
console.dir(data)
})
});
});

0 comments on commit 9dc7bad

Please sign in to comment.