forked from legraphista/newrelic-neo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·50 lines (45 loc) · 1.32 KB
/
index.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
47
48
49
50
#!/usr/bin/env node
var argv = require("./args");
var config = require('./getConfig');
var logger = require("./prettyConsole");
var path = require('path');
var fs = require('fs');
if (argv.f || argv.fork) {
logger.log("Forking process...");
var args = [].concat(process.argv).slice(2);
var child = require("daemon").daemon(path.join(__dirname, 'daemon.js'), args);
logger.log('Forked child with pid ' + child.pid);
fs.appendFileSync(global.PID, child.pid + '\n');
process.exit(0);
}
if (argv.stop) {
if (!fs.existsSync(global.PID)) {
console.warn('Cannot find pid file!');
process.exit(2);
}
logger.log('Reading pidfile', global.PID);
var pids = fs.readFileSync(global.PID).toString().trim().split('\n');
pids.forEach(function(pid) {
try {
console.log('Sending SIGTERM to', pid);
process.kill(pid);
} catch (ex) {
console.error(ex);
}
});
fs.unlinkSync(global.PID);
process.exit(0);
}
if (argv['print-config']) {
var configFile =
(fs.existsSync(global.CONFIG_FILE) && require(global.CONFIG_FILE)) ||
require('./config');
logger.log(JSON.stringify(configFile, null, 4));
process.exit(0);
}
if (!config) {
console.warn('Config not provided, please refer to -h/--help');
process.exit(1);
}
fs.appendFileSync(global.PID, process.pid + '\n');
require('./daemon');