diff --git a/app.js b/app.js index 6a1bb9d49d..51b752ccc9 100644 --- a/app.js +++ b/app.js @@ -142,11 +142,6 @@ function start() { 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'); @@ -292,7 +287,9 @@ function shutdown(code) { function restart() { if (process.send) { winston.info('[app] Restarting...'); - process.send('nodebb:restart'); + process.send({ + action: 'restart' + }); } else { winston.error('[app] Could not restart server. Shutting down.'); shutdown(); diff --git a/loader.js b/loader.js index 2ab9be2715..e0bfac6258 100644 --- a/loader.js +++ b/loader.js @@ -12,9 +12,19 @@ var nconf = require('nconf'), } }); - nbb.on('message', function(cmd) { - if (cmd === 'nodebb:restart') { - nbb_restart(); + nbb.on('message', function(message) { + if (message && typeof message === 'object' && message.action) { + if (message.action === 'restart') { + nbb_restart(); + } + } + }); + + nbb.on('exit', function(code, signal) { + if (code) { + nbb_start(); + } else { + nbb_stop(); } }); }, diff --git a/nodebb b/nodebb index 18f6df8966..bf7b82e42e 100755 --- a/nodebb +++ b/nodebb @@ -22,7 +22,13 @@ case "$1" in echo "Starting NodeBB"; echo " \"./nodebb stop\" to stop the NodeBB server"; echo " \"./nodebb log\" to view server output"; - echo "" > ./logs/output.log; + + if [ -f "./logs/output.log" ]; # Preserve the last output log + then + mv ./logs/output.log ./logs/output.1.log; + fi; + + # Start the loader daemon node loader -d "$@" ;; @@ -42,13 +48,11 @@ case "$1" in then echo "NodeBB is not running"; echo " \"./nodebb start\" to launch the NodeBB server"; - return 1; else echo "NodeBB Running (pid $(cat pidfile))"; echo " \"./nodebb stop\" to stop the NodeBB server"; echo " \"./nodebb log\" to view server output"; echo " \"./nodebb restart\" to restart NodeBB"; - return 0; fi ;; diff --git a/src/meta.js b/src/meta.js index eef8acee95..4f2a25f7e9 100644 --- a/src/meta.js +++ b/src/meta.js @@ -448,7 +448,9 @@ var fs = require('fs'), /* Assorted */ Meta.restart = function() { if (process.send) { - process.send('nodebb:restart'); + process.send({ + action: 'restart' + }); } else { winston.error('[meta.restart] Could not restart, are you sure NodeBB was started with `./nodebb start`?'); }