forked from dfilatov/twitter-trends
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.js
39 lines (34 loc) · 922 Bytes
/
boot.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
32
33
34
35
36
37
38
39
var cluster = require('cluster'),
fs = require('fs'),
env = require('./lib/config').get('env'),
logger = require('./lib/logger'),
app = require('./lib/app');
if(cluster.isMaster) {
if(env.socket) {
try {
fs.unlinkSync(env.socket);
}
catch(e) {}
}
var workersCount = env.workersCount;
while(workersCount--) {
cluster.fork();
}
cluster.on('exit', function(worker) {
worker.suicide || cluster.fork();
});
if(env.hotReload) {
['SIGINT', 'SIGTERM', 'SIGQUIT'].forEach(function(signal) {
process.on(signal, function() {
Object.keys(cluster.workers).forEach(function(id) {
cluster.workers[id].destroy();
});
process.exit();
});
});
}
}
else {
logger.info('worker %s started', process.pid);
app.start();
}