iobroker.bee 0.2.3 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -4
- package/admin/jsonConfig.json +23 -5
- package/build/lib/commands.js +8 -1
- package/build/lib/commands.js.map +1 -1
- package/build/lib/jobs.js +122 -3
- package/build/lib/jobs.js.map +1 -1
- package/build/lib/logs.js +186 -0
- package/build/lib/logs.js.map +1 -0
- package/build/lib/node.js +239 -0
- package/build/lib/node.js.map +1 -0
- package/build/lib/planner.js +25 -7
- package/build/lib/planner.js.map +1 -1
- package/build/lib/preflight.js +7 -0
- package/build/lib/preflight.js.map +1 -1
- package/build/lib/protocol.js +3 -1
- package/build/lib/protocol.js.map +1 -1
- package/build/main.js +123 -7
- package/build/main.js.map +1 -1
- package/build/runner.js +8 -0
- package/build/runner.js.map +1 -1
- package/io-package.json +10 -2
- package/package.json +3 -2
- package/scripts/node-update.sh +134 -0
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.NODE_VERDICT = exports.NODE_STATUS = void 0;
|
|
7
|
+
exports.majorOf = majorOf;
|
|
8
|
+
exports.nodeStep = nodeStep;
|
|
9
|
+
exports.serviceOf = serviceOf;
|
|
10
|
+
exports.nodeBlockers = nodeBlockers;
|
|
11
|
+
exports.engineConflicts = engineConflicts;
|
|
12
|
+
exports.readEngines = readEngines;
|
|
13
|
+
exports.nodeFacts = nodeFacts;
|
|
14
|
+
exports.nodeUnit = nodeUnit;
|
|
15
|
+
exports.launchNodeUpdate = launchNodeUpdate;
|
|
16
|
+
exports.unitActive = unitActive;
|
|
17
|
+
exports.readNodeStatus = readNodeStatus;
|
|
18
|
+
exports.readVerdict = readVerdict;
|
|
19
|
+
exports.writeVerdict = writeVerdict;
|
|
20
|
+
const node_child_process_1 = require("node:child_process");
|
|
21
|
+
const node_fs_1 = require("node:fs");
|
|
22
|
+
const promises_1 = require("node:fs/promises");
|
|
23
|
+
const node_path_1 = require("node:path");
|
|
24
|
+
const semver_1 = __importDefault(require("semver"));
|
|
25
|
+
const util_1 = require("./util");
|
|
26
|
+
/**
|
|
27
|
+
* Update of Node.js to the major line of the profile (DesiredProfile.node), only upwards.
|
|
28
|
+
*
|
|
29
|
+
* Node.js comes from the package nodejs of NodeSource, as the installer of ioBroker sets it up. The update
|
|
30
|
+
* stops ioBroker, so the agent cannot do it itself: it starts scripts/node-update.sh as root in a systemd
|
|
31
|
+
* unit of its own (sudo systemd-run, which the installer allows the user iobroker). After the restart the
|
|
32
|
+
* agent checks under the new Node.js that the instances that ran before run again and writes its verdict;
|
|
33
|
+
* without a positive verdict the script installs the old package again. Files in the data directory:
|
|
34
|
+
* node-status.json (script), node-verdict.json (agent), node-update.log.
|
|
35
|
+
*/
|
|
36
|
+
exports.NODE_STATUS = 'node-status.json';
|
|
37
|
+
exports.NODE_VERDICT = 'node-verdict.json';
|
|
38
|
+
const NODE_SCRIPT = 'node-update.sh';
|
|
39
|
+
/** Major line of a version, e.g. 22 for "v22.11.0", "22" or "22.x" */
|
|
40
|
+
function majorOf(version) {
|
|
41
|
+
return semver_1.default.coerce(version ?? '')?.major || null;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The step that brings Node.js to the major line of the profile; null if it runs that line already, or a
|
|
45
|
+
* newer one (no downgrades)
|
|
46
|
+
*
|
|
47
|
+
* @param target DesiredProfile.node, e.g. "22"
|
|
48
|
+
* @param current process.version
|
|
49
|
+
*/
|
|
50
|
+
function nodeStep(target, current) {
|
|
51
|
+
const want = majorOf(target);
|
|
52
|
+
const have = majorOf(current);
|
|
53
|
+
if (!want || !have || want <= have) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
return { action: 'node', from: current, to: String(want), status: 'pending' };
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The systemd service ioBroker runs in, from /proc/self/cgroup, e.g. "iobroker.service"
|
|
60
|
+
*
|
|
61
|
+
* @param cgroup content of /proc/self/cgroup
|
|
62
|
+
*/
|
|
63
|
+
function serviceOf(cgroup) {
|
|
64
|
+
return /\/system\.slice\/([^/\s]+\.service)/.exec(cgroup)?.[1] ?? null;
|
|
65
|
+
}
|
|
66
|
+
/** Reasons that block the update of Node.js; empty if it can run */
|
|
67
|
+
function nodeBlockers(f) {
|
|
68
|
+
if (f.platform !== 'linux') {
|
|
69
|
+
return ['nur unter Linux möglich'];
|
|
70
|
+
}
|
|
71
|
+
const errors = [];
|
|
72
|
+
if (!f.service) {
|
|
73
|
+
errors.push('ioBroker läuft nicht als systemd-Dienst');
|
|
74
|
+
}
|
|
75
|
+
if (!f.sudo) {
|
|
76
|
+
errors.push('kein sudo ohne Passwort für systemd-run (Installation mit --hardened?)');
|
|
77
|
+
}
|
|
78
|
+
if (!f.packaged || !f.source) {
|
|
79
|
+
errors.push('Node.js stammt nicht aus dem Paket nodejs von NodeSource');
|
|
80
|
+
}
|
|
81
|
+
else if (f.arch !== 'amd64' && f.arch !== 'arm64') {
|
|
82
|
+
errors.push(`NodeSource bietet für ${f.arch || 'diese Architektur'} kein Node.js an (nur amd64 und arm64)`);
|
|
83
|
+
}
|
|
84
|
+
if (f.held) {
|
|
85
|
+
errors.push('das Paket nodejs ist auf hold gesetzt');
|
|
86
|
+
}
|
|
87
|
+
if (!f.offDeviceBackup) {
|
|
88
|
+
errors.push('keine Sicherung außerhalb des Geräts (BackItUp)');
|
|
89
|
+
}
|
|
90
|
+
return errors;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Installed packages whose engines.node excludes the major line
|
|
94
|
+
*
|
|
95
|
+
* @param target major line, e.g. 22
|
|
96
|
+
* @param engines per package its version and engines.node
|
|
97
|
+
*/
|
|
98
|
+
function engineConflicts(target, engines) {
|
|
99
|
+
const line = `^${target}.0.0`;
|
|
100
|
+
return Object.entries(engines)
|
|
101
|
+
.filter(([, e]) => !!e.node && !!semver_1.default.validRange(e.node) && !semver_1.default.intersects(e.node, line))
|
|
102
|
+
.map(([name, e]) => `${name}@${e.version} verlangt Node ${e.node}`);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Version and engines.node of installed packages iobroker.<name>
|
|
106
|
+
*
|
|
107
|
+
* @param cwd directory of ioBroker, e.g. /opt/iobroker
|
|
108
|
+
* @param names adapters, "js-controller" for the controller
|
|
109
|
+
*/
|
|
110
|
+
function readEngines(cwd, names) {
|
|
111
|
+
const result = {};
|
|
112
|
+
for (const name of names) {
|
|
113
|
+
try {
|
|
114
|
+
const pkg = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(cwd, 'node_modules', `iobroker.${name}`, 'package.json'), 'utf8'));
|
|
115
|
+
const node = pkg.engines?.node;
|
|
116
|
+
result[name] = { version: String(pkg.version), ...(typeof node === 'string' ? { node } : {}) };
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
// not installed as a package of its own
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
function run(cmd, args, timeout = 15_000) {
|
|
125
|
+
return new Promise(resolve => {
|
|
126
|
+
(0, node_child_process_1.execFile)(cmd, args, { timeout, windowsHide: true }, (error, stdout, stderr) => resolve({ ok: !error, out: String(stdout).trim(), err: String(stderr).trim() || error?.message || '' }));
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
const isRoot = () => process.getuid?.() === 0;
|
|
130
|
+
/** Root runs systemd-run itself, everybody else with sudo -n */
|
|
131
|
+
function asRoot(args) {
|
|
132
|
+
return isRoot() ? [args[0], args.slice(1)] : ['sudo', ['-n', ...args]];
|
|
133
|
+
}
|
|
134
|
+
function realpath(path) {
|
|
135
|
+
try {
|
|
136
|
+
return (0, node_fs_1.realpathSync)(path);
|
|
137
|
+
}
|
|
138
|
+
catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
const SOURCES = ['/etc/apt/sources.list.d/nodesource.sources', '/etc/apt/sources.list.d/nodesource.list'];
|
|
143
|
+
/**
|
|
144
|
+
* Looks at this system
|
|
145
|
+
*
|
|
146
|
+
* @param offDeviceBackup Inventory.backup.offDevice
|
|
147
|
+
*/
|
|
148
|
+
async function nodeFacts(offDeviceBackup) {
|
|
149
|
+
const facts = {
|
|
150
|
+
platform: process.platform,
|
|
151
|
+
service: null,
|
|
152
|
+
sudo: false,
|
|
153
|
+
arch: null,
|
|
154
|
+
packaged: false,
|
|
155
|
+
source: false,
|
|
156
|
+
held: false,
|
|
157
|
+
offDeviceBackup,
|
|
158
|
+
};
|
|
159
|
+
if (process.platform !== 'linux') {
|
|
160
|
+
return facts;
|
|
161
|
+
}
|
|
162
|
+
const binary = realpath(process.execPath);
|
|
163
|
+
const [cgroup, sudo, arch, owner, held] = await Promise.all([
|
|
164
|
+
(0, promises_1.readFile)('/proc/self/cgroup', 'utf8').catch(() => ''),
|
|
165
|
+
run(...asRoot(['systemd-run', '--version'])),
|
|
166
|
+
run('dpkg', ['--print-architecture']),
|
|
167
|
+
binary ? run('dpkg', ['-S', binary]) : Promise.resolve({ ok: false, out: '', err: '' }),
|
|
168
|
+
run('apt-mark', ['showhold', 'nodejs']),
|
|
169
|
+
]);
|
|
170
|
+
facts.service = serviceOf(cgroup);
|
|
171
|
+
facts.sudo = sudo.ok;
|
|
172
|
+
facts.arch = arch.ok ? arch.out : null;
|
|
173
|
+
facts.packaged = !!binary && binary === realpath('/usr/bin/node') && owner.ok && owner.out.startsWith('nodejs:');
|
|
174
|
+
facts.source = SOURCES.some(f => (0, node_fs_1.existsSync)(f) && /deb\.nodesource\.com\/node_\d+\.x/.test((0, node_fs_1.readFileSync)(f, 'utf8')));
|
|
175
|
+
facts.held = held.ok && held.out.split('\n').some(l => l.trim() === 'nodejs');
|
|
176
|
+
return facts;
|
|
177
|
+
}
|
|
178
|
+
/** Name of the systemd unit for an update of Node.js */
|
|
179
|
+
function nodeUnit(now = Date.now()) {
|
|
180
|
+
return `bee-node-${now}`;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Starts scripts/node-update.sh as root in a unit of its own. It stops ioBroker, so this process ends soon.
|
|
184
|
+
*
|
|
185
|
+
* @param o what to start
|
|
186
|
+
* @param o.dir data directory of the agent
|
|
187
|
+
* @param o.target major line
|
|
188
|
+
* @param o.service systemd service of ioBroker
|
|
189
|
+
* @param o.unit name of the unit, see nodeUnit
|
|
190
|
+
* @param o.waitSeconds how long the script waits for the verdict of the agent
|
|
191
|
+
*/
|
|
192
|
+
async function launchNodeUpdate(o) {
|
|
193
|
+
await (0, promises_1.rm)((0, node_path_1.join)(o.dir, exports.NODE_STATUS), { force: true });
|
|
194
|
+
await (0, promises_1.rm)((0, node_path_1.join)(o.dir, exports.NODE_VERDICT), { force: true });
|
|
195
|
+
// a copy: the package of the agent may change while the script runs
|
|
196
|
+
const script = (0, node_path_1.join)(o.dir, NODE_SCRIPT);
|
|
197
|
+
await (0, promises_1.copyFile)((0, node_path_1.join)(__dirname, '..', '..', 'scripts', NODE_SCRIPT), script);
|
|
198
|
+
const r = await run(...asRoot([
|
|
199
|
+
'systemd-run',
|
|
200
|
+
`--unit=${o.unit}`,
|
|
201
|
+
'--collect',
|
|
202
|
+
'--quiet',
|
|
203
|
+
`--description=ioBroker.bee: Node.js ${o.target}`,
|
|
204
|
+
'/bin/bash',
|
|
205
|
+
script,
|
|
206
|
+
o.dir,
|
|
207
|
+
o.target,
|
|
208
|
+
o.service,
|
|
209
|
+
String(o.waitSeconds),
|
|
210
|
+
]));
|
|
211
|
+
if (!r.ok) {
|
|
212
|
+
throw new Error(`systemd-run: ${r.err || r.out || 'fehlgeschlagen'}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** Whether the unit of the script is still there (it is removed when the script ends) */
|
|
216
|
+
async function unitActive(unit) {
|
|
217
|
+
return (await run('systemctl', ['is-active', '--quiet', unit])).ok;
|
|
218
|
+
}
|
|
219
|
+
function readNodeStatus(dir) {
|
|
220
|
+
return (0, util_1.readJson)((0, node_path_1.join)(dir, exports.NODE_STATUS));
|
|
221
|
+
}
|
|
222
|
+
/** Whether the agent already gave its verdict to the script, and which */
|
|
223
|
+
async function readVerdict(dir) {
|
|
224
|
+
return (0, util_1.readJson)((0, node_path_1.join)(dir, exports.NODE_VERDICT));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* The verdict of the agent under the new Node.js. On one line: the script reads it with grep and sed.
|
|
228
|
+
*
|
|
229
|
+
* @param dir data directory of the agent
|
|
230
|
+
* @param ok the instances run, the script keeps the new Node.js
|
|
231
|
+
* @param reason otherwise why, the script goes back to the old one
|
|
232
|
+
*/
|
|
233
|
+
async function writeVerdict(dir, ok, reason = '') {
|
|
234
|
+
const file = (0, node_path_1.join)(dir, exports.NODE_VERDICT);
|
|
235
|
+
const data = ok ? { ok: true } : { ok: false, reason: reason.replace(/["\\\r\n]/g, ' ').slice(0, 400) };
|
|
236
|
+
await (0, promises_1.writeFile)(`${file}.tmp`, `${JSON.stringify(data)}\n`);
|
|
237
|
+
await (0, promises_1.rename)(`${file}.tmp`, file);
|
|
238
|
+
}
|
|
239
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../../src/lib/node.ts"],"names":[],"mappings":";;;;;;AAiCA,0BAEC;AASD,4BAOC;AAOD,8BAEC;AAsBD,oCAuBC;AAQD,0CAKC;AAQD,kCAYC;AAgCD,8BA+BC;AAGD,4BAEC;AAYD,4CA8BC;AAGD,gCAEC;AAED,wCAEC;AAGD,kCAEC;AASD,oCAKC;AApRD,2DAA8C;AAC9C,qCAAiE;AACjE,+CAA6E;AAC7E,yCAAiC;AACjC,oDAA4B;AAE5B,iCA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AED,yFAAyF;AAClF,KAAK,UAAU,UAAU,CAAC,IAAY;IACzC,OAAO,CAAC,MAAM,GAAG,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvE,CAAC;AAED,SAAgB,cAAc,CAAC,GAAW;IACtC,OAAO,IAAA,eAAQ,EAAa,IAAA,gBAAI,EAAC,GAAG,EAAE,mBAAW,CAAC,CAAC,CAAC;AACxD,CAAC;AAED,0EAA0E;AACnE,KAAK,UAAU,WAAW,CAAC,GAAW;IACzC,OAAO,IAAA,eAAQ,EAAmC,IAAA,gBAAI,EAAC,GAAG,EAAE,oBAAY,CAAC,CAAC,CAAC;AAC/E,CAAC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,YAAY,CAAC,GAAW,EAAE,EAAW,EAAE,MAAM,GAAG,EAAE;IACpE,MAAM,IAAI,GAAG,IAAA,gBAAI,EAAC,GAAG,EAAE,oBAAY,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IACxG,MAAM,IAAA,oBAAS,EAAC,GAAG,IAAI,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,MAAM,IAAA,iBAAM,EAAC,GAAG,IAAI,MAAM,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC"}
|
package/build/lib/planner.js
CHANGED
|
@@ -8,6 +8,7 @@ exports.computePlan = computePlan;
|
|
|
8
8
|
exports.rollbackPlan = rollbackPlan;
|
|
9
9
|
exports.checkDependencies = checkDependencies;
|
|
10
10
|
const semver_1 = __importDefault(require("semver"));
|
|
11
|
+
const node_1 = require("./node");
|
|
11
12
|
const util_1 = require("./util");
|
|
12
13
|
/** Adapters installed locally that are neither in the profile, tolerated, nor scheduled for removal */
|
|
13
14
|
function foreignAdapters(desired, installed) {
|
|
@@ -23,7 +24,7 @@ function foreignAdapters(desired, installed) {
|
|
|
23
24
|
.sort();
|
|
24
25
|
}
|
|
25
26
|
/**
|
|
26
|
-
* Steps to reach the profile.
|
|
27
|
+
* Steps to reach the profile. Node.js comes first, the agent (bee) always last.
|
|
27
28
|
*
|
|
28
29
|
* @param desired desired state of the server
|
|
29
30
|
* @param installed installed versions
|
|
@@ -31,8 +32,9 @@ function foreignAdapters(desired, installed) {
|
|
|
31
32
|
* @param from where the adapters were installed from (installedFrom); with a package of the server and the
|
|
32
33
|
* same version installed from somewhere else, the package is installed once more (a build that kept
|
|
33
34
|
* the version number). Only given as long as that was not tried yet for this job.
|
|
35
|
+
* @param node the running Node.js (process.version); with it a step to the major line of the profile
|
|
34
36
|
*/
|
|
35
|
-
function computePlan(desired, installed, selfName = 'bee', from) {
|
|
37
|
+
function computePlan(desired, installed, selfName = 'bee', from, node) {
|
|
36
38
|
const steps = [];
|
|
37
39
|
if (!desired.profile) {
|
|
38
40
|
return steps;
|
|
@@ -63,12 +65,15 @@ function computePlan(desired, installed, selfName = 'bee', from) {
|
|
|
63
65
|
}
|
|
64
66
|
// removals first (frees space), then installs/updates alphabetically, the agent last
|
|
65
67
|
const rank = (s) => (s.adapter === selfName ? 2 : s.action === 'remove' ? 0 : 1);
|
|
66
|
-
|
|
68
|
+
steps.sort((a, b) => rank(a) - rank(b) || a.adapter.localeCompare(b.adapter));
|
|
69
|
+
// Node.js before everything else: the new versions may need it
|
|
70
|
+
const step = node ? (0, node_1.nodeStep)(desired.profile.node, node) : null;
|
|
71
|
+
return step ? [step, ...steps] : steps;
|
|
67
72
|
}
|
|
68
|
-
/** Steps that restore the previous state after a failed rollout (reverse order) */
|
|
73
|
+
/** Steps that restore the previous state after a failed rollout (reverse order); Node.js stays */
|
|
69
74
|
function rollbackPlan(steps) {
|
|
70
75
|
return steps
|
|
71
|
-
.filter(s => s.action !== 'backup' && s.status === 'ok')
|
|
76
|
+
.filter(s => s.action !== 'backup' && s.action !== 'node' && s.status === 'ok')
|
|
72
77
|
.reverse()
|
|
73
78
|
.map(s => {
|
|
74
79
|
if (s.action === 'install') {
|
|
@@ -90,6 +95,12 @@ function rollbackPlan(steps) {
|
|
|
90
95
|
* Checks the dependencies of all target versions against the state after the plan
|
|
91
96
|
* (io-package.json dependencies, globalDependencies and engines.node of the target version).
|
|
92
97
|
*
|
|
98
|
+
* @param desired desired state of the server
|
|
99
|
+
* @param installed installed versions
|
|
100
|
+
* @param env versions on the system
|
|
101
|
+
* @param env.jsController installed js-controller
|
|
102
|
+
* @param env.node running Node.js
|
|
103
|
+
* @param env.nodeMajor the major line the plan brings Node.js to before the adapters
|
|
93
104
|
* @returns list of violations; empty if everything fits
|
|
94
105
|
*/
|
|
95
106
|
function checkDependencies(desired, installed, env) {
|
|
@@ -108,8 +119,15 @@ function checkDependencies(desired, installed, env) {
|
|
|
108
119
|
if (installed[name] === a.version) {
|
|
109
120
|
continue;
|
|
110
121
|
}
|
|
111
|
-
if (a.node && semver_1.default.validRange(a.node)
|
|
112
|
-
|
|
122
|
+
if (a.node && semver_1.default.validRange(a.node)) {
|
|
123
|
+
if (env.nodeMajor) {
|
|
124
|
+
if (!semver_1.default.intersects(a.node, `^${env.nodeMajor}.0.0`)) {
|
|
125
|
+
errors.push(`${name}@${a.version} verlangt Node ${a.node}, geplant ist Node ${env.nodeMajor}`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (!semver_1.default.satisfies(env.node, a.node)) {
|
|
129
|
+
errors.push(`${name}@${a.version} verlangt Node ${a.node}, installiert ist ${env.node}`);
|
|
130
|
+
}
|
|
113
131
|
}
|
|
114
132
|
for (const dep of [...(a.dependencies || []), ...(a.globalDependencies || [])]) {
|
|
115
133
|
for (const [depName, range] of Object.entries(dep)) {
|
package/build/lib/planner.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"planner.js","sourceRoot":"","sources":["../../src/lib/planner.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"planner.js","sourceRoot":"","sources":["../../src/lib/planner.ts"],"names":[],"mappings":";;;;;AAeA,0CAcC;AAaD,kCAyCC;AAGD,oCAmBC;AAcD,8CAyCC;AAhKD,oDAA4B;AAC5B,iCAAkC;AAElC,iCAAyC;AAWzC,uGAAuG;AACvG,SAAgB,eAAe,CAAC,OAAuB,EAAE,SAAoB;IACzE,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,EAAE,CAAC;IACd,CAAC;IACD,OAAO,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC;SACxB,MAAM,CACH,CAAC,CAAC,EAAE,CACA,CAAC,OAAO,CAAC,OAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC7B,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC9B,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;QAC3B,2DAA2D;QAC3D,CAAC,KAAK,eAAe,CAC5B;SACA,IAAI,EAAE,CAAC;AAChB,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CACvB,OAAuB,EACvB,SAAoB,EACpB,QAAQ,GAAG,KAAK,EAChB,IAAyC,EACzC,IAAa;IAEb,MAAM,KAAK,GAAc,EAAE,CAAC;IAC5B,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,KAAK,CAAC;IACjB,CAAC;IACD,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpE,MAAM,OAAO,GAAG,SAAS,CAAC,IA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C,SAAS,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;oBACjG,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,OAAO,YAAY,OAAO,IAAI,KAAK,mBAAmB,IAAI,EAAE,CAAC,CAAC;gBAC3F,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/build/lib/preflight.js
CHANGED
|
@@ -57,6 +57,13 @@ async function preflight(input) {
|
|
|
57
57
|
if (input.dependencyErrors.length) {
|
|
58
58
|
return { ok: false, kind: 'block', reason: `Abhängigkeiten: ${input.dependencyErrors.join('; ')}` };
|
|
59
59
|
}
|
|
60
|
+
if (input.nodeErrors?.errors.length) {
|
|
61
|
+
return {
|
|
62
|
+
ok: false,
|
|
63
|
+
kind: 'block',
|
|
64
|
+
reason: `Update auf Node.js ${input.nodeErrors.target} nicht möglich: ${input.nodeErrors.errors.join('; ')}`,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
60
67
|
const free = await freeDiskMb(input.diskPath);
|
|
61
68
|
if (free !== null && free < input.minFreeMb) {
|
|
62
69
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../src/lib/preflight.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"preflight.js","sourceRoot":"","sources":["../../src/lib/preflight.ts"],"names":[],"mappings":";;AA8CA,0BAyBC;AAED,gCAOC;AAED,8BA2CC;AA7HD,+CAA0C;AAC1C,iCAAkC;AAkClC,SAAS,MAAM,CAAC,KAAa;IACzB,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IACvB,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,OAAO,EAAE,CAAC;QAChC,OAAO,CAAC,KAAK,MAAM,CAAC;IACxB,CAAC;IACD,IAAI,CAAC,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,GAAG,CAAC,cAAc,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACzG,CAAC;IACL,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC;AACxB,CAAC"}
|
package/build/lib/protocol.js
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
* WebSocket to TUNNEL_PATH of the server and carries the connections of the browser (see tunnel.ts).
|
|
21
21
|
*/
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
exports.TERMINAL_JOB_STATES = exports.TUNNEL_PATH = exports.ACCESS_KINDS = exports.INSTANCE_ID = exports.MAX_COMMENT_LENGTH = exports.PROTOCOL_VERSION = void 0;
|
|
23
|
+
exports.TERMINAL_JOB_STATES = exports.TUNNEL_PATH = exports.ACCESS_KINDS = exports.MAX_LOG_UPLOAD_BYTES = exports.INSTANCE_ID = exports.MAX_COMMENT_LENGTH = exports.PROTOCOL_VERSION = void 0;
|
|
24
24
|
exports.deviceTopic = deviceTopic;
|
|
25
25
|
exports.controlTopic = controlTopic;
|
|
26
26
|
exports.normalizeComment = normalizeComment;
|
|
@@ -63,6 +63,8 @@ function parseOsPackage(line) {
|
|
|
63
63
|
}
|
|
64
64
|
/** Instance id as the commands accept it, e.g. "javascript.0" */
|
|
65
65
|
exports.INSTANCE_ID = /^[a-z0-9][a-z0-9_-]*\.\d{1,4}$/;
|
|
66
|
+
/** Largest log file the agent uploads, compressed (nginx in front of the server allows 52 MB) */
|
|
67
|
+
exports.MAX_LOG_UPLOAD_BYTES = 50 * 1024 * 1024;
|
|
66
68
|
exports.ACCESS_KINDS = ['admin', 'vis', 'console'];
|
|
67
69
|
/** WebSocket path of the tunnel endpoint on the server */
|
|
68
70
|
exports.TUNNEL_PATH = '/tunnel';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/lib/protocol.ts"],"names":[],"mappings":";AAAA;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C,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AAC1E,CAAC;AAED,iEAAiE;AACpD,QAAA,WAAW,GAAG,gCAAgC,CAAC;AAe5D,iGAAiG;AACpF,QAAA,oBAAoB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AA4GxC,QAAA,YAAY,GAAiB,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAetE,0DAA0D;AAC7C,QAAA,WAAW,GAAG,SAAS,CAAC;AAyBxB,QAAA,mBAAmB,GAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC"}
|
package/build/main.js
CHANGED
|
@@ -38,6 +38,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
39
|
const utils = __importStar(require("@iobroker/adapter-core"));
|
|
40
40
|
const node_fs_1 = require("node:fs");
|
|
41
|
+
const promises_1 = require("node:fs/promises");
|
|
41
42
|
const node_os_1 = __importDefault(require("node:os"));
|
|
42
43
|
const node_path_1 = require("node:path");
|
|
43
44
|
const commands_1 = require("./lib/commands");
|
|
@@ -46,6 +47,8 @@ const instances_1 = require("./lib/instances");
|
|
|
46
47
|
const enrollment_1 = require("./lib/enrollment");
|
|
47
48
|
const inventory_1 = require("./lib/inventory");
|
|
48
49
|
const jobs_1 = require("./lib/jobs");
|
|
50
|
+
const logs_1 = require("./lib/logs");
|
|
51
|
+
const node_1 = require("./lib/node");
|
|
49
52
|
const packages_1 = require("./lib/packages");
|
|
50
53
|
const planner_1 = require("./lib/planner");
|
|
51
54
|
const preflight_1 = require("./lib/preflight");
|
|
@@ -54,6 +57,15 @@ const remote_1 = require("./lib/remote");
|
|
|
54
57
|
const transport_1 = require("./lib/transport");
|
|
55
58
|
const tunnel_1 = require("./lib/tunnel");
|
|
56
59
|
const util_1 = require("./lib/util");
|
|
60
|
+
/** Host of the broker for the status, e.g. "bee.iobroker.click" */
|
|
61
|
+
function hostOf(url) {
|
|
62
|
+
try {
|
|
63
|
+
return new URL(url || '').hostname || 'der Flottenverwaltung';
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return 'der Flottenverwaltung';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
57
69
|
class BeeAdapter extends utils.Adapter {
|
|
58
70
|
dataDir = '';
|
|
59
71
|
creds = null;
|
|
@@ -73,6 +85,7 @@ class BeeAdapter extends utils.Adapter {
|
|
|
73
85
|
reconciling = false;
|
|
74
86
|
/** A command of the fleet management is being carried out (one at a time) */
|
|
75
87
|
commandRunning = false;
|
|
88
|
+
logUploading = false;
|
|
76
89
|
lastWaitReason = '';
|
|
77
90
|
unloading = false;
|
|
78
91
|
/** Open remote access sessions by session id */
|
|
@@ -108,6 +121,16 @@ class BeeAdapter extends utils.Adapter {
|
|
|
108
121
|
instancesOf: adapter => this.instancesOf(adapter),
|
|
109
122
|
errorsSince: (ts, adapters) => this.errorLog.filter(e => e.ts >= ts && adapters.some(a => e.from.startsWith(`${a}.`))),
|
|
110
123
|
onFinished: (job, result) => this.onJobFinished(job, result),
|
|
124
|
+
running: async () => (await this.instancesOf()).filter(i => i.alive).map(i => i.id),
|
|
125
|
+
launchNode: async (target, unit, waitSeconds) => {
|
|
126
|
+
const service = (0, node_1.serviceOf)(await (0, promises_1.readFile)('/proc/self/cgroup', 'utf8').catch(() => ''));
|
|
127
|
+
if (!service) {
|
|
128
|
+
throw new Error('ioBroker läuft nicht als systemd-Dienst');
|
|
129
|
+
}
|
|
130
|
+
this.log.warn(`Node.js is updated to ${target}: ioBroker (${service}) restarts (fleet management)`);
|
|
131
|
+
await (0, node_1.launchNodeUpdate)({ dir: this.dataDir, target, service, unit, waitSeconds });
|
|
132
|
+
},
|
|
133
|
+
unitActive: unit => (0, node_1.unitActive)(unit),
|
|
111
134
|
});
|
|
112
135
|
await this.jobs.load();
|
|
113
136
|
await this.jobs.setHalt(!!this.control?.halt);
|
|
@@ -217,7 +240,7 @@ class BeeAdapter extends utils.Adapter {
|
|
|
217
240
|
async onConnected() {
|
|
218
241
|
this.log.info('Connected to beekeeper');
|
|
219
242
|
await this.setState('info.connection', true, true);
|
|
220
|
-
await this.setState('info.status',
|
|
243
|
+
await this.setState('info.status', `Verbunden mit ${hostOf(this.creds?.mqttUrl)}`, true);
|
|
221
244
|
await this.heartbeat();
|
|
222
245
|
await this.sendInventory(true);
|
|
223
246
|
// results produced while offline
|
|
@@ -262,12 +285,77 @@ class BeeAdapter extends utils.Adapter {
|
|
|
262
285
|
else if (msg.ref && (msg.cmd === 'instance' || msg.cmd === 'restart' || msg.cmd === 'osUpgrade')) {
|
|
263
286
|
await this.runCommand(msg);
|
|
264
287
|
}
|
|
288
|
+
else if (msg.ref && msg.cmd === 'logList') {
|
|
289
|
+
// only reads: also during a job or another command
|
|
290
|
+
await this.logListCommand(msg.ref);
|
|
291
|
+
}
|
|
292
|
+
else if (msg.ref && msg.cmd === 'logFetch') {
|
|
293
|
+
// may take minutes on a mobile connection: the other messages go on meanwhile
|
|
294
|
+
void this.logFetchCommand(msg.ref, msg.by || 'Flottenverwaltung', msg.logFetch);
|
|
295
|
+
}
|
|
265
296
|
}
|
|
266
297
|
// ------------------------------------------------------------------ commands of the fleet management
|
|
267
|
-
async reply(ref, state, message) {
|
|
268
|
-
const msg = {
|
|
298
|
+
async reply(ref, state, message, files) {
|
|
299
|
+
const msg = {
|
|
300
|
+
v: protocol_1.PROTOCOL_VERSION,
|
|
301
|
+
ts: Date.now(),
|
|
302
|
+
ref,
|
|
303
|
+
state,
|
|
304
|
+
...(message ? { message } : {}),
|
|
305
|
+
...(files ? { files } : {}),
|
|
306
|
+
};
|
|
269
307
|
await this.transport?.publish('reply', msg);
|
|
270
308
|
}
|
|
309
|
+
/** Directories of the log files of ioBroker (file transports of iobroker.json) */
|
|
310
|
+
logDirs() {
|
|
311
|
+
let config = null;
|
|
312
|
+
try {
|
|
313
|
+
config = utils.getConfig();
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
this.log.debug(`iobroker.json not readable: ${e.message}`);
|
|
317
|
+
}
|
|
318
|
+
return (0, logs_1.logDirs)(config, (0, node_path_1.join)(utils.controllerDir, '..', '..'));
|
|
319
|
+
}
|
|
320
|
+
async logListCommand(ref) {
|
|
321
|
+
try {
|
|
322
|
+
const files = await (0, logs_1.listLogFiles)(this.logDirs());
|
|
323
|
+
await this.reply(ref, 'done', `${files.length} Log-Dateien`, files);
|
|
324
|
+
}
|
|
325
|
+
catch (e) {
|
|
326
|
+
await this.reply(ref, 'error', e.message);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/** Uploads a log file to the own server, one at a time */
|
|
330
|
+
async logFetchCommand(ref, by, req) {
|
|
331
|
+
try {
|
|
332
|
+
if (this.logUploading) {
|
|
333
|
+
throw new Error('Es wird schon eine Log-Datei übertragen');
|
|
334
|
+
}
|
|
335
|
+
if (!req || typeof req.url !== 'string' || typeof req.ticket !== 'string') {
|
|
336
|
+
throw new Error('Unvollständige Anfrage');
|
|
337
|
+
}
|
|
338
|
+
if (!(0, packages_1.trustedPackageUrl)(req.url, [this.config.enrollUrl, this.creds?.mqttUrl || ''])) {
|
|
339
|
+
throw new Error(`${req.url} gehört nicht zum Flottenserver`);
|
|
340
|
+
}
|
|
341
|
+
const file = await (0, logs_1.findLogFile)(this.logDirs(), req.file);
|
|
342
|
+
if (!file) {
|
|
343
|
+
throw new Error(`Log-Datei ${String(req.file)} gibt es nicht`);
|
|
344
|
+
}
|
|
345
|
+
this.logUploading = true;
|
|
346
|
+
this.log.info(`Log file ${req.file} is uploaded on request of ${by} (fleet management)`);
|
|
347
|
+
await this.reply(ref, 'running', `${req.file} wird komprimiert übertragen`);
|
|
348
|
+
const bytes = await (0, logs_1.uploadLog)(file, req.url, req.ticket, (0, transport_1.trustedCas)(this.creds?.ca || ''));
|
|
349
|
+
await this.reply(ref, 'done', `${req.file}: ${(bytes / 1024 / 1024).toFixed(1)} MB übertragen`);
|
|
350
|
+
}
|
|
351
|
+
catch (e) {
|
|
352
|
+
this.log.warn(`Log file ${String(req?.file)} for ${by}: ${e.message}`);
|
|
353
|
+
await this.reply(ref, 'error', e.message);
|
|
354
|
+
}
|
|
355
|
+
finally {
|
|
356
|
+
this.logUploading = false;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
271
359
|
/** Sends the inventory again a while after a command, when the instances show its effect */
|
|
272
360
|
inventorySoon() {
|
|
273
361
|
for (const ms of [5_000, 30_000]) {
|
|
@@ -502,7 +590,8 @@ class BeeAdapter extends utils.Adapter {
|
|
|
502
590
|
await this.setState('info.remoteAccess', active.length > 0, true);
|
|
503
591
|
await this.setState('info.remoteAccessBy', active
|
|
504
592
|
.map(t => `${remote_1.ACCESS_LABEL[t.kind]}${t.instance ? ` (${t.instance})` : ''}${this.shellText(t)}: ${t.by}, ${t.purpose} (bis ${new Date(t.expiresAt).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })})`)
|
|
505
|
-
|
|
593
|
+
// in the settings an empty value would show the label alone
|
|
594
|
+
.join('; ') || 'keiner', true);
|
|
506
595
|
}
|
|
507
596
|
// ------------------------------------------------------------------ inventory and heartbeat
|
|
508
597
|
async inventory() {
|
|
@@ -603,10 +692,16 @@ class BeeAdapter extends utils.Adapter {
|
|
|
603
692
|
this.errorLog.splice(0, this.errorLog.length - 500);
|
|
604
693
|
}
|
|
605
694
|
}
|
|
695
|
+
/**
|
|
696
|
+
* Enabled instances with a process of their own on this host and whether they run
|
|
697
|
+
*
|
|
698
|
+
* @param adapter only of this adapter; missing: all
|
|
699
|
+
*/
|
|
606
700
|
async instancesOf(adapter) {
|
|
701
|
+
const prefix = adapter ? `system.adapter.${adapter}.` : 'system.adapter.';
|
|
607
702
|
const res = await this.getObjectViewAsync('system', 'instance', {
|
|
608
|
-
startkey:
|
|
609
|
-
endkey:
|
|
703
|
+
startkey: prefix,
|
|
704
|
+
endkey: `${prefix}香`,
|
|
610
705
|
});
|
|
611
706
|
const list = [];
|
|
612
707
|
for (const row of res.rows) {
|
|
@@ -717,7 +812,7 @@ class BeeAdapter extends utils.Adapter {
|
|
|
717
812
|
const from = this.persisted.results[key] === 'done'
|
|
718
813
|
? undefined
|
|
719
814
|
: Object.fromEntries(Object.entries(inv.software.adapters).map(([n, a]) => [n, a.installedFrom]));
|
|
720
|
-
const plan = (0, planner_1.computePlan)(d, installed, this.name, from);
|
|
815
|
+
const plan = (0, planner_1.computePlan)(d, installed, this.name, from, process.version);
|
|
721
816
|
await this.setState('info.onTarget', plan.length === 0, true);
|
|
722
817
|
if (d.mode === 'self') {
|
|
723
818
|
// self-managed: no automatic rollout, only a hint about the new state
|
|
@@ -752,6 +847,7 @@ class BeeAdapter extends utils.Adapter {
|
|
|
752
847
|
}
|
|
753
848
|
// drift after an earlier success (e.g. manual change): converge again
|
|
754
849
|
delete this.persisted.results[key];
|
|
850
|
+
const nodeTarget = plan.find(s => s.action === 'node')?.to ?? undefined;
|
|
755
851
|
const pf = await (0, preflight_1.preflight)({
|
|
756
852
|
now: new Date(),
|
|
757
853
|
halted: !!this.control?.halt,
|
|
@@ -768,7 +864,11 @@ class BeeAdapter extends utils.Adapter {
|
|
|
768
864
|
dependencyErrors: (0, planner_1.checkDependencies)(d, installed, {
|
|
769
865
|
jsController: inv.software.jsController,
|
|
770
866
|
node: process.version,
|
|
867
|
+
nodeMajor: nodeTarget ? Number(nodeTarget) : undefined,
|
|
771
868
|
}),
|
|
869
|
+
nodeErrors: nodeTarget
|
|
870
|
+
? { target: nodeTarget, errors: await this.nodeErrors(nodeTarget, inv, plan) }
|
|
871
|
+
: undefined,
|
|
772
872
|
});
|
|
773
873
|
if (!pf.ok) {
|
|
774
874
|
if (pf.kind === 'block') {
|
|
@@ -805,6 +905,22 @@ class BeeAdapter extends utils.Adapter {
|
|
|
805
905
|
await this.report('preflight', `${plan.length} Schritte geplant, Vorprüfung bestanden`, plan);
|
|
806
906
|
await this.jobs.start(d, plan, this.config.backupBeforeUpdate !== false, files);
|
|
807
907
|
}
|
|
908
|
+
/**
|
|
909
|
+
* Why Node.js cannot go to the major line: the system, and installed packages that exclude it
|
|
910
|
+
* (those the plan changes are checked with their new version by checkDependencies)
|
|
911
|
+
*
|
|
912
|
+
* @param target major line
|
|
913
|
+
* @param inv inventory
|
|
914
|
+
* @param plan steps of the job
|
|
915
|
+
*/
|
|
916
|
+
async nodeErrors(target, inv, plan) {
|
|
917
|
+
const changed = new Set(plan.map(s => s.adapter));
|
|
918
|
+
const names = ['js-controller', ...Object.keys(inv.software.adapters).filter(n => !changed.has(n))];
|
|
919
|
+
return [
|
|
920
|
+
...(0, node_1.nodeBlockers)(await (0, node_1.nodeFacts)(inv.backup.offDevice)),
|
|
921
|
+
...(0, node_1.engineConflicts)(Number(target), (0, node_1.readEngines)((0, node_path_1.join)(utils.controllerDir, '..', '..'), names)),
|
|
922
|
+
];
|
|
923
|
+
}
|
|
808
924
|
// ------------------------------------------------------------------ states, notifications
|
|
809
925
|
async updateInfoStates() {
|
|
810
926
|
await this.setState('info.deviceId', this.creds?.deviceId || '', true);
|