Node.js based forum software built for the modern web
communication between loader and child
Julian Lam64c4dd7e6305
diff --git a/loader.js b/loader.jsnew file mode 100644index 0000000000..eb46269d5a--- /dev/null+++ b/loader.js@@ -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();\ No newline at end of filediff --git a/src/webserver.js b/src/webserver.jsindex 0d65b7c99e..ff0f7bd67e 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -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) {