From 0d6be40238a510cfee555afa0eddc212582ca159 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 17 Nov 2014 14:47:36 -0500 Subject: [PATCH] fixed #2406 --- loader.js | 11 +++++++++++ nodebb | 7 ++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/loader.js b/loader.js index 5781fefa54..0a9d6e0a05 100644 --- a/loader.js +++ b/loader.js @@ -42,6 +42,7 @@ Loader.init = function(callback) { process.on('SIGHUP', Loader.restart); process.on('SIGUSR2', Loader.reload); + process.on('SIGTERM', Loader.stop); callback(); }; @@ -217,6 +218,16 @@ Loader.reload = function() { }); }; +Loader.stop = function() { + Object.keys(cluster.workers).forEach(function(id) { + // Gracefully close workers + cluster.workers[id].kill(); + }); + + // Clean up the pidfile + fs.unlinkSync(__dirname + '/pidfile'); +}; + Loader.notifyWorkers = function (msg) { Object.keys(cluster.workers).forEach(function(id) { cluster.workers[id].send(msg); diff --git a/nodebb b/nodebb index 0df5899454..5a036e4e94 100755 --- a/nodebb +++ b/nodebb @@ -12,10 +12,11 @@ fi function pidExists() { if [ -e "pidfile" ]; then - kill -s 0 $(cat pidfile); - if [ !$? ]; + if ps -p $(cat pidfile) > /dev/null then return 1; - else return 0; + else + rm ./pidfile; + return 0; fi else return 0;