CartoDB-SQL-API/cluster.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2011-06-20 21:39:12 +08:00
#!/usr/bin/env node
/*
* SQL API loader
* ===============
*
2012-06-02 01:19:13 +08:00
* Builds a cluster of node processes managed by cluster library.
* Only compatible with node 0.4.x
*
2011-06-20 21:39:12 +08:00
* node app [environment]
*
* environments: [development, test, production]
*
*/
var _ = require('underscore');
var cluster = require('cluster');
// sanity check arguments
2011-10-08 00:28:07 +08:00
var ENV = process.argv[2];
2011-09-16 19:43:10 +08:00
if (ENV != 'development' && ENV != 'production' && ENV != 'test' && ENV != 'staging') {
2011-08-23 21:58:06 +08:00
console.error("\n./cluster [environment]");
2011-09-16 19:43:10 +08:00
console.error("environments: [development, test, production, staging]");
2011-06-20 21:39:12 +08:00
process.exit(1);
}
// set Node.js app settings and boot
2011-10-08 00:28:07 +08:00
global.settings = require(__dirname + '/config/settings');
var env = require(__dirname + '/config/environments/' + ENV);
2011-06-20 21:39:12 +08:00
_.extend(global.settings, env);
cluster('./app/controllers/app')
.use(cluster.logger('logs'))
.use(cluster.stats())
.use(cluster.pidfiles('pids'))
.listen(global.settings.node_port, global.settings.node_host);
2011-09-05 07:49:46 +08:00
2011-09-16 19:43:10 +08:00
console.log('CartoDB SQL-API running on port: ' + global.settings.node_port);