Created
April 12, 2012 12:18
-
-
Save AndreasMadsen/2366873 to your computer and use it in GitHub Desktop.
immortal example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var immortal = require('immortal'); | |
var spawn = function(id, callback) { | |
var socket = net.connect('/tmp/monitor.sock'); | |
console.log(id, 'start'); | |
socket.on('error', function(error) { | |
if (error.code !== 'ENOENT') throw error; | |
immortal.start(__dirname+'/worker.js', { | |
strategy: 'unattached', | |
auto:false, | |
monitor: null | |
}, function(error) { | |
if (error) throw error; | |
console.log('immortal process spawned'); | |
// error === null | |
// Der er derfor ingen grund til at lave et respawn | |
// Desuden er der kun når forkerte options er givet i immortal.start(name, options) at | |
// error ikke vil være null. | |
//setTimeout(spawn.bind(null, id, callback), 100); | |
}); | |
}); | |
socket.on('connect', function() { | |
console.log(id, 'connect'); | |
callback(null, socket); | |
}); | |
}; | |
for (var i = 0 ; i < 5; i++) { | |
spawn(i, function() { | |
console.log('spawned...'); | |
}); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var server = net.createServer(function(socket) { | |
// do some stuff | |
}); | |
server.on('error', function() { | |
process.exit(0); // only listen in one of the daemons | |
}); | |
server.listen('/tmp/monitor.sock'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment