Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created August 12, 2011 03:22
Show Gist options
  • Save indexzero/1141361 to your computer and use it in GitHub Desktop.
Save indexzero/1141361 to your computer and use it in GitHub Desktop.
var async = require('async'),
forever = require('forever');
function startApp (options, next){
var child = new (forever.Monitor) (script, {
'options': [
'--port', options.port,
'--secret', options.secret,
'--userSchema', options.userSchema
]
});
child.start();
child.on('start', function (_, data) {
console.log('Forever process running server.js on ' + options.port);
next(null, child);
});
}
// Array config data
var apps = [
{ userSchema: 'test1', port: 8000, secret: 'krFB6so8GZdJCqfcu9oh' },
{ userSchema: 'test2', port: 8001, secret: 'xIXQw2RfmFqNTwlhmQmw' }
]
async.map(apps, startApp, function (err, monitors) {
forever.startServer(monitors, function () {
//
// Ignore data returned from `.startServer()`
//
});
});
// Calling during app.get
app.get('/servers', requiresLogin, function (req, res) {
forever.list(false, function (err, data) {
if (err) {
throw err;
}
console.log(data)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment