clavarium 0.2.531-next.1 → 0.2.535-next.1
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/deploy/multipass-refresh.mjs +9 -11
- package/deploy/updater.mjs +27 -5
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -56,14 +56,14 @@ export async function multipassTurn({ run, mode, inWindow, busy, state, save, lo
|
|
|
56
56
|
|
|
57
57
|
const answers = async () => { for (let i = 0; i < BACK_TRIES; i += 1) { if ((await sh([multipass, 'list', '--format', 'json'], 30_000)).code === 0) return true; await sleep(BACK_EVERY_MS); } return false; };
|
|
58
58
|
/* MUTE AFTER ITS UPDATE (25-11, on a real server: four machines started, then its daemon died and stayed mute for
|
|
59
|
-
three hours). Not waited for: its daemon restarted, then stopped and started for sure
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
three hours). Not waited for: its daemon restarted, then stopped and started for sure; each step said. Its
|
|
60
|
+
previous version is never put back by itself (its owner's choice: it may not read what the new one wrote).
|
|
61
|
+
Still mute: the server's watch tries again every 10 minutes and says so. True once it answers. */
|
|
62
|
+
const rescue = async () => {
|
|
62
63
|
if (await answers()) return true;
|
|
63
64
|
const steps = [
|
|
64
65
|
['its daemon is restarted', ['snap', 'restart', 'multipass.multipassd']],
|
|
65
66
|
['its daemon is stopped and started for sure', null],
|
|
66
|
-
...(updated ? [['its previous version is put back', ['snap', 'revert', 'multipass']]] : []),
|
|
67
67
|
];
|
|
68
68
|
for (const [what, argv] of steps) {
|
|
69
69
|
log(`multipass: it does not answer: ${what}`);
|
|
@@ -74,8 +74,8 @@ export async function multipassTurn({ run, mode, inWindow, busy, state, save, lo
|
|
|
74
74
|
return false;
|
|
75
75
|
};
|
|
76
76
|
/* Started again; what could not be stays written down, for the next turn. */
|
|
77
|
-
const back = async (names
|
|
78
|
-
if (!(await rescue(
|
|
77
|
+
const back = async (names) => {
|
|
78
|
+
if (!(await rescue())) { log('multipass: it still does not answer: its machines are started at the next turn; the server\'s watch keeps trying'); return names; }
|
|
79
79
|
const left = [];
|
|
80
80
|
for (const name of names) {
|
|
81
81
|
let r = await sh([multipass, 'start', name], MACHINE_MS);
|
|
@@ -83,7 +83,7 @@ export async function multipassTurn({ run, mode, inWindow, busy, state, save, lo
|
|
|
83
83
|
if (r.code !== 0) {
|
|
84
84
|
/* It died while they were started (25-11): rescued, then this one tried once more. */
|
|
85
85
|
const mute = (await sh([multipass, 'list', '--format', 'json'], 30_000)).code !== 0;
|
|
86
|
-
if (mute && await rescue(
|
|
86
|
+
if (mute && await rescue()) r = await sh([multipass, 'start', name], MACHINE_MS);
|
|
87
87
|
if (r.code !== 0) { left.push(name); log(`multipass: ${name} could not be started again: ${first(r)}`); }
|
|
88
88
|
}
|
|
89
89
|
}
|
|
@@ -92,9 +92,7 @@ export async function multipassTurn({ run, mode, inWindow, busy, state, save, lo
|
|
|
92
92
|
|
|
93
93
|
const pending = state().multipassRefresh?.machines ?? [];
|
|
94
94
|
if (pending.length) {
|
|
95
|
-
|
|
96
|
-
const lately = Date.parse(state().multipassRefresh?.triedAt ?? '');
|
|
97
|
-
const left = await back(pending, { updated: Number.isFinite(lately) && now() - lately < 86_400_000 });
|
|
95
|
+
const left = await back(pending);
|
|
98
96
|
save({ multipassRefresh: { ...state().multipassRefresh, machines: left } });
|
|
99
97
|
if (left.length) return `${left.length} machine(s) still to start again`;
|
|
100
98
|
log('multipass: the machines of the last update are running again');
|
|
@@ -128,7 +126,7 @@ export async function multipassTurn({ run, mode, inWindow, busy, state, save, lo
|
|
|
128
126
|
/* --ignore-running: a client of Multipass still open (a terminal, a command) would make snap refuse (seen on a real machine); its machine is asleep. */
|
|
129
127
|
const done = await sh(['snap', 'refresh', 'multipass', '--ignore-running'], REFRESH_MS);
|
|
130
128
|
log(done.code === 0 ? 'multipass: updated' : `multipass: its update failed: ${first(done)}`);
|
|
131
|
-
const left = await back(running
|
|
129
|
+
const left = await back(running);
|
|
132
130
|
save({ multipassRefresh: { ...state().multipassRefresh, machines: left } });
|
|
133
131
|
log(left.length ? `multipass: ${left.length} machine(s) to start again at the next turn` : 'multipass: its machines are running again');
|
|
134
132
|
return done.code === 0 ? 'updated' : 'update failed';
|
package/deploy/updater.mjs
CHANGED
|
@@ -409,8 +409,9 @@ export class Updater {
|
|
|
409
409
|
#o; #run; #fetch;
|
|
410
410
|
constructor({ code = PATHS.code, conf = PATHS.conf, stateDir = PATHS.stateDir, data = PATHS.data, hostTarget = PATHS.host, gitReadTarget = PATHS.gitRead, tunnelTarget = PATHS.tunnel, registry = REGISTRY, run = runCommand, fetcher = fetch, now = () => new Date(), log = (line) => console.log(line),
|
|
411
411
|
verifySignatures, restart, health, backup, restoreData, installPrivileged, ensureNode, serviceState, answers, restarts, mainPid, pidCwd, diagnose, dropIn = DROP_IN,
|
|
412
|
+
bootId = () => { try { return readFileSync('/proc/sys/kernel/random/boot_id', 'utf8').trim(); } catch { return ''; } },
|
|
412
413
|
clock = () => Date.now(), sleep = (ms) => new Promise((r) => setTimeout(r, ms)), minFreeMb = 1024, healthMs = 60_000, watchMs = 120_000, settleMs = 10_000, noticeMs = NOTICE_MS, releaseSettleMs = RELEASE_SETTLE_MS } = {}) {
|
|
413
|
-
this.#o = { code, conf, stateDir, data, hostTarget, gitReadTarget, tunnelTarget, registry: registry.replace(/\/$/, ''), now, log, minFreeMb, healthMs, watchMs, settleMs, noticeMs, releaseSettleMs, clock, sleep, dropIn };
|
|
414
|
+
this.#o = { code, conf, stateDir, data, hostTarget, gitReadTarget, tunnelTarget, registry: registry.replace(/\/$/, ''), now, log, bootId, minFreeMb, healthMs, watchMs, settleMs, noticeMs, releaseSettleMs, clock, sleep, dropIn };
|
|
414
415
|
this.#run = run; this.#fetch = fetcher;
|
|
415
416
|
this.verifySignatures = verifySignatures ?? ((dir) => this.#npm(['audit', 'signatures'], { cwd: dir, timeoutMs: 300_000 }));
|
|
416
417
|
this.restart = restart ?? (() => this.#restart());
|
|
@@ -668,15 +669,35 @@ export class Updater {
|
|
|
668
669
|
}
|
|
669
670
|
#dataFormat() { try { return JSON.parse(readFileSync(join(this.#o.data, 'data-format.json'), 'utf8')).format; } catch { return undefined; } }
|
|
670
671
|
|
|
672
|
+
/* Whether the lock is held by a process alive now -- of THIS start of the machine (25-11, on a test machine: frozen
|
|
673
|
+
in the middle of an update, started again; its lock and its "under way" stayed, and a number taken by another
|
|
674
|
+
process after the start would have looked alive for ever). */
|
|
675
|
+
#lockHeld() {
|
|
676
|
+
let text = '';
|
|
677
|
+
try { text = readFileSync(join(this.#o.stateDir, 'lock'), 'utf8').trim(); } catch { return false; }
|
|
678
|
+
const [pidText, boot] = text.split(/\s+/);
|
|
679
|
+
const pid = Number(pidText) || 0;
|
|
680
|
+
if (boot && boot !== this.#o.bootId()) return false;
|
|
681
|
+
let alive = false; try { if (pid) { process.kill(pid, 0); alive = true; } } catch (e) { alive = e.code === 'EPERM'; }
|
|
682
|
+
return alive;
|
|
683
|
+
}
|
|
684
|
+
/* An update or a return cut by the machine stopping: no longer said "under way"; written down as cut. */
|
|
685
|
+
clearCut() {
|
|
686
|
+
const running = this.#state().running;
|
|
687
|
+
if (!running || this.#lockHeld()) return false;
|
|
688
|
+
this.#o.log(`${running.action} ${running.version}: cut at "${running.step}" (the machine stopped): no longer under way`);
|
|
689
|
+
this.#history({ action: running.action === 'back' ? 'back' : 'update', to: running.version ?? null, result: 'failed', why: `cut at "${running.step}": the machine stopped in the middle; nothing was switched` });
|
|
690
|
+
return true;
|
|
691
|
+
}
|
|
671
692
|
#lock() {
|
|
672
693
|
mkdirSync(this.#o.stateDir, { recursive: true, mode: 0o755 });
|
|
673
694
|
const file = join(this.#o.stateDir, 'lock');
|
|
674
695
|
for (let i = 0; i < 2; i += 1) {
|
|
675
|
-
try { const fd = openSync(file, 'wx'); writeFileSync(fd,
|
|
696
|
+
try { const fd = openSync(file, 'wx'); writeFileSync(fd, `${process.pid} ${this.#o.bootId()}`); closeSync(fd); return () => rmSync(file, { force: true }); } catch (error) {
|
|
676
697
|
if (error.code !== 'EEXIST') throw error;
|
|
677
|
-
const pid = Number(readFileSync(file, 'utf8')) || 0;
|
|
698
|
+
const pid = Number(readFileSync(file, 'utf8').trim().split(/\s+/)[0]) || 0;
|
|
678
699
|
/* A lock left by a process that is gone (killed, the machine stopped) is taken over. */
|
|
679
|
-
|
|
700
|
+
const alive = this.#lockHeld();
|
|
680
701
|
if (!alive) this.#o.log(`a stale lock (process ${pid || '?'} is gone): taken over`);
|
|
681
702
|
if (alive) throw new Refused('an update or an installation is running already');
|
|
682
703
|
rmSync(file, { force: true });
|
|
@@ -890,6 +911,7 @@ export class Updater {
|
|
|
890
911
|
|
|
891
912
|
/* What the host program asked (a request file), or the timer's turn. */
|
|
892
913
|
async runOnce() {
|
|
914
|
+
this.clearCut();
|
|
893
915
|
const file = join(this.#o.stateDir, 'request');
|
|
894
916
|
let request = '';
|
|
895
917
|
try { request = readFileSync(file, 'utf8').trim(); rmSync(file, { force: true }); } catch { /* none */ }
|
|
@@ -1086,7 +1108,7 @@ async function main(argv) {
|
|
|
1086
1108
|
const u = new Updater({ log: (line) => console.error(line) });
|
|
1087
1109
|
const print = (x) => console.log(JSON.stringify(x, null, 2));
|
|
1088
1110
|
switch (verb) {
|
|
1089
|
-
case 'check': await u.check().catch(() => {}); return print(u.about());
|
|
1111
|
+
case 'check': u.clearCut(); await u.check().catch(() => {}); return print(u.about());
|
|
1090
1112
|
case 'status': return print(u.about());
|
|
1091
1113
|
case 'run': {
|
|
1092
1114
|
/* What this release sets up beside itself (the certificate timer), at its first turn: the
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.535-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.535-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|