Skip to content

Instantly share code, notes, and snippets.

@youurayy
Created September 20, 2011 10:04
Show Gist options
  • Save youurayy/1228778 to your computer and use it in GitHub Desktop.
Save youurayy/1228778 to your computer and use it in GitHub Desktop.
var child_process = require('child_process');
var forever = '/opt/local/bin/forever';
var node = '/opt/local/bin/node';
var bash = '/bin/bash';
var mongod = '/opt/local/bin/mongod';
var cwd = process.cwd();
var procs = [
[ 'test1', node, cwd + '/test1.js' ],
[ 'test2', node, cwd + '/test2.js' ],
// [ 'mongod', mongod, '--dbpath', '/opt/local/var/db/mongodb', '--logpath', '/opt/local/var/log/mongodb.log', '--rest' ],
[ 'test3', bash, cwd + '/test3.sh' ]
];
for(var i in procs) {
var o = procs[i];
var is_script = o[1] === node || o[1] === bash;
var m = /(.+)\/(.+)$/.exec(o[is_script ? 2 : 1]);
var dir = m[1];
var prog = m[2];
var id = o[0];
var a = [
'start',
'-a',
'-l', id + '.log',
'-o', id + '.out',
'-e', id + '.err',
'--minUptime', '5000',
'-c', o[1]
];
if(o[1] === node) {
a.push('--sourceDir');
a.push(dir);
a.push(prog);
}
else if(is_script) {
a.push(o[2]);
}
for(var i = 3; i < o.length; i++)
a.push(o[i]);
console.log(a.join(' '));
child_process.spawn(forever, a);
}
var cnt = 0;
var iii = setInterval(function() { console.log('test1'); if(cnt++ > 5) clearInterval(iii); }, 1000);
var cnt = 0;
var iii = setInterval(function() { console.log('test2'); if(cnt++ > 5) clearInterval(iii); }, 1000);
#!/bin/sh
echo test3
sleep 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment