Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changed `reload()` to reload workers only

  • Loading branch information...
commit cb6eba8680b0f2f74e8c7aa634a1d367bddcb3a4 1 parent 56fe053
@tj tj authored
Showing with 21 additions and 13 deletions.
  1. +15 −0 lib/master.js
  2. +6 −13 lib/plugins/reload.js
View
15 lib/master.js
@@ -23,6 +23,7 @@ var Worker = require('./worker')
, close = netBinding.close
, unlink = fsBinding.unlink
, dgram = require('dgram')
+ , tty = require('tty')
, net = require('net')
, fs = require('fs')
, os = require('os');
@@ -448,6 +449,7 @@ Master.prototype.createSocket = function(fn){
*/
Master.prototype.registerSignalHandlers = function(){
+ var self = this;
process.on('SIGINT', this.destroy.bind(this));
process.on('SIGTERM', this.destroy.bind(this));
process.on('SIGQUIT', this.close.bind(this));
@@ -470,6 +472,19 @@ Master.prototype.defaultWorkers = function(){
};
/**
+ * Restart workers only, sending `signal` defaulting
+ * to __SIGQUIT__.
+ *
+ * @param {Type} name
+ * @return {Type}
+ * @api public
+ */
+
+Master.prototype.restartWorkers = function(signal){
+ this.kill(signal || 'SIGQUIT');
+};
+
+/**
* Maintain worker count, re-spawning if necessary.
*
* @api private
View
19 lib/plugins/reload.js
@@ -19,7 +19,7 @@ var fs = require('fs')
*
* Options:
*
- * - `signal` Signal to send, defaults to __SIGTERM__
+ * - `signal` Signal defaulting to __SIGTERM__
* - `interval` Watcher interval, defaulting to `100`
* - `extensions` File extensions to watch, defaults to ['.js']
*
@@ -38,7 +38,7 @@ var fs = require('fs')
* .listen(3000);
*
* cluster(server)
- * .use(cluster.reload('lib', { signal: 'SIGQUIT', interval: 60000 }))
+ * .use(cluster.reload('lib', { interval: 60000 }))
* .listen(3000);
*
* cluster(server)
@@ -69,13 +69,11 @@ exports = module.exports = function(files, options){
options = options || {};
// defaults
- var sig = options.signal || 'SIGTERM'
- , interval = options.interval || 100
- , extensions = options.extensions || ['.js'];
+ var interval = options.interval || 100
+ , extensions = options.extensions || ['.js']
+ , signal = options.signal || 'SIGTERM';
return function(master){
- var restarting;
-
if (!files) files = master.dir;
if (!Array.isArray(files)) files = [files];
files.forEach(traverse);
@@ -104,17 +102,12 @@ exports = module.exports = function(files, options){
function watch(file) {
if (!~extensions.indexOf(extname(file))) return;
fs.watchFile(file, { interval: interval }, function(curr, prev){
- if (restarting) return;
if (curr.mtime > prev.mtime) {
console.log(' \033[36mchanged\033[0m \033[90m- %s\033[0m', file);
- master.restart(sig);
+ master.restartWorkers(signal);
}
});
}
-
- master.on('restarting', function(){
- restarting = true;
- });
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.