diff --git a/bin/up b/bin/up index 9bf8925..8785885 100755 --- a/bin/up +++ b/bin/up @@ -44,6 +44,7 @@ program , 'development' == process.env.NODE_ENV ? 1 : cpus) .option('-t, --timeout [ms]', 'Worker timeout.') .option('-k, --keepalive', 'Restart failed workers.') + .option('-m, --manual-ready', 'Manual call require("up").ready() in code.') /** * Capture requires. @@ -149,7 +150,8 @@ var keepAlive = program.keepalive; */ debug('starting cluster with %d workers on port %d', numWorkers, port); -debug('`\033[97mkill -s SIGUSR2 %d\033[90m` or \033[97mctrl + r\033[90m' +debug('`\033[97mkill -s SIGUSR2 %d\033[90m` or' + + '`\033[97mkill -s SIGHUP %d\033[90m` or \033[97mctrl + r\033[90m' + ' to load new code', process.pid); var httpServer = http.Server().listen(program.port) @@ -159,6 +161,7 @@ var httpServer = http.Server().listen(program.port) , requires: requires , title: program.title , keepAlive: keepAlive + , assumeReady: !program.manualReady }) /** @@ -172,6 +175,15 @@ if (program.pidfile) { }); } +/** + * Listen on SIGHUP signal. + */ + +process.on('SIGHUP', function () { + debug('\033[97mSIGHUP\033[90m signal detected - reloading'); + srv.reload(); +}); + /** * Listen on SIGUSR2 signal. */ diff --git a/lib/up.js b/lib/up.js index ae5ac2b..85e5f0f 100644 --- a/lib/up.js +++ b/lib/up.js @@ -115,14 +115,10 @@ UpServer.prototype.__proto__ = Distributor.prototype; */ UpServer.prototype.reload = function (fn) { - if (this.reloading) { - debug('reloading in process - ignoring reload'); - return this; - } // remove all workers in the spawning state - for (var i = 0, l = this.spawning.length; i < l; i++) { - this.spawning[i].shutdown(); + while (this.spawning.length > 0) { + this.spawning[0].shutdown(); } if (this.workerTimeout > 0) { diff --git a/lib/worker.js b/lib/worker.js index 5fcc5da..1b350c6 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -62,7 +62,7 @@ process.on('message', function (msg) { switch (msg.type) { case 'die': setTimeout(function () { - process.exit(0); + process.kill(process.pid); }, msg.time); break; case 'ready': diff --git a/package.json b/package.json index 27405b6..7b1e6f4 100644 --- a/package.json +++ b/package.json @@ -1,26 +1,37 @@ { - "name": "up" - , "description": "Zero downtime reloads for Node HTTP(S) servers." - , "tags": ["cluster", "reload", "process", "monitor", "graceful", "restart"] - , "homepage": "https://github.com/learnboost/up" - , "version": "0.2.1" - , "bin": { "up": "./bin/up" } - , "main": "./lib/up" - , "engines": { "node": ">= 0.6.0" } - , "dependencies": { - "eq": "0.1.0" - , "ms": "0.1.0" - , "debug": "0.1.0" - , "commander": "0.6.1" - , "distribute": "0.1.4" - } - , "devDependencies": { - "mocha": "*" - , "expect.js": "*" - , "express": "*" - , "superagent": "*" - } - , "scripts": { - "test": "./node_modules/mocha/bin/mocha test/*.test.js" - } + "name": "up", + "description": "Zero downtime reloads for Node HTTP(S) servers.", + "tags": [ + "cluster", + "reload", + "process", + "monitor", + "graceful", + "restart" + ], + "homepage": "https://github.com/learnboost/up", + "version": "0.2.5", + "bin": { + "up": "./bin/up" + }, + "main": "./lib/up", + "engines": { + "node": ">= 0.6.0" + }, + "dependencies": { + "eq": "0.1.0", + "ms": "0.1.0", + "debug": "0.1.0", + "commander": "0.6.1", + "distribute": "0.1.4" + }, + "devDependencies": { + "mocha": "*", + "expect.js": "*", + "express": "*", + "superagent": "*" + }, + "scripts": { + "test": "./node_modules/mocha/bin/mocha test/*.test.js" + } }