forked from WebManufacture/ILAB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRootService.js
78 lines (71 loc) · 2.14 KB
/
RootService.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
74
75
76
77
78
var Path = require('path');
var fs = require('fs');
var os = require("os");
require(Path.resolve("./Frame.js"));
Frame.portsStart = 5600;
Frame._availablePort = Frame.portsStart;
Frame.serviceId = "ServicesManager";
Frame.servicePort = Frame.portsStart;
var ServicesManager = useRoot("System/ServicesManager");
Frame._initFrame = function () {
console.log("Starting ILAB v 3.0.78");
try {
process.setMaxListeners(100);
var wd = process.argv[2];
var services = new ServicesManager(function () {
return Frame._availablePort += 5;
});
services.on("error", function (err) {
if (err.serviceId) {
console.log("Service error: " + err.serviceId);
}
console.error(err.stack);
err.handled = true;
});
/*
spawnMon.on("virtual-start", function (options) {
console.log("Spawn service started with:");
console.log(options);
});
spawnMon.on("virtual-stop", function (options) {
console.log("Spawn service stopped.");
});
spawnMon.on("error", function (err) {
console.error(err);
});
spawnMon.on("virtual-output", function (data) {
console.log(data);
});*/
var allSection = [];
for (var i = 2; i <= process.argv.length; i++){
var arg = process.argv[i];
if (!arg) continue;
if (arg === "--config") {
// используется config.json если третьим аргументом идёт флаг --config
var configFile = require(Path.resolve("./config.json"));
for (var key in configFile) {
allSection.push(services.StartService(key, configFile[key]));
}
}
else{
allSection.push(services.StartService(arg));
}
}
Promise.all(allSection).then(function() {
console.log("All started!");
}).catch(function(err) {
if (err && !err.handled){
console.error("Root error:")
console.error(err);
}
});
/*setInterval(function() {
console.log(new Date());
}, 5000);*/
}
catch (err) {
console.log("RootError: ");
console.error(err);
}
};
Frame._initFrame();