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]
|
2012-09-04 19:35:06 +08:00
|
|
|
if (ENV != 'development' && ENV != 'production' && ENV != 'staging'){
|
2011-12-27 23:35:59 +08:00
|
|
|
console.error("\nnode app.js [environment]");
|
2012-09-04 19:35:06 +08:00
|
|
|
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);
|
|
|
|
|
2012-07-11 02:38:54 +08:00
|
|
|
// 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);
|
|
|
|
|
2013-01-30 00:36:50 +08:00
|
|
|
// 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,
|
2012-10-09 23:09:40 +08:00
|
|
|
host: global.environment.host,
|
2012-09-28 19:05:49 +08:00
|
|
|
monPort: global.environment.port+1,
|
2012-10-09 23:09:40 +08:00
|
|
|
monHost: global.environment.host,
|
2012-12-05 20:59:20 +08:00
|
|
|
timeout: global.environment.socket_timeout,
|
2012-10-09 23:09:40 +08:00
|
|
|
noWorkers: 1
|
2012-09-28 19:05:49 +08:00
|
|
|
});
|
|
|
|
|
2013-02-01 18:28:08 +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);
|
2012-10-09 23:09:40 +08:00
|
|
|
}, 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
|
|
|
|
2013-01-30 18:29:44 +08:00
|
|
|
process.on('SIGUSR1', function() {
|
|
|
|
ws.dumpCacheStats();
|
|
|
|
});
|