From 08abbe19bca647e0ec2d670ea95c9a8a58f257f7 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 4 Sep 2014 17:09:57 -0400 Subject: [PATCH] zero downtime and reload support with cluster module --- app.js | 7 ++++++ loader.js | 47 ++++++++++++++++++++++++++++++----------- src/meta.js | 2 +- src/meta/templates.js | 11 ++++++++++ src/middleware/index.js | 9 +------- src/socket.io/admin.js | 9 +++++++- src/webserver.js | 4 ++-- 7 files changed, 65 insertions(+), 24 deletions(-) diff --git a/app.js b/app.js index c09f2d67c3..f6c0313abe 100644 --- a/app.js +++ b/app.js @@ -157,6 +157,13 @@ function start() { process.on('SIGTERM', shutdown); process.on('SIGINT', shutdown); process.on('SIGHUP', restart); + process.on('message', function(message) { + switch(message) { + case 'reload': + meta.reload(); + break; + } + }) process.on('uncaughtException', function(err) { winston.error(err.message); console.log(err.stack); diff --git a/loader.js b/loader.js index 83b37cbc2e..65d8381c3e 100644 --- a/loader.js +++ b/loader.js @@ -95,7 +95,8 @@ var nconf = require('nconf'), // nbb, nbbOld; var Loader = { - timesStarted: 0 + timesStarted: 0, + shutdown_queue: [] }; Loader.init = function() { @@ -106,11 +107,6 @@ Loader.init = function() { silent: process.env.NODE_ENV !== 'development' ? true : false }); - for(var x=0;x