I have an application in node.js.
This application is divided into 3 parts:
launcher.js, which start the other two parts and restart them when it fails / updates after cleaning processing.
app.js that themselves work on the computer.
server.js, which is used to access the log and other command.
Simplified code to run:
var cluster = require('cluster'), exec = require('child_process').exec, server; if (cluster.isMaster) { cluster.fork(); server = exec('server.js'); cluster.on('exit', function(worker, code, signal) { //Clean corrupted data, log crash if neccessary, reload source code for update ... cluster.fork(); }); server.on('exit', function () { //Same as for app, with a different handling of signal... server = exec('node server.js'); }); } else { var self = require('app.js); self.start(); }
The good thing with the cluster is that they are in the same process as in Launcher, so I can deal with some error without restarting the application (just calling the correct function inside the application for a βsoft restartβ), and keep everything in one process.
While with exec, I was stuck in restarting the server, once not knowing what went wrong, and that means having a subshell, which I don't like.
Is there a way to unlock the cluster, but start a different code?
source share