Skip to content

Instantly share code, notes, and snippets.

@s3u
Created July 9, 2012 19:07
Show Gist options
  • Save s3u/3078273 to your computer and use it in GitHub Desktop.
Save s3u/3078273 to your computer and use it in GitHub Desktop.
diffs to cluster2
diff --git a/lib/monitor.js b/lib/monitor.js
index a47bd7e..e4a0f1d 100644
--- a/lib/monitor.js
+++ b/lib/monitor.js
@@ -28,8 +28,7 @@ var Monitor = module.exports = function Monitor(options) {
this.options = options || {port: 8081, stats: {}, path: '/'};
this.stats = this.options.stats;
- var app = express.createServer();
-
+ var app = express();
var self = this;
app.set('views', __dirname + '/../public/views');
app.use(express.static(__dirname + '/../public'));
diff --git a/lib/process.js b/lib/process.js
index def310d..0f079a2 100644
--- a/lib/process.js
+++ b/lib/process.js
@@ -20,6 +20,7 @@ var misc = require('./misc.js'),
_ = require('underscore'),
assert = require('assert'),
cluster = require('cluster'),
+ http = require('http'),
EventEmitter = require('events').EventEmitter,
os = require('os'),
fs = require('fs');
@@ -120,7 +121,7 @@ var Process = module.exports = function Process(options) {
});
this.createWorker = function () {
- var worker = cluster.fork();
+ var worker = cluster.fork().process;
var self = this;
fs.writeFileSync(this.options.pids + '/worker.' + worker.pid + '.pid', worker.pid);
@@ -175,7 +176,8 @@ Process.prototype.listen = function(app, cb) {
port: self.options.monPort,
path: self.options.monPath}
);
- monitor.on('listening', function() {
+ var server = http.createServer(monitor);
+ server.on('listening', function() {
misc.ensureDir(process.cwd() + '/pids', true); // Ensure pids dir
misc.ensureDir(process.cwd() + '/logs'); // Ensure logs dir
@@ -220,13 +222,13 @@ Process.prototype.listen = function(app, cb) {
cb.call(null);
});
- monitor.on('error', function (e) {
+ server.on('error', function (e) {
if(e.code === 'EADDRINUSE') {
console.log('Address in use ...');
process.exit(-1);
}
});
- monitor.listen(this.options.monPort);
+ server.listen(this.options.monPort);
}
else {
var listening = false, conns = 0, totalConns = 0, timedoutConns = 0;
@@ -337,4 +339,3 @@ Process.prototype.shutdown = function() {
log('Shutdown request received - emitting SIGTERM');
this.emitter.emit('SIGTERM');
};
-
diff --git a/package.json b/package.json
index 1050a6e..57e072f 100644
--- a/package.json
+++ b/package.json
@@ -11,17 +11,17 @@
"url": "https://github.com/ql-io/cluster2"
},
"engines": {
- "node": ">= 0.6.0"
+ "node": ">= 0.8.0"
},
"main": "lib/index.js",
"dependencies": {
"underscore": "",
- "express": "2.5.9",
+ "express": "",
"ejs": "",
"npm": ""
},
"devDependencies": {
- "express": "2.5.9",
+ "express": "",
"nodeunit": "",
"request": ""
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment