Windshaft-cartodb/cluster.js

65 lines
1.8 KiB
JavaScript
Raw Normal View History

2011-12-27 23:35:59 +08:00
/*
* Windshaft-CartoDB
* ===============
*
* ./app.js [environment]
*
* environments: [development, production]
*/
2012-09-28 19:05:49 +08:00
var Cluster = require('cluster2');
2011-12-27 23:35:59 +08:00
// sanity check
var ENV = process.argv[2]
if (ENV != 'development' && ENV != 'production' && ENV != 'staging'){
2011-12-27 23:35:59 +08:00
console.error("\nnode app.js [environment]");
console.error("environments: [development, production, staging]\n");
2011-12-27 23:35:59 +08:00
process.exit(1);
}
var _ = require('underscore')
, Step = require('step')
, CartodbWindshaft = require('./lib/cartodb/cartodb_windshaft');
// set environment specific variables
global.settings = require(__dirname + '/config/settings');
global.environment = require(__dirname + '/config/environments/' + ENV);
_.extend(global.settings, global.environment);
// Include cart_data.js only _after_ the "global" variable is set
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/28
var cartoData = require('./lib/cartodb/carto_data');
2011-12-27 23:35:59 +08:00
var Windshaft = require('windshaft');
var serverOptions = require('./lib/cartodb/server_options');
2012-09-28 19:05:49 +08:00
var ws = CartodbWindshaft(serverOptions);
// Maximum number of connections for one process (see apps.js)
ws.maxConnections = global.environment.maxConnections || 128;
2012-09-28 19:05:49 +08:00
//.use(cluster.logger('logs'))
//.use(cluster.stats())
//.use(cluster.pidfiles('pids'))
var cluster = new Cluster({
port: global.environment.port,
host: global.environment.host,
2012-09-28 19:05:49 +08:00
monPort: global.environment.port+1,
monHost: global.environment.host,
timeout: global.environment.socket_timeout,
noWorkers: 1
2012-09-28 19:05:49 +08:00
});
console.log(new Date().toISOString() + " - " + process.pid + " - Windshaft cluster starting");
2012-09-28 19:05:49 +08:00
cluster.listen(function(cb) {
cb(ws);
}, function() {
console.log("Windshaft tileserver started on port " + global.environment.port);
2012-09-28 19:05:49 +08:00
});
2011-12-27 23:35:59 +08:00
process.on('SIGUSR1', function() {
ws.dumpCacheStats();
});