clavarium 0.2.225-beta.1 → 0.2.226-beta.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/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +16 -1
- package/server/main.mjs +3 -1
- package/server/vm.mjs +6 -0
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.226-beta.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.226-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -1961,6 +1961,19 @@ export class Conversations {
|
|
|
1961
1961
|
/* The conversations whose machine should be running: built, not asleep. */
|
|
1962
1962
|
/* (Stopped by its owner: not running either, until somebody starts it.) */
|
|
1963
1963
|
awake() { return this.#store.all().filter((c) => c.phase === 'ready' && c.asleep !== true && c.stopped !== true).map((c) => c.name); }
|
|
1964
|
+
/* Every machine running, its disk trimmed (vm.mjs trim), one machine at a time, a shared one once. */
|
|
1965
|
+
async trimAll() {
|
|
1966
|
+
const seen = new Set();
|
|
1967
|
+
for (const name of this.awake()) {
|
|
1968
|
+
const vm = this.#vms.vmOf?.(name) ?? name;
|
|
1969
|
+
if (seen.has(vm)) continue;
|
|
1970
|
+
seen.add(vm);
|
|
1971
|
+
if ((await this.#vms.state(name).catch(() => undefined)) !== 'Running') continue;
|
|
1972
|
+
await this.#trim(name);
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
/* Before a stop or a sleep: what it erased given back first, never holding the stop up long. */
|
|
1976
|
+
async #trim(name, timeoutMs) { if (typeof this.#vms.trim !== 'function') return; await this.#vms.trim(name, timeoutMs).catch(() => undefined); }
|
|
1964
1977
|
/* Put to sleep, and nothing else: not one being built (02-11: a reset machine was taken for a sleeper and
|
|
1965
1978
|
suspended mid-build), not a failed one. */
|
|
1966
1979
|
/* (One woken the time a copy reads it -- #borrowed -- is not asleep then: its memory is never "reclaimed" under it.) */
|
|
@@ -2171,6 +2184,7 @@ export class Conversations {
|
|
|
2171
2184
|
this.#plan(name, act, ['suspend']);
|
|
2172
2185
|
this.drop(name);
|
|
2173
2186
|
act.ctl = new AbortController();
|
|
2187
|
+
await this.#trim(name, 60_000);
|
|
2174
2188
|
const r = await this.#vms.suspend(name, { signal: act.ctl.signal, onLine: (line) => this.#seen(name, act, line) });
|
|
2175
2189
|
if (r.aborted) result = { ok: false, preempted: true };
|
|
2176
2190
|
else {
|
|
@@ -2285,12 +2299,13 @@ export class Conversations {
|
|
|
2285
2299
|
has its tool, a screen or an action: then only this one's programs end, the others go on. */
|
|
2286
2300
|
async #stopUnlessShared(name) {
|
|
2287
2301
|
const shared = this.#store.get(name)?.sharedMachine;
|
|
2288
|
-
if (!shared) return this.#vms.stop(name);
|
|
2302
|
+
if (!shared) { await this.#trim(name, 60_000); return this.#vms.stop(name); }
|
|
2289
2303
|
for (const other of this.#store.all().filter((x) => x.name !== name && x.sharedMachine === shared)) {
|
|
2290
2304
|
if (this.#watching.has(other.name) || this.#acts.has(other.name) || this.#timers.has(other.name)) return this.#endShared(name);
|
|
2291
2305
|
const alive = await this.#vms.exec(other.name, ['tmux', '-L', SOCKET, 'has-session', '-t', `=${SESSION}`]).catch(() => ({ code: 1 }));
|
|
2292
2306
|
if (alive.code === 0) return this.#endShared(name);
|
|
2293
2307
|
}
|
|
2308
|
+
await this.#trim(name, 60_000);
|
|
2294
2309
|
return this.#vms.stop(name);
|
|
2295
2310
|
}
|
|
2296
2311
|
#endShared(name) { return this.#vms.execMachine(name, ['sudo', '-n', 'pkill', '-KILL', '-u', `c-${name}`], { timeoutMs: STEP_MS }).catch(() => undefined); }
|
package/server/main.mjs
CHANGED
|
@@ -788,6 +788,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
788
788
|
for (const name of all.awake()) { const now = await secrets.reconcile(name, delivered.get(name)).catch(() => null); if (now !== null) delivered.set(name, now); }
|
|
789
789
|
};
|
|
790
790
|
const secretsTimer = setInterval(() => { void secretsGuard().catch(() => {}); }, 60_000); secretsTimer.unref?.();
|
|
791
|
+
/* The machines' disks give back what was erased, every hour (conversations.trimAll, vm.mjs trim). */
|
|
792
|
+
const trimTimer = setInterval(() => { void all.trimAll().catch(() => {}); }, 60 * 60_000); trimTimer.unref?.();
|
|
791
793
|
/* The certificate the front serves, said in Settings (certificate.mjs). */
|
|
792
794
|
const certificate = new Certificate({ origin: publicOrigin, alerts });
|
|
793
795
|
/* All the machines to another disk, from Settings (machinesmove.mjs). */
|
|
@@ -924,7 +926,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
924
926
|
screen: await quick(screenNow(), 1500, null), catalogue: await quick(catalogue.providers().catch(() => []), 1500, []),
|
|
925
927
|
}) });
|
|
926
928
|
const { server, listening } = serve(port, all, folders, { gate, originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, rooms, machineList, features, desks: new Desks({ file: new JsonFile(`${dataDir}/desktops.json`, {}) }), apikeys, relayJoin: host.length ? new RelayJoin({ host: asHost }) : null, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
927
|
-
server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopNetworkWatch(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); clearInterval(stopSigninHelp); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
929
|
+
server.on('close', () => { closing = true; stopBinders(); stopTethers(); clearInterval(historyTimer); clearInterval(secretsTimer); clearInterval(trimTimer); history.save(); stopVmWatch(); stopShelf(); stopHealth(); stopNetworkWatch(); stopUpdates(); stopWatch(); clearInterval(mailTimer); clearInterval(restartTimer); clearInterval(expiryTimer); clearInterval(answerTimer); clearInterval(wakeTimer); clearInterval(docketTimer); clearInterval(stopSigninHelp); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
928
930
|
let closing = false;
|
|
929
931
|
boxes.attach(server, WebSocketServer);
|
|
930
932
|
browsers.attach(server, WebSocketServer); server.on('close', () => browsers.shutdown());
|
package/server/vm.mjs
CHANGED
|
@@ -79,6 +79,7 @@ export function runner(prefix) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
/* The verbs that change a machine: its state is asked again after them. */
|
|
82
|
+
export const TRIM_MS = 120_000;
|
|
82
83
|
const CHANGES = new Set(['launch', 'clone', 'start', 'stop', 'suspend', 'kill', 'halt', 'hardstop', 'delete', 'purge', 'set', 'rename', 'restore', 'snapshot', 'revive', 'reclaim']);
|
|
83
84
|
export const STATES_FRESH_MS = 3000;
|
|
84
85
|
/* The VM manager did not say what a machine is in: not an answer about the machine. */
|
|
@@ -141,6 +142,11 @@ export class Vms {
|
|
|
141
142
|
}
|
|
142
143
|
/* In a shared machine: its machine-wide work, as its admin user, never through a door (the door itself installed). */
|
|
143
144
|
execMachine(conversation, argv, options) { return this.run(['vm', 'exec', this.vmOf(conversation), '--', ...argv], options); }
|
|
145
|
+
/* ITS DISK GIVES BACK WHAT WAS ERASED (17-11): the system inside tells the disk which blocks are free
|
|
146
|
+
(fstrim; the VM manager's disks take it, discard=unmap), and the disk file on the host shrinks to what
|
|
147
|
+
is really used. Ubuntu does it once a week by itself; asked here every hour and before each stop or
|
|
148
|
+
sleep. A second one is quick: only what changed since is looked at. */
|
|
149
|
+
trim(conversation, timeoutMs = TRIM_MS) { return this.execMachine(conversation, ['sudo', '-n', 'fstrim', '--all'], { timeoutMs }); }
|
|
144
150
|
/* The host's list of who lives in a shared machine (vm share / unshare). */
|
|
145
151
|
share(conversation) { return this.run(['vm', 'share', this.vmOf(conversation), conversation]); }
|
|
146
152
|
unshare(conversation) { return this.run(['vm', 'unshare', this.vmOf(conversation), conversation]); }
|