-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.js
46 lines (39 loc) · 1.12 KB
/
loader.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
40
41
42
43
44
45
46
var nconf = require('nconf'),
fs = require('fs'),
path = require('path'),
async = require('async'),
configFilePath = path.join(__dirname, 'config.json'),
pidFilePath = path.join(__dirname, 'pidfile'),
File = require('./src/utils/File'),
Loader = require('./src/Loader');
fs.open(configFilePath, 'r', function(err) {
var pid, loader;
if(!err) {
// configure nconf
nconf.argv().env().file({
file: configFilePath
});
loader = new Loader(nconf);
loader.init();
loader.displayStartupMessages();
loader.start();
if(nconf.get('daemon') !== 'false' && nconf.get('daemon') !== false) {
if(File.existsSync(pidFilePath)) {
try {
pid = fs.readFileSync(pidFilePath, { encoding: 'utf-8' });
process.kill(pid, 0);
process.exit();
} catch (e) {
fs.unlinkSync(pidFilePath);
}
}
require('daemon')({
stdout: process.stdout,
stderr: process.stderr
});
fs.writeFile(__dirname + '/pidfile', process.pid);
}
} else {
console.log('Missing master configuation file.');
}
});