Node.js based forum software built for the modern web
moved process events out of webserver.js and into app.js
psychobunny4d598dcd632f
diff --git a/app.js b/app.jsindex 665944644b..a9b452ba35 100644--- a/app.js+++ b/app.js@@ -95,7 +95,6 @@ function loadConfig() {nconf.set('themes_path', path.resolve(__dirname, nconf.get('themes_path')));}-function start() {loadConfig();@@ -117,7 +116,6 @@ function start() {require('./src/database').init(function(err) {meta.configs.init(function () {-var templates = require('./public/src/templates'),translator = require('./public/src/translator'),webserver = require('./src/webserver'),@@ -130,11 +128,8 @@ function start() {upgrade.check(function(schema_ok) {if (schema_ok || nconf.get('check-schema') === false) {-sockets.init(webserver.server);-plugins.init();-translator.loadServer();var customTemplates = meta.config['theme:templates'] ? path.join(nconf.get('themes_path'), meta.config['theme:id'], meta.config['theme:templates']) : false;@@ -148,6 +143,15 @@ function start() {});notifications.init();++ 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();+ });} else {winston.warn('Your NodeBB schema is out-of-date. Please run the following command to bring your dataset up to spec:');winston.warn(' node app --upgrade');@@ -236,6 +240,25 @@ function reset() {});}+function shutdown(code) {+ winston.info('[app] Shutdown (SIGTERM/SIGINT) Initialised.');+ db.close();+ winston.info('[app] Database connection closed.');++ winston.info('[app] Shutdown complete.');+ process.exit();+}++function restart() {+ if (process.send) {+ winston.info('[app] Restarting...');+ process.send('nodebb:restart');+ } else {+ winston.error('[app] Could not restart server. Shutting down.');+ shutdown();+ }+}+function displayHelp() {winston.info('Usage: node app [options] [arguments]');winston.info(' [NODE_ENV=development | NODE_ENV=production] node app [--start] [arguments]');diff --git a/src/webserver.js b/src/webserver.jsindex d76814a07a..47c1c9c0ca 100644--- a/src/webserver.js+++ b/src/webserver.js@@ -37,33 +37,6 @@ if(nconf.get('ssl')) {server = require('http').createServer(WebServer);}-// Signals-var shutdown = function(code) {- winston.info('[app] Shutdown (SIGTERM/SIGINT) Initialised.');- db.close();- winston.info('[app] Database connection closed.');-- winston.info('[app] Shutdown complete.');- 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) {"use strict";@@ -85,7 +58,7 @@ process.on('uncaughtException', function(err) {logger.init(app);auth.registerApp(app);-+async.series({themesData: meta.themes.get,currentThemeData: function(next) {