Skip to content

Node.js based forum software built for the modern web

fixed #2406

Julian Lam0d6be40238a5
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;