-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
31 lines (26 loc) · 881 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
var logger = require('../service/logger'),
webserver = require('./webserver/webserver'),
cluster = require('cluster'),
os = require('os'),
config = require('config').aqi;
// setup node environment
process.env.NODE_ENV = process.env.NODE_ENV ? process.env.NODE_ENV : 'development';
var childsNo = function() {
return config.webserver.childs == 'auto'
? os.cpus().length
: config.webserver.childs;
};
if (cluster.isMaster) {
process.title = 'deep-breath-aqi: master';
// spawn given number of children processes
for (var i = 0; i < childsNo(); i++) {
cluster.fork();
}
} else {
process.title = 'deep-breath-aqi: webserver';
webserver.init().done(function() {
logger.info('[app] Webserver process initialised: %d', process.pid)
}, function(error) {
logger.error('[app] Error while initializing webserver process %d: %s', process.pid, error.message);
});
}