-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.js
executable file
·47 lines (38 loc) · 1.62 KB
/
services.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
"use strict";
(function (exports) {
exports.init = function init(api) {
const child_process = require('child_process');
api.registerDataStream('services',
api.createProcessStream('services', './servicesstream.sh', [], processData, 1000, true)
);
api.pubsub.subscribe('serviceCall', function (opts) {
if (opts.name && opts.command) {
child_process.exec('sudo service ' + opts.name + ' ' + opts.command);
}
});
const svcStatRE = /^ \[ ([-+\?]) \] (.*)$/;
const services = [];
const servicesByName = {};
services.$_idField = 'name';
function processData(data) {
var lines = data.split('\n');
for (var i = 0; i < lines.length; ++i) {
var match = lines[i].match(svcStatRE);
if (match && match.length === 3) {
var name = match[2];
var stat = match[1];
var obj = servicesByName[name];
if (!obj) {
obj = { name: name };
servicesByName[name] = obj;
services.push(obj);
}
obj.stat = stat;
}
}
// need to be referentially different than the previous, otherwise diff() returns NO_DIFF and sends nothing
// TODO: need to fix this in the wsPubSubServer code!
return services.slice();
}
}
})(exports);