clavarium 0.2.532-next.1 → 0.2.536-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/clavarium-host
CHANGED
|
@@ -963,11 +963,9 @@ case "$AREA $VERB" in
|
|
|
963
963
|
[ $# -le 1 ] || usage
|
|
964
964
|
if [ $# -eq 1 ]; then
|
|
965
965
|
[ "$1" = "hard" ] || refuse "vm revive [hard]"
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
sleep 2
|
|
970
|
-
run timeout 120 snap start multipass.multipassd
|
|
966
|
+
unstick="$CODE/current/app/deploy/multipass-unstick.sh"
|
|
967
|
+
if [ "$SAY" = "yes" ]; then echo "$unstick (daemon stopped, its old dnsmasq ended, failed starts reset, started)"; exit 0; fi
|
|
968
|
+
run timeout 300 bash "$unstick"
|
|
971
969
|
else
|
|
972
970
|
run timeout 170 snap restart multipass.multipassd
|
|
973
971
|
fi ;;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
1
2
|
/* MULTIPASS UPDATED IN CLAVARIUM'S OWN WINDOW (23-11, its owner's ask, after a morning on a real server: snap
|
|
2
3
|
* updated Multipass by itself at 06:08, every machine was left suspended, nothing could be reached).
|
|
3
4
|
*
|
|
@@ -16,6 +17,8 @@ const BACK_TRIES = 36;
|
|
|
16
17
|
const BACK_EVERY_MS = 5_000;
|
|
17
18
|
export const TRY_EVERY_MS = 20 * 3600_000;
|
|
18
19
|
/* In the data folder while it runs: the server's watch leaves Multipass alone (vmwatch.mjs, `paused`). */
|
|
20
|
+
/* Its daemon stopped, its old dnsmasq ended, systemd's failed starts reset, started (multipass-unstick.sh, 25-11). */
|
|
21
|
+
export const UNSTICK = fileURLToPath(new URL('multipass-unstick.sh', import.meta.url));
|
|
19
22
|
export const MULTIPASS_UPDATING = 'multipass-updating';
|
|
20
23
|
|
|
21
24
|
const first = (r) => String(r?.stderr || r?.stdout || '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) || `exit ${r?.code}`;
|
|
@@ -68,7 +71,7 @@ export async function multipassTurn({ run, mode, inWindow, busy, state, save, lo
|
|
|
68
71
|
for (const [what, argv] of steps) {
|
|
69
72
|
log(`multipass: it does not answer: ${what}`);
|
|
70
73
|
if (argv) await sh(argv, REFRESH_MS);
|
|
71
|
-
else
|
|
74
|
+
else await sh(['bash', UNSTICK], 300_000);
|
|
72
75
|
if (await answers()) { log(`multipass: it answers again (${what})`); return true; }
|
|
73
76
|
}
|
|
74
77
|
return false;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
# MULTIPASS STOPPED AND STARTED FOR SURE (25-11, on a real server: after its update its daemon restarted, but its
|
|
3
|
+
# old dnsmasq -- the small server giving its machines their addresses -- stayed alive, still holding port 53; each new
|
|
4
|
+
# daemon died starting its own ("Address already in use"), systemd gave up ("Start request repeated too quickly"),
|
|
5
|
+
# and only a restart of the whole server freed it). Its daemon stopped; what stays of its dnsmasq in its control
|
|
6
|
+
# group ended; systemd's count of failed starts reset; started.
|
|
7
|
+
# Its machines left running by a daemon that died (qemu in its group, 25-11 on test-c: the new daemon cannot take
|
|
8
|
+
# them back -- "Failed to get shared write lock" on their disks -- and stays mute) are stopped too, step by step as
|
|
9
|
+
# a forced stop is (the host program's vm halt): asked to shut down from inside (with the VM manager's own key, a
|
|
10
|
+
# minute), then asked to end (10 s), then ended. Each step said; the server's watch then starts again those that ran.
|
|
11
|
+
# Run as root, by the host program (vm revive hard) and the updater (deploy/multipass-refresh.mjs).
|
|
12
|
+
set -u
|
|
13
|
+
UNIT=snap.multipass.multipassd.service
|
|
14
|
+
# Where the VM manager keeps its data (moved to another disk: its MULTIPASS_STORAGE), for its leases and its key.
|
|
15
|
+
DATA="/var/snap/multipass/common/data/multipassd"
|
|
16
|
+
MOVED_TO="$(sed -n 's/^Environment=MULTIPASS_STORAGE=\(\/[A-Za-z0-9/._-]*\)$/\1/p' /etc/systemd/system/$UNIT.d/override.conf 2>/dev/null | head -1)"
|
|
17
|
+
[ -n "$MOVED_TO" ] && [ -d "$MOVED_TO/data" ] && DATA="$MOVED_TO/data"
|
|
18
|
+
gone() { ! kill -0 "$1" 2>/dev/null; }
|
|
19
|
+
# A machine whose daemon died: shut down from inside, then asked to end, then ended.
|
|
20
|
+
halt_orphan() {
|
|
21
|
+
local pid="$1" name="$2" ip i
|
|
22
|
+
ip="$(awk -v n="$name" '$4 == n {print $3}' "$DATA/network/dnsmasq.leases" 2>/dev/null | tail -1)"
|
|
23
|
+
if [ -n "$ip" ] && [ -r "$DATA/ssh-keys/id_rsa" ] && timeout 20 ssh -i "$DATA/ssh-keys/id_rsa" -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 "ubuntu@$ip" sudo shutdown -h now >/dev/null 2>&1; then
|
|
24
|
+
# Its system shuts down (about 20 s on a test machine); its qemu then waits, paused (Multipass starts it
|
|
25
|
+
# with -no-shutdown): ended once its system is down.
|
|
26
|
+
for i in $(seq 1 45); do gone "$pid" && break; ping -c 1 -W 1 "$ip" >/dev/null 2>&1 || { [ "$i" -ge 5 ] && break; }; sleep 1; done
|
|
27
|
+
gone "$pid" || sleep 8 # its network goes before its disks are done
|
|
28
|
+
kill -TERM "$pid" 2>/dev/null || true
|
|
29
|
+
for i in $(seq 1 10); do gone "$pid" && break; sleep 1; done
|
|
30
|
+
gone "$pid" || kill -KILL "$pid" 2>/dev/null || true
|
|
31
|
+
echo " $name: shut down from inside"; return
|
|
32
|
+
fi
|
|
33
|
+
kill -TERM "$pid" 2>/dev/null || true
|
|
34
|
+
for i in $(seq 1 10); do gone "$pid" && { echo " $name: asked to end"; return; }; sleep 1; done
|
|
35
|
+
kill -KILL "$pid" 2>/dev/null || true
|
|
36
|
+
echo " $name: ended"
|
|
37
|
+
}
|
|
38
|
+
timeout 120 snap stop multipass.multipassd >/dev/null 2>&1 || true
|
|
39
|
+
for procs in "/sys/fs/cgroup/system.slice/$UNIT/cgroup.procs" "/sys/fs/cgroup/systemd/system.slice/$UNIT/cgroup.procs"; do
|
|
40
|
+
[ -r "$procs" ] || continue
|
|
41
|
+
for pid in $(cat "$procs" 2>/dev/null); do
|
|
42
|
+
comm="$(cat "/proc/$pid/comm" 2>/dev/null)"
|
|
43
|
+
case "$comm" in
|
|
44
|
+
dnsmasq) echo "its old dnsmasq ended ($pid)"; kill -KILL "$pid" 2>/dev/null || true ;;
|
|
45
|
+
qemu-system-*) name="$(tr '\0' ' ' < "/proc/$pid/cmdline" 2>/dev/null | grep -o 'instances/[a-z0-9-]*' | head -1 | cut -d/ -f2)"
|
|
46
|
+
echo "a machine left by the dead daemon, stopped: ${name:-?} ($pid)"; halt_orphan "$pid" "${name:-?}" ;;
|
|
47
|
+
esac
|
|
48
|
+
done
|
|
49
|
+
done
|
|
50
|
+
pkill -KILL -x multipassd 2>/dev/null || true
|
|
51
|
+
systemctl reset-failed "$UNIT" 2>/dev/null || true
|
|
52
|
+
sleep 2
|
|
53
|
+
timeout 120 snap start multipass.multipassd
|
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.536-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.536-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|