You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Windshaft-cartodb/app.js

99 lines
2.9 KiB

10 years ago
var path = require('path');
var fs = require('fs');
9 years ago
var ENVIRONMENT;
10 years ago
if ( process.argv[2] ) {
9 years ago
ENVIRONMENT = process.argv[2];
10 years ago
} else if ( process.env.NODE_ENV ) {
9 years ago
ENVIRONMENT = process.env.NODE_ENV;
10 years ago
} else {
9 years ago
ENVIRONMENT = 'development';
10 years ago
}
9 years ago
var availableEnvironments = {
production: true,
staging: true,
development: true
};
// sanity check
9 years ago
if (!availableEnvironments[ENVIRONMENT]){
console.error('node app.js [environment]');
console.error('environments: %s', Object.keys(availableEnvironments).join(', '));
process.exit(1);
}
9 years ago
process.env.NODE_ENV = ENVIRONMENT;
// set environment specific variables
9 years ago
global.environment = require('./config/environments/' + ENVIRONMENT);
global.log4js = require('log4js');
10 years ago
var log4js_config = {
appenders: [],
9 years ago
replaceConsole: true
};
if (global.environment.uv_threadpool_size) {
process.env.UV_THREADPOOL_SIZE = global.environment.uv_threadpool_size;
}
if ( global.environment.log_filename ) {
var logdir = path.dirname(global.environment.log_filename);
// See cwd inlog4js.configure call below
logdir = path.resolve(__dirname, logdir);
if ( ! fs.existsSync(logdir) ) {
console.error("Log filename directory does not exist: " + logdir);
process.exit(1);
}
console.log("Logs will be written to " + global.environment.log_filename);
log4js_config.appenders.push(
{ type: "file", filename: global.environment.log_filename }
);
} else {
log4js_config.appenders.push(
{ type: "console", layout: { type:'basic' } }
);
}
10 years ago
global.log4js.configure(log4js_config, { cwd: __dirname });
global.logger = global.log4js.getLogger();
9 years ago
global.environment.api_hostname = require('os').hostname().split('.')[0];
// Include cartodb_windshaft only _after_ the "global" variable is set
// See https://github.com/Vizzuality/Windshaft-cartodb/issues/28
9 years ago
var cartodbWindshaft = require('./lib/cartodb/server');
var serverOptions = require('./lib/cartodb/server_options');
9 years ago
var server = cartodbWindshaft(serverOptions);
// Maximum number of connections for one process
// 128 is a good number if you have up to 1024 filedescriptors
// 4 is good if you have max 32 filedescriptors
// 1 is good if you have max 16 filedescriptors
9 years ago
server.maxConnections = global.environment.maxConnections || 128;
9 years ago
server.listen(serverOptions.bind.port, serverOptions.bind.host);
var version = require("./package").version;
9 years ago
server.on('listening', function() {
10 years ago
console.log(
"Windshaft tileserver %s started on %s:%s (%s)",
9 years ago
version, serverOptions.bind.host, serverOptions.bind.port, ENVIRONMENT
10 years ago
);
});
process.on('SIGHUP', function() {
global.log4js.clearAndShutdownAppenders(function() {
global.log4js.configure(log4js_config);
10 years ago
global.logger = global.log4js.getLogger();
console.log('Log files reloaded');
});
});
process.on('uncaughtException', function(err) {
10 years ago
global.logger.error('Uncaught exception: ' + err.stack);
});