-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfliplet-agent-uninstall.js
73 lines (60 loc) · 1.67 KB
/
fliplet-agent-uninstall.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const os = require('os');
const path = require('path');
let packageName;
switch (os.platform()) {
case 'win32':
packageName = 'node-windows';
break;
case 'darwin':
packageName = 'node-mac';
break;
default:
throw new Error('OS not supported');
}
const Service = require(packageName).Service;
const { Agent, config } = require('./libs/agent-bootstrap');
try {
(new Agent(config.config)).then(function (agent) {
config.setup(agent, {
log
});
if (!agent.operations.length) {
console.error('No operations have been defined.');
}
const fileName = path.basename(config.path).split('.')[0];
const description = agent.operations[0].description;
log.info(`Registering operation ${description} for file ${fileName}`);
// Create a new service object
const svc = new Service({
name: `Fliplet Agent (${fileName})`,
description,
script: require('path').join(__dirname, 'fliplet-agent-start.js'),
workingdirectory: require('path').join(__dirname, 'fliplet-agent-start.js'),
env: [
{
name: 'CFGPATH',
value: config.path
},
{
name: 'SERVICE',
value: true
}
],
nodeOptions: [
'--harmony',
'--max_old_space_size=4096'
]
});
svc.on('error', console.error);
svc.on('uninstall',function(){
console.info('The agent has been uninstalled successfully.');
process.exit();
});
// Uninstall the service.
svc.uninstall();
}).catch(function (err) {
log.critical(err);
});
} catch (e) {
log.critical(`There was an error running your config file. (Error: ${e.message})`);
}