From 9dc7bad3c40325b6483dd8c2df57f9068de52721 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 11 Aug 2011 23:37:43 -0400 Subject: [PATCH] [doc] Added example about running / listing multiple processes programmatically --- examples/list-multiple.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 examples/list-multiple.js diff --git a/examples/list-multiple.js b/examples/list-multiple.js new file mode 100644 index 00000000..e24a6bc4 --- /dev/null +++ b/examples/list-multiple.js @@ -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) + }) + }); +}); \ No newline at end of file