forked from aliyun-node/agentx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
start_client.js
executable file
·48 lines (41 loc) · 1.26 KB
/
start_client.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
#!/usr/bin/env node
'use strict';
var path = require('path');
var nounou = require('nounou');
var util = require('util');
var clientPath = path.join(__dirname, 'client.js');
var argv = process.argv.slice(2);
var printUsage = function () {
console.log('参数错误。用法示例:');
console.log(' agentx <config.json>');
console.log(' agentx -v');
};
if (argv.length < 1) {
printUsage();
process.exit(1);
}
if (argv[0] === '-v') {
console.log(require('./package.json').version);
process.exit(0);
}
nounou(clientPath, {
args: [argv[0]],
count: 1
})
.on('fork', function (client) {
console.log('[%s] [client:%d] new client start', Date(), client.pid);
})
.on('disconnect', function (client) {
console.error('[%s] [%s] client:%s disconnect, suicide: %s.',
Date(), process.pid, client.pid, client.suicide);
})
.on('expectedExit', function (client, code, signal) {
console.log('[%s] [%s], client %s died (code: %s, signal: %s)', Date(),
process.pid, client.pid, code, signal);
})
.on('unexpectedExit', function (client, code, signal) {
var err = new Error(util.format('client %s died (code: %s, signal: %s)',
client.pid, code, signal));
err.name = 'ClientDiedError';
console.error('[%s] [%s] client exit: %s', Date(), process.pid, err.stack);
});