communication between loader and child

v1.18.x
Julian Lam 11 years ago
parent ef63d816fe
commit 64c4dd7e63

@ -0,0 +1,19 @@
var fork = require('child_process').fork,
start = function() {
var nbb = fork('./app', [], {
env: {
'NODE_ENV': 'development'
}
});
nbb.on('message', function(cmd) {
if (cmd === 'nodebb:restart') {
nbb.kill();
setTimeout(function() {
start();
}, 1000);
}
});
};
start();

@ -45,13 +45,30 @@ if(nconf.get('ssl')) {
module.exports.server = server;
// Signals
process.on('SIGINT', function() {
winston.info('[app] Shutdown Initialised.');
db.close();
winston.info('[app] Database connection closed.');
winston.info('[app] Goodbye!');
process.exit();
var shutdown = function(code) {
winston.info('[app] Shutdown (SIGTERM/SIGINT) Initialised.');
db.close();
winston.info('[app] Database connection closed.');
winston.info('[app] Goodbye!');
process.exit();
},
restart = function() {
if (process.send) {
winston.info('[app] Restarting...');
process.send('nodebb:restart');
} else {
winston.error('[app] Could not restart server. Shutting down.');
shutdown();
}
};
process.on('SIGTERM', shutdown);
process.on('SIGINT', shutdown);
process.on('SIGHUP', restart);
process.on('uncaughtException', function(err) {
winston.error('[app] Encountered Uncaught Exception: ' + err.message);
console.log(err.stack);
restart();
});
(function (app) {

Loading…
Cancel
Save