clavarium 0.2.191-beta.1 → 0.2.192-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/deploy/clavarium-host +10 -4
- package/npm-shrinkwrap.json +6 -6
- package/package.json +2 -2
- package/server/api.mjs +25 -6
- package/server/capacity.mjs +26 -18
- package/server/conversations.mjs +31 -5
- package/server/machinelist.mjs +58 -0
- package/server/main.mjs +23 -7
- package/server/settingswords.mjs +14 -1
- package/server/talk.mjs +9 -0
- package/server/vm.mjs +7 -0
- package/server/vmwatch.mjs +82 -23
- package/server/watchdog.mjs +102 -0
- package/web/app.js +125 -3
- package/web/index.html +25 -2
- package/web/style.css +13 -0
package/deploy/clavarium-host
CHANGED
|
@@ -945,12 +945,15 @@ case "$AREA $VERB" in
|
|
|
945
945
|
run "$MULTIPASS" exec "$vm" -- "$@" ;;
|
|
946
946
|
"vm ping")
|
|
947
947
|
# Does the VM manager answer at all? Asked now and then by the server
|
|
948
|
-
# (vmwatch.mjs); bounded, so that a VM manager that hangs is an answer
|
|
948
|
+
# (vmwatch.mjs); bounded, so that a VM manager that hangs is an answer:
|
|
949
|
+
# mute for 30 s is mute.
|
|
949
950
|
[ $# -eq 0 ] || usage
|
|
950
|
-
run timeout
|
|
951
|
+
run timeout 30 "$MULTIPASS" list --format csv ;;
|
|
951
952
|
"vm revive")
|
|
952
|
-
# The VM manager has not answered for minutes: its daemon restarted
|
|
953
|
-
#
|
|
953
|
+
# The VM manager has not answered for minutes: its daemon restarted
|
|
954
|
+
# (every machine is suspended and resumed). Asked by the server as its
|
|
955
|
+
# owner chose (vmwatch.mjs: at night, always, or never by itself), at
|
|
956
|
+
# most once in hours; or by its owner, confirmed in Settings, Machines.
|
|
954
957
|
[ $# -eq 0 ] || usage
|
|
955
958
|
run timeout 170 snap restart multipass.multipassd ;;
|
|
956
959
|
"vm states")
|
|
@@ -1237,6 +1240,7 @@ OOMScoreAdjust=-900'
|
|
|
1237
1240
|
# place <machines|data|folders> <device> <size MB> <free MB>
|
|
1238
1241
|
# memory <total MB> <available MB>
|
|
1239
1242
|
# machine <one of our VMs> <resident MB>
|
|
1243
|
+
# machineage <one of our VMs> <seconds its qemu has run>
|
|
1240
1244
|
# cpu <total ticks> <idle ticks> <cores> (for the curves: a difference of two looks)
|
|
1241
1245
|
# machinecpu <one of our VMs> <ticks it used>
|
|
1242
1246
|
[ $# -eq 0 ] || usage
|
|
@@ -1255,6 +1259,8 @@ OOMScoreAdjust=-900'
|
|
|
1255
1259
|
[ -n "$vm" ] || continue
|
|
1256
1260
|
rss="$(awk '/^VmRSS:/{print int($2/1024)}' "/proc/$pid/status" 2>/dev/null)" || rss=""
|
|
1257
1261
|
[ -n "$rss" ] && printf 'machine %s %s\n' "$vm" "$rss"
|
|
1262
|
+
age="$(ps -o etimes= -p "$pid" 2>/dev/null | tr -d ' ')" || age=""
|
|
1263
|
+
case "$age" in ''|*[!0-9]*) ;; *) printf 'machineage %s %s\n' "$vm" "$age" ;; esac
|
|
1258
1264
|
ticks="$(awk '{print $14 + $15}' "/proc/$pid/stat" 2>/dev/null)" || ticks=""
|
|
1259
1265
|
[ -n "$ticks" ] && printf 'machinecpu %s %s\n' "$vm" "$ticks"
|
|
1260
1266
|
done
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.192-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.192-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
|
13
13
|
"@xterm/xterm": "^6.0.0",
|
|
14
14
|
"clavarium-binder": "0.1.62-next.1",
|
|
15
15
|
"clavarium-docket": "0.1.2-next.2",
|
|
16
|
-
"clavarium-parley": "0.17.
|
|
16
|
+
"clavarium-parley": "0.17.91-next.1",
|
|
17
17
|
"clavarium-tether": "0.1.0-next.60",
|
|
18
18
|
"mammoth": "1.13.0",
|
|
19
19
|
"mermaid": "11.17.2",
|
|
@@ -787,9 +787,9 @@
|
|
|
787
787
|
}
|
|
788
788
|
},
|
|
789
789
|
"node_modules/clavarium-parley": {
|
|
790
|
-
"version": "0.17.
|
|
791
|
-
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.
|
|
792
|
-
"integrity": "sha512-
|
|
790
|
+
"version": "0.17.91-next.1",
|
|
791
|
+
"resolved": "https://registry.npmjs.org/clavarium-parley/-/clavarium-parley-0.17.91-next.1.tgz",
|
|
792
|
+
"integrity": "sha512-RLgCjziHY+0JNah9mYVTZruVjxqePKSLy8OHOTr2ZioaFx0i0EvwaObzw65ufa3KZZBNEM/5L0rxdAZh2FEAmg==",
|
|
793
793
|
"license": "MIT",
|
|
794
794
|
"bin": {
|
|
795
795
|
"parley": "bin/parley.mjs",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.192-beta.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@xterm/xterm": "^6.0.0",
|
|
48
48
|
"clavarium-binder": "0.1.62-next.1",
|
|
49
49
|
"clavarium-docket": "0.1.2-next.2",
|
|
50
|
-
"clavarium-parley": "0.17.
|
|
50
|
+
"clavarium-parley": "0.17.91-next.1",
|
|
51
51
|
"clavarium-tether": "0.1.0-next.60",
|
|
52
52
|
"mammoth": "1.13.0",
|
|
53
53
|
"mermaid": "11.17.2",
|
package/server/api.mjs
CHANGED
|
@@ -12,7 +12,8 @@
|
|
|
12
12
|
* one at a time (force takes the place of any other; force-now: the next
|
|
13
13
|
* step of the one running) -> its state (202), as below
|
|
14
14
|
* POST /api/conversations/<name>/machine {escalate: true|false}: a stop that hangs goes on to its qemu by itself (default) or asks
|
|
15
|
-
*
|
|
15
|
+
* POST /api/conversations/<name>/machine {watchdog: {on?, delayMin?}}: mute or full that long, its machine is forced off and started, once
|
|
16
|
+
* GET /api/conversations/<name>/machine {action: {kind, since, until, steps: [{id, state, since, s}]} | null, report, limits, escalate, watchdog}
|
|
16
17
|
* POST /api/conversations/<name>/machine/cancel the size kept for its wake, given up
|
|
17
18
|
* GET /api/conversations/<name>/health what was last seen of its machine
|
|
18
19
|
* POST /api/conversations/<name>/health look now (never wakes a machine)
|
|
@@ -28,6 +29,7 @@
|
|
|
28
29
|
* POST /api/conversations/<name>/terminal/repair its terminal does not come though its machine runs: repaired
|
|
29
30
|
* POST /api/conversations/<name>/talk {text, answers?, files?, via?}: written in its chat; files from .../talk/file; via 'voice': dictated
|
|
30
31
|
* POST /api/conversations/<name>/talk/react {to, reaction}: the owner's reaction to a message of the tool (null: taken back)
|
|
32
|
+
* POST /api/conversations/<name>/talk/pin {to, on}: the owner pins a message of the chat (on: false unpins); 5 at most
|
|
31
33
|
* POST /api/conversations/<name>/chat-name {name}: the name the chat gives its tool ('' : the neutral word of the dictionary)
|
|
32
34
|
* POST /api/conversations/<name>/tasks-binder {binder}: the binder shown beside its chat ('' automatic, '-' none, else an id)
|
|
33
35
|
* POST /api/conversations/<name>/voice-mark {on}: what is dictated into its terminal starts with a microphone sign (AI tools only)
|
|
@@ -123,7 +125,11 @@
|
|
|
123
125
|
* GET /api/history?of=server|<name>&span=1h|24h|7d the curves of memory, CPU and disk (and the reserve, for the server)
|
|
124
126
|
* GET /api/history/all?span=1h|24h|7d Settings, Usage: the server and every machine (asleep too) on one time axis,
|
|
125
127
|
* in GB and cores: {t, capacity, server, itself, machines: [{name, alloc, asleep, ...}]}
|
|
126
|
-
* POST /api/server/
|
|
128
|
+
* POST /api/server/pressure {way: force|sleep|alert}: memory short, the machine that takes the most forced off (default), put to sleep, or only said
|
|
129
|
+
* GET /api/server/machines {machines: [{name, state, rssMb, sizeMb, since, action}], manager: {ok, downSince, mode, asked, last, reviving}, pressure}
|
|
130
|
+
* POST /api/server/machines/<name>/force its machine forced off, as from its conversation (202)
|
|
131
|
+
* POST /api/server/vm-manager {mode: night|always|ask}: when it hangs, restarted by itself at night (default), always, or never
|
|
132
|
+
* POST /api/server/vm-manager/restart {confirm: true}: restarted now; every machine is suspended and resumed
|
|
127
133
|
* GET /api/server/logs?source=&span= what the server's programs said POST /api/server/restart POST /api/server/reboot (the whole server)
|
|
128
134
|
* GET /api/operators who may sign in POST /api/operators {email} -> {email, password}: shown once
|
|
129
135
|
* POST /api/operators/<email>/password -> {email, password} POST /api/operators/<email>/disable|enable|remove
|
|
@@ -196,7 +202,7 @@ function readBody(request, max = BODY_MAX) {
|
|
|
196
202
|
/* This run of the server: a page's count of binder changes is of one run, and starts again with the next. */
|
|
197
203
|
const BOOT = Math.random().toString(36).slice(2, 10);
|
|
198
204
|
|
|
199
|
-
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue, rooms) {
|
|
205
|
+
export async function handleApi(request, response, conversations, headers, resources, originOk = sameOrigin, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue, rooms, machineList) {
|
|
200
206
|
const { pathname } = new URL(request.url ?? '/', 'http://local');
|
|
201
207
|
if (!pathname.startsWith('/api/')) return false;
|
|
202
208
|
let send = (status, body) => {
|
|
@@ -430,6 +436,8 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
430
436
|
if (pathname === '/api/certificate' && certificate) return send(200, await certificate.about({ fresh: query.get('fresh') === '1' })), true;
|
|
431
437
|
/* This server's disk and memory (capacity.mjs): everything for Settings; only whether it is high for the list. */
|
|
432
438
|
if (pathname === '/api/server' && capacity) return send(200, await capacity.about()), true;
|
|
439
|
+
/* Settings, Machines: each machine, the VM manager, this server's two choices (machinelist.mjs). */
|
|
440
|
+
if (pathname === '/api/server/machines' && machineList) return send(200, await machineList.list()), true;
|
|
433
441
|
if (pathname === '/api/server/brief' && capacity) return send(200, { ...(await capacity.brief()), machines: platform?.machines ?? true }), true;
|
|
434
442
|
if (pathname === '/api/alerts' && alerts) return send(200, alerts.about()), true;
|
|
435
443
|
if (pathname === '/api/flows' && setup) return send(200, setup.graph()), true;
|
|
@@ -591,8 +599,16 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
591
599
|
if (pathname === '/api/updates/settings' && updates) return send(200, await updates.settings({ mode: body.mode, channel: body.channel, window: body.window })), true;
|
|
592
600
|
if (pathname === '/api/updates/apply' && updates) return send(202, await updates.apply(body.version)), true;
|
|
593
601
|
if (pathname === '/api/updates/back' && updates) return send(202, await updates.back(body.version)), true;
|
|
594
|
-
/*
|
|
595
|
-
if (pathname === '/api/server/
|
|
602
|
+
/* Memory short: the machine that takes the most forced off (default), put to sleep, or only said. */
|
|
603
|
+
if (pathname === '/api/server/pressure' && capacity) { capacity.setPressureWay(body.way); return send(200, await capacity.about()), true; }
|
|
604
|
+
/* Settings, Machines: Force stop from the list; the VM manager restarted (confirmed: every machine is resumed); what is done when it hangs. */
|
|
605
|
+
const forcedOf = /^\/api\/server\/machines\/([^/]+)\/force$/.exec(pathname);
|
|
606
|
+
if (forcedOf && machineList) return send(202, await machineList.force(decodeURIComponent(forcedOf[1]))), true;
|
|
607
|
+
if (pathname === '/api/server/vm-manager/restart' && machineList) {
|
|
608
|
+
if (body?.confirm !== true) throw new Refusal(400, 'Restarting the machine manager resumes every machine: confirm it.');
|
|
609
|
+
return send(200, await machineList.revive()), true;
|
|
610
|
+
}
|
|
611
|
+
if (pathname === '/api/server/vm-manager' && machineList) return send(200, await machineList.setManagerMode(body?.mode)), true;
|
|
596
612
|
if (pathname === '/api/server/reserve' && capacity) { capacity.setReserve({ diskMb: body.diskMb, diskPercent: body.diskPercent, memoryMb: body.memoryMb, memoryPercent: body.memoryPercent }); return send(200, await capacity.about()), true; }
|
|
597
613
|
if (pathname === '/api/git-hosts/forget' && gitAccess) return send(200, gitAccess.forgetHost(body.host)), true;
|
|
598
614
|
const unkeyed = /^\/api\/git-keys\/([a-z0-9-]{1,32})\/remove$/.exec(pathname);
|
|
@@ -777,12 +793,13 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
777
793
|
}
|
|
778
794
|
return send(200, { asset, rights, given }), true;
|
|
779
795
|
}
|
|
780
|
-
const talking = /^\/api\/conversations\/([^/]+)\/talk(\/invite|\/remind|\/react)?$/.exec(pathname);
|
|
796
|
+
const talking = /^\/api\/conversations\/([^/]+)\/talk(\/invite|\/remind|\/react|\/pin)?$/.exec(pathname);
|
|
781
797
|
if (talking && talk) {
|
|
782
798
|
const conversation = decodeURIComponent(talking[1]);
|
|
783
799
|
if (talking[2] === '/invite') return send(200, await talk.invite(conversation, typeof body.lang === 'string' ? body.lang : 'en')), true;
|
|
784
800
|
if (talking[2] === '/remind') return send(200, await talk.remind(conversation, { urgent: body?.urgent === true })), true;
|
|
785
801
|
if (talking[2] === '/react') return send(200, await talk.react(conversation, body.to, body.reaction ?? null)), true;
|
|
802
|
+
if (talking[2] === '/pin') return send(200, await talk.pin(conversation, body.to, body.on !== false)), true;
|
|
786
803
|
if (typeof body.on === 'boolean') { const now = await talk.set(conversation, body.on); retell(conversation); return send(200, now), true; }
|
|
787
804
|
/* What the chat may add to an answer: the choices ticked, the answers of a group, the zone of a picture it is about (Parley checks each). */
|
|
788
805
|
return send(201, await talk.say(conversation, body.text, body.answers, body.files, body.via, { picked: body.picked, replies: body.replies, about: body.about })), true;
|
|
@@ -924,6 +941,8 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
924
941
|
/* One action on its machine, or the owner's choice for its way down (conversations.mjs, machineAction). */
|
|
925
942
|
if (typeof body?.action === 'string') return send(202, await conversations.machineAction(conversation, body.action)), true;
|
|
926
943
|
if (typeof body?.escalate === 'boolean') return send(200, conversations.setStopEscalate(conversation, body.escalate)), true;
|
|
944
|
+
/* Its watchdog (watchdog.mjs): on or off, and how long it waits. */
|
|
945
|
+
if (body?.watchdog && typeof body.watchdog === 'object') return send(200, conversations.setWatchdog(conversation, { on: typeof body.watchdog.on === 'boolean' ? body.watchdog.on : undefined, delayMin: body.watchdog.delayMin })), true;
|
|
927
946
|
const resized = await conversations.resize(conversation, { memoryMb: body.memoryMb, diskGb: body.diskGb, cpus: body.cpus });
|
|
928
947
|
/* Asleep, nothing was started: the choice is only kept, for its wake. */
|
|
929
948
|
return send(resized.phase === 'restarting' ? 202 : 200, resized), true;
|
package/server/capacity.mjs
CHANGED
|
@@ -39,6 +39,8 @@ import { Refusal, DISK_GB } from './conversations.mjs';
|
|
|
39
39
|
import { MIN_FREE_MB } from './shelf.mjs';
|
|
40
40
|
|
|
41
41
|
export const RESERVE_DISK_MB = 5 * 1024;
|
|
42
|
+
/* Short of memory: what is done to the machine that takes the most (pressureWay). */
|
|
43
|
+
export const PRESSURE_WAYS = Object.freeze(['force', 'sleep', 'alert']);
|
|
42
44
|
export const RESERVE_MEMORY_MB = 1024;
|
|
43
45
|
export const RESERVE_DISK_PERCENT = 5;
|
|
44
46
|
export const RESERVE_MEMORY_PERCENT = 5;
|
|
@@ -69,12 +71,13 @@ const whole = (text) => (/^\d{1,12}$/.test(String(text)) ? Number(text) : undefi
|
|
|
69
71
|
|
|
70
72
|
/* What "server room" printed, as facts; any other line is left out. */
|
|
71
73
|
export function readRoom(text) {
|
|
72
|
-
const facts = { places: [], memory: null, machines: [], cpu: null, machineCpu: {} };
|
|
74
|
+
const facts = { places: [], memory: null, machines: [], cpu: null, machineCpu: {}, machineAge: {} };
|
|
73
75
|
for (const line of String(text ?? '').slice(0, 64 * 1024).split('\n').slice(0, 500)) {
|
|
74
76
|
const p = line.trim().split(' ');
|
|
75
77
|
if (p[0] === 'place' && p.length === 5 && PLACES.includes(p[1]) && [2, 3, 4].every((i) => whole(p[i]) !== undefined) && !facts.places.some((x) => x.what === p[1])) facts.places.push({ what: p[1], device: whole(p[2]), sizeMb: whole(p[3]), freeMb: whole(p[4]) });
|
|
76
78
|
if (p[0] === 'memory' && p.length === 3 && whole(p[1]) > 0 && whole(p[2]) !== undefined) facts.memory = { totalMb: whole(p[1]), availableMb: whole(p[2]) };
|
|
77
79
|
if (p[0] === 'cpu' && p.length === 4 && [1, 2, 3].every((i) => whole(p[i]) !== undefined)) facts.cpu = { ticks: whole(p[1]), idle: whole(p[2]), cores: whole(p[3]) };
|
|
80
|
+
if (p[0] === 'machineage' && p.length === 3 && VM.test(p[1]) && whole(p[2]) !== undefined) facts.machineAge[p[1]] = whole(p[2]);
|
|
78
81
|
if (p[0] === 'machinecpu' && p.length === 3 && VM.test(p[1]) && whole(p[2]) !== undefined) facts.machineCpu[p[1]] = whole(p[2]);
|
|
79
82
|
if (p[0] === 'machine' && p.length === 3 && VM.test(p[1]) && whole(p[2]) !== undefined && !facts.machines.some((m) => m.vm === p[1])) facts.machines.push({ vm: p[1], rssMb: whole(p[2]) });
|
|
80
83
|
}
|
|
@@ -135,14 +138,15 @@ export class Capacity {
|
|
|
135
138
|
return this.reserve();
|
|
136
139
|
}
|
|
137
140
|
|
|
138
|
-
/*
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
141
|
+
/* SHORT OF MEMORY (under the reserve), WHAT IS DONE to the running machine that takes the most, as
|
|
142
|
+
its owner chose (09-11): forced off ('force', the default: quick, and sure for this server), put
|
|
143
|
+
to sleep ('sleep': keeps its state, but writes all its memory to disk at the worst time; a frozen
|
|
144
|
+
one, which cannot be put to sleep, is forced off), or nothing but the alert ('alert'). */
|
|
145
|
+
pressureWay() { const w = this.#store.get('pressure')?.way; return PRESSURE_WAYS.includes(w) ? w : 'force'; }
|
|
146
|
+
setPressureWay(way) {
|
|
147
|
+
if (!PRESSURE_WAYS.includes(way)) throw new Refusal(400, 'Short of memory, a machine is forced off (force), put to sleep (sleep), or only said (alert).');
|
|
148
|
+
this.#store.put({ name: 'pressure', way });
|
|
149
|
+
return this.pressureWay();
|
|
146
150
|
}
|
|
147
151
|
|
|
148
152
|
/* What is free now. `fresh`: asked again whatever the cache says. */
|
|
@@ -178,7 +182,7 @@ export class Capacity {
|
|
|
178
182
|
const records = new Map(all.map((c) => [`clv-${c.name}`, c]));
|
|
179
183
|
const machines = room.machines.map((m) => {
|
|
180
184
|
const c = records.get(m.vm);
|
|
181
|
-
return { name: c ? c.name : null, shelf: m.vm.startsWith('clvshelf-'), rssMb: m.rssMb, sizeMb: c?.memoryMb ?? null };
|
|
185
|
+
return { name: c ? c.name : null, shelf: m.vm.startsWith('clvshelf-'), rssMb: m.rssMb, sizeMb: c?.memoryMb ?? null, ...(room.machineAge?.[m.vm] !== undefined ? { ageS: room.machineAge[m.vm] } : {}) };
|
|
182
186
|
});
|
|
183
187
|
/* What the system says is available: the machines' own use is in it already. */
|
|
184
188
|
const memory = room.memory ? { totalMb: room.memory.totalMb, freeMb: room.memory.availableMb, usedPercent: percent(room.memory.totalMb - room.memory.availableMb, room.memory.totalMb) } : null;
|
|
@@ -225,7 +229,7 @@ export class Capacity {
|
|
|
225
229
|
machines: { disksMb: Object.values(u.machines).reduce((a, b) => a + b, 0), each: Object.entries(u.machines).map(([name, mb]) => ({ name, mb })).sort((a, b) => b.mb - a.mb), shelfMb: u.shelf ?? null, imagesMb: u.images ?? null, othersMb: u.others ?? null },
|
|
226
230
|
at: new Date(this.#usageAt).toISOString(),
|
|
227
231
|
} : null;
|
|
228
|
-
return { known: Boolean(figures), reserve: { diskMb: this.reserve().diskMb, memoryMb: this.reserve().memoryMb }, settings: this.reserve(),
|
|
232
|
+
return { known: Boolean(figures), reserve: { diskMb: this.reserve().diskMb, memoryMb: this.reserve().memoryMb }, settings: this.reserve(), pressure: this.pressureWay(), ...(figures ?? {}), usage, measuring: Boolean(this.#measuring) };
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
/* For the list: only whether it is high, and how much. Cheap: what is
|
|
@@ -295,17 +299,21 @@ export class Capacity {
|
|
|
295
299
|
const running = f.machines.filter((m) => m.name && awake.has(m.name));
|
|
296
300
|
const takes = (m) => (what === 'disk' ? this.#usage?.machines?.[m.name] ?? -1 : m.rssMb);
|
|
297
301
|
const most = running.sort((a, b) => takes(b) - takes(a) || b.rssMb - a.rssMb)[0] ?? null;
|
|
298
|
-
let slept = null; let frozen = null; let forced = null;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
if (
|
|
302
|
+
let slept = null; let frozen = null; let forced = null; let held = null;
|
|
303
|
+
/* Memory: as its owner chose (pressureWay). Disk: put to sleep, as before. */
|
|
304
|
+
const way = what === 'memory' ? this.pressureWay() : 'sleep';
|
|
305
|
+
if (most && way === 'alert') held = most.name;
|
|
306
|
+
if (most && way === 'force' && this.#force) forced = await Promise.resolve(this.#force(most.name)).then((ok) => (ok === false ? null : most.name), () => null);
|
|
307
|
+
if (most && way === 'sleep' && this.#sleep) slept = await Promise.resolve(this.#sleep(most.name)).then(() => most.name, (error) => { if (/frozen/.test(String(error?.message ?? ''))) frozen = most.name; return null; });
|
|
308
|
+
/* Frozen: never suspended (it would hang the VM manager); forced off instead. */
|
|
309
|
+
if (frozen && this.#force) forced = await Promise.resolve(this.#force(frozen)).then((ok) => (ok === false ? null : frozen), () => null);
|
|
302
310
|
const figures = `${gb(free)} free, ${gb(f.reserve[`${what}Mb`])} kept in reserve`;
|
|
303
|
-
const did = slept ? ` ${slept} was put to sleep.` : forced ? ` ${forced} was frozen
|
|
311
|
+
const did = slept ? ` ${slept} was put to sleep.` : forced ? ` ${forced} was forced off${frozen ? ' (frozen)' : ''}.` : frozen ? ` ${frozen} takes the most but is frozen: Force stop frees it.` : held ? ` ${held} takes the most: nothing was done, as you chose.` : '';
|
|
304
312
|
this.#alert?.({ title: `This server is short of ${what}`, body: `${figures}.${did}`, url: '/?open=settings&at=resources' });
|
|
305
313
|
if (slept) this.#say?.(slept, `This server ran short of ${what} (${figures}). This machine took the most, so it was put to sleep. Wake it once there is room again.`);
|
|
306
|
-
if (forced) this.#say?.(forced, `This server ran short of ${what} (${figures}). This machine took the most and was frozen
|
|
314
|
+
if (forced) this.#say?.(forced, `This server ran short of ${what} (${figures}). This machine took the most${frozen ? ' and was frozen' : ''}, so it was forced off, as after a power cut. Start it again once there is room.`);
|
|
307
315
|
else if (frozen) this.#say?.(frozen, `This server ran short of ${what} (${figures}). This machine took the most but is frozen: it could not be put to sleep. Force stop frees it.`);
|
|
308
|
-
done.push({ what, slept, ...(frozen ? { frozen,
|
|
316
|
+
done.push({ what, way, slept, ...(forced ? { forced } : {}), ...(frozen ? { frozen } : {}), ...(held ? { held } : {}) });
|
|
309
317
|
}
|
|
310
318
|
return done;
|
|
311
319
|
}
|
package/server/conversations.mjs
CHANGED
|
@@ -67,6 +67,11 @@ const NEXT = Object.freeze({ polite: 'force', force: 'term', term: 'kill' });
|
|
|
67
67
|
/* Each step in words, for the journal and the chat (the page has its own, web/app.js). */
|
|
68
68
|
const STEP_WORDS = Object.freeze({ polite: 'polite stop', force: 'forced stop', term: 'SIGTERM', kill: 'SIGKILL', check: 'check', start: 'start', suspend: 'sleep', resleep: 'wake and sleep again', stop: 'clean stop' });
|
|
69
69
|
const KIND_DOING = Object.freeze({ start: 'starting', stop: 'stopping', restart: 'restarting', sleep: 'going to sleep', force: 'being forced off', resize: 'being resized' });
|
|
70
|
+
/* THE WATCHDOG of a machine (watchdog.mjs), as its owner set it: on, with how long it may stay mute or
|
|
71
|
+
full before it is forced off and started again. The defaults, and what may be chosen (minutes). */
|
|
72
|
+
export const WATCHDOG_DELAY_MIN = 60;
|
|
73
|
+
export const WATCHDOG_MIN = 10;
|
|
74
|
+
export const WATCHDOG_MAX = 24 * 60;
|
|
70
75
|
const KIND_WORDS = Object.freeze({ start: ['Started', 'Not started'], stop: ['Stopped', 'Not stopped'], restart: ['Restarted', 'Not restarted'], sleep: ['Asleep', 'Not asleep'], force: ['Stopped by force', 'Not stopped by force'], resize: ['Resized', 'Not resized'] });
|
|
71
76
|
|
|
72
77
|
export class Refusal extends Error {
|
|
@@ -1389,12 +1394,14 @@ export class Conversations {
|
|
|
1389
1394
|
to its next step). Answers at once with what the page reads (machineState); the action goes
|
|
1390
1395
|
on, its steps on the record (`machine`), its report kept after it (`machineReport`), said in
|
|
1391
1396
|
the journal and in its chat. `this.acted`: its end, for whoever waits for it. */
|
|
1392
|
-
|
|
1397
|
+
/* `wait`: resolves with its report instead, once it is done (the watchdog, the memory watch, the
|
|
1398
|
+
server's list: callers that act on it, so that no other action's end is taken for theirs). */
|
|
1399
|
+
async machineAction(name, kind, { wait = false } = {}) {
|
|
1393
1400
|
const c = this.#store.get(name);
|
|
1394
1401
|
if (!c) throw new Refusal(404, 'No such conversation.');
|
|
1395
1402
|
if (kind === 'force-now') return this.#forceNow(name);
|
|
1396
1403
|
if (!MACHINE_KINDS.includes(kind)) throw new Refusal(400, 'Not an action of a machine.');
|
|
1397
|
-
if (kind === 'restart') { await this.restart(name);
|
|
1404
|
+
if (kind === 'restart') { await this.restart(name); const done = this.restarted; this.acted = done; return wait ? done : this.machineState(name); }
|
|
1398
1405
|
const running = this.#acts.get(name);
|
|
1399
1406
|
if (kind !== 'force') this.#busyCheck(name);
|
|
1400
1407
|
else {
|
|
@@ -1405,8 +1412,9 @@ export class Conversations {
|
|
|
1405
1412
|
if (kind === 'start') await this.room({ kind: 'start', name, memoryMb: c.memoryMb });
|
|
1406
1413
|
if (this.#acts.has(name)) throw this.#busy(name);
|
|
1407
1414
|
const act = this.#take(name, kind);
|
|
1408
|
-
|
|
1409
|
-
|
|
1415
|
+
const done = this.#perform(name, act);
|
|
1416
|
+
this.acted = done;
|
|
1417
|
+
return wait ? done : this.machineState(name);
|
|
1410
1418
|
}
|
|
1411
1419
|
|
|
1412
1420
|
/* "FORCE NOW": the step running is ended and the next one started (polite -> forced -> SIGTERM ->
|
|
@@ -1432,7 +1440,25 @@ export class Conversations {
|
|
|
1432
1440
|
machineState(name) {
|
|
1433
1441
|
const c = this.#store.get(name);
|
|
1434
1442
|
if (!c) throw new Refusal(404, 'No such conversation.');
|
|
1435
|
-
return { action: c.machine ?? null, report: c.machineReport ?? null, limits: STEP_LIMITS, escalate: c.stopEscalate !== false };
|
|
1443
|
+
return { action: c.machine ?? null, report: c.machineReport ?? null, limits: STEP_LIMITS, escalate: c.stopEscalate !== false, watchdog: this.watchdog(name) };
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
/* ITS WATCHDOG, as its owner set it (a default, changed per conversation): on, and how long its
|
|
1447
|
+
machine may stay mute or full before it is forced off and started again (watchdog.mjs). */
|
|
1448
|
+
watchdog(name) {
|
|
1449
|
+
const w = this.#store.get(name)?.watchdog;
|
|
1450
|
+
return { on: w?.on !== false, delayMin: Number.isInteger(w?.delayMin) ? w.delayMin : WATCHDOG_DELAY_MIN };
|
|
1451
|
+
}
|
|
1452
|
+
setWatchdog(name, { on, delayMin } = {}) {
|
|
1453
|
+
if (!this.#store.get(name)) throw new Refusal(404, 'No such conversation.');
|
|
1454
|
+
const now = this.watchdog(name);
|
|
1455
|
+
const minutes = delayMin === undefined ? now.delayMin : delayMin;
|
|
1456
|
+
if (!Number.isInteger(minutes) || minutes < WATCHDOG_MIN || minutes > WATCHDOG_MAX) throw new Refusal(400, `The watchdog waits ${WATCHDOG_MIN} to ${WATCHDOG_MAX} minutes.`);
|
|
1457
|
+
const next = { on: on === undefined ? now.on : on !== false, delayMin: minutes };
|
|
1458
|
+
/* Kept only where it differs from the default. */
|
|
1459
|
+
const kept = { ...(next.on ? {} : { on: false }), ...(next.delayMin === WATCHDOG_DELAY_MIN ? {} : { delayMin: next.delayMin }) };
|
|
1460
|
+
this.#store.patch(name, { watchdog: Object.keys(kept).length ? kept : undefined });
|
|
1461
|
+
return this.machineState(name);
|
|
1436
1462
|
}
|
|
1437
1463
|
|
|
1438
1464
|
/* THE WAY DOWN, AS ITS OWNER CHOSE (a default, changed per conversation): on (the default), a stop
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/* SETTINGS, MACHINES (09-11): every conversation's machine at a glance -- its state, the memory its
|
|
2
|
+
* qemu holds on this server, and since when -- each one forced off from there; then the VM manager
|
|
3
|
+
* (does it answer, restarted by its owner) and the two choices of this server: what is done when the
|
|
4
|
+
* VM manager hangs (vmwatch.mjs) and when memory is short (capacity.mjs).
|
|
5
|
+
*
|
|
6
|
+
* Nothing here asks a machine anything: the states come in one question to the VM manager (shared with
|
|
7
|
+
* every caller for a few seconds), the memory from the host's own figures. A VM manager that does not
|
|
8
|
+
* answer gives "Unknown" for each, never "gone".
|
|
9
|
+
*/
|
|
10
|
+
import { Refusal } from './conversations.mjs';
|
|
11
|
+
|
|
12
|
+
export class MachineList {
|
|
13
|
+
#conversations; #vms; #capacity; #vmWatch; #now;
|
|
14
|
+
constructor({ conversations, vms, capacity, vmWatch, now = () => Date.now() }) {
|
|
15
|
+
this.#conversations = conversations; this.#vms = vms; this.#capacity = capacity; this.#vmWatch = vmWatch; this.#now = now;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* { machines: [{ name, state, rssMb, sizeMb, since, action }], manager, pressure }. `since`: when its qemu
|
|
19
|
+
started (running, or asleep and still holding memory), else when it was last stopped or put to
|
|
20
|
+
sleep here, else null. */
|
|
21
|
+
async list() {
|
|
22
|
+
const states = await this.#vms.states().catch(() => null);
|
|
23
|
+
const room = await this.#capacity?.room().catch(() => null) ?? null;
|
|
24
|
+
const held = new Map((room?.machines ?? []).map((m) => [m.vm, m]));
|
|
25
|
+
const machines = this.#conversations.list().filter((c) => c.phase === 'ready').map((c) => {
|
|
26
|
+
const vm = `clv-${c.name}`;
|
|
27
|
+
const state = states ? (states.get(vm) ?? 'Gone') : 'Unknown';
|
|
28
|
+
const rssMb = held.get(vm)?.rssMb ?? 0;
|
|
29
|
+
const age = room?.machineAge?.[vm];
|
|
30
|
+
const report = c.machineReport;
|
|
31
|
+
const ended = report?.ok && ((state === 'Stopped' && ['stop', 'force'].includes(report.kind)) || (state === 'Suspended' && report.kind === 'sleep')) ? report.at : null;
|
|
32
|
+
const since = age !== undefined && rssMb > 0 ? new Date(this.#now() - age * 1000).toISOString() : ended;
|
|
33
|
+
return { name: c.name, state, rssMb, sizeMb: c.memoryMb ?? null, since, action: c.machine?.kind ?? null };
|
|
34
|
+
}).sort((a, b) => b.rssMb - a.rssMb || a.name.localeCompare(b.name));
|
|
35
|
+
return { machines, manager: this.#vmWatch?.about() ?? null, pressure: this.#capacity?.pressureWay() ?? null };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/* "Force stop" from the list: the same as from its conversation (one lock per machine). */
|
|
39
|
+
async force(name) {
|
|
40
|
+
if (!this.#conversations.get(name)) throw new Refusal(404, 'No such conversation.');
|
|
41
|
+
await this.#conversations.machineAction(name, 'force');
|
|
42
|
+
return this.list();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* "Restart the manager", confirmed in the page: every machine is suspended and resumed. */
|
|
46
|
+
async revive() {
|
|
47
|
+
if (!this.#vmWatch) throw new Refusal(404, 'No machine manager here.');
|
|
48
|
+
try { await this.#vmWatch.revive(); } catch (error) { throw new Refusal(error.status ?? 500, error.message); }
|
|
49
|
+
return this.list();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
setManagerMode(mode) {
|
|
53
|
+
try { this.#vmWatch?.setMode(mode); } catch (error) { throw new Refusal(error.status ?? 400, error.message); }
|
|
54
|
+
return this.list();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
setPressure(way) { this.#capacity?.setPressureWay(way); return this.list(); }
|
|
58
|
+
}
|
package/server/main.mjs
CHANGED
|
@@ -81,6 +81,8 @@ import { Events } from './events.mjs';
|
|
|
81
81
|
import { Bundles } from './bundle.mjs';
|
|
82
82
|
import { migrateData } from './dataformat.mjs';
|
|
83
83
|
import { VmWatch } from './vmwatch.mjs';
|
|
84
|
+
import { Watchdog } from './watchdog.mjs';
|
|
85
|
+
import { MachineList } from './machinelist.mjs';
|
|
84
86
|
import { WakeLearn } from './wakelearn.mjs';
|
|
85
87
|
import { BoxCollect } from './boxcollect.mjs';
|
|
86
88
|
import { Boxes, handleBoxes, voiceboxConnector, syncTargets, PAIR_PATH as BOX_PAIR_PATH, FIRMWARE_PATH as BOX_FIRMWARE_PATH } from './boxes.mjs';
|
|
@@ -186,7 +188,7 @@ const withoutTmux = (env) => Object.fromEntries(Object.entries(env).filter(([key
|
|
|
186
188
|
|
|
187
189
|
const REFUSED = 'This Clavarium belongs to someone else: your account is not one of its operators.\n';
|
|
188
190
|
|
|
189
|
-
function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, rooms, features, apikeys, relayJoin } = {}) {
|
|
191
|
+
function serve(port, conversations, resources, { gate = () => 'local', originOk, shortcuts, voice, sharing, door, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, guide, repair, capacity, updates, instance = new Instance(), certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, boxes, catalogue, rooms, machineList, features, apikeys, relayJoin } = {}) {
|
|
190
192
|
/* Its manifest carries the name of this Clavarium, or the one a device chose (instance.mjs). */
|
|
191
193
|
const sendManifest = (response, url) => response.writeHead(200, { ...HEADERS, 'content-type': 'application/manifest+json' }).end(instance.manifest(new URL(url ?? '/', 'http://local').searchParams.get('name') ?? undefined));
|
|
192
194
|
const sendFile = async (response, file) => {
|
|
@@ -261,7 +263,7 @@ function serve(port, conversations, resources, { gate = () => 'local', originOk,
|
|
|
261
263
|
/* Settings, Access, API keys: made and revoked by an administrator only (past the gate). */
|
|
262
264
|
if (apikeys && pathname.startsWith('/api/apikeys') && await handleApiKeys(request, response, apikeys.keys, originOk, HEADERS, events)) return;
|
|
263
265
|
if (boxes && pathname.startsWith('/api/boxes') && await handleBoxes(request, response, boxes, originOk, HEADERS, (text) => QRCode.toString(text, { type: 'svg', margin: 1, errorCorrectionLevel: 'M' }))) return;
|
|
264
|
-
if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue, rooms)) return;
|
|
266
|
+
if (conversations && await handleApi(request, response, conversations, HEADERS, resources, originOk, shortcuts, voice, sharing, secrets, network, signin, mailboxes, gitReview, platform, answerer, wakeups, alerts, talk, gitAccess, gitKeeper, shelf, health, setup, repair, guide, capacity, updates, instance, certificate, team, reacting, machinesMove, serverLogs, history, events, bundles, wifi, binders, meshcentral, tethers, accounts, groups, catalogue, rooms, machineList)) return;
|
|
265
267
|
if (pathname === '/manifest.webmanifest' && request.method === 'GET') { sendManifest(response, request.url); return; }
|
|
266
268
|
const file = FILES[pathname];
|
|
267
269
|
if (!file || (request.method !== 'GET' && request.method !== 'HEAD')) {
|
|
@@ -520,7 +522,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
520
522
|
const gitTimer = gitKeeper.start(gitEveryMs);
|
|
521
523
|
/* A conversation with a tool on a screen that is not its terminal: see talk.mjs. */
|
|
522
524
|
/* Voice boxes: what the tool says in their conversation is read aloud (boxes.mjs). */
|
|
523
|
-
let boxes; let rooms;
|
|
525
|
+
let boxes; let rooms; let machineList;
|
|
524
526
|
const talk = new Talk({ spoke: (name, text, to, how) => { void boxes?.agentSaid(name, text, to, how); }, inRoom: (name, entry, kind) => rooms?.answered(name, entry, kind), store: talkStore, words: new Store(`${dataDir}/talk-words.json`), keptDir: `${dataDir}/talk-kept`, vms, conversations: all, resources: folders, toolbox, warm: (name) => bridge?.warm(name), ...(talkEveryMs ? { listenEveryMs: talkEveryMs } : {}),
|
|
525
527
|
...(rereadAfterMs === undefined ? {} : { rereadAfterMs }),
|
|
526
528
|
/* A line typed down the terminal already open when there is one, and
|
|
@@ -607,10 +609,22 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
607
609
|
/* Where its chat is on, its agent is given an event when its disk or memory crosses a level (healthdocket.mjs);
|
|
608
610
|
not where its owner turned on its own reaction (above): one way of telling it, not two. */
|
|
609
611
|
const healthDocket = new HealthDocket({ store: new Store(`${dataDir}/health-docket.json`), dockets, reacting: (name) => reacting.settings(name).on });
|
|
610
|
-
health.forgotten = (name) => healthDocket.forget(name);
|
|
612
|
+
health.forgotten = (name) => { healthDocket.forget(name); watchdog.forget(name); };
|
|
611
613
|
/* A machine's problems worth keeping in What happened: said once, until they went away. */
|
|
612
614
|
const problemsSaid = new Map();
|
|
615
|
+
/* ITS WATCHDOG (watchdog.mjs): mute or full for as long as its owner set, forced off then started, once;
|
|
616
|
+
its AI told in its chat, its owner alerted with the report. */
|
|
617
|
+
const watchdog = new Watchdog({ conversations: all, store: new Store(`${dataDir}/watchdog.json`),
|
|
618
|
+
act: async (name) => {
|
|
619
|
+
events.add({ kind: 'machine', text: `Machine of ${name}: mute or full for too long, forced off and started by its watchdog`, conversation: name });
|
|
620
|
+
const forced = await all.machineAction(name, 'force', { wait: true });
|
|
621
|
+
if (!forced?.ok) return forced;
|
|
622
|
+
return all.machineAction(name, 'start', { wait: true });
|
|
623
|
+
},
|
|
624
|
+
tell: (name, text, started) => all.renewed(name, text, started),
|
|
625
|
+
alert: (payload) => { events.add({ kind: 'machine', text: `${payload.title}: ${payload.body ?? ''}`.trim() }); void alerts.tell(payload)?.catch?.(() => {}); } });
|
|
613
626
|
health.judged = (name, record) => {
|
|
627
|
+
void watchdog.judged(name, record).catch(() => {});
|
|
614
628
|
talk.machine(name, record); void reacting.judged(name, record).catch(() => {});
|
|
615
629
|
/* A folder that came loose and was put back: said once, in its chat (the look that put it back). */
|
|
616
630
|
for (const path of record?.remounted ?? []) { try { talk.event(name, { kind: 'machine-ok', text: `Le dossier ${path} s'était détaché de la machine : il a été remonté.`, topic: 'Machine', brief: 'Shared folder' }); } catch { /* its chat is off */ } }
|
|
@@ -641,8 +655,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
641
655
|
const capacity = new Capacity({ run: asHost, store: new Store(`${dataDir}/server.json`), conversations: all, shelf, ...(serverRoomMs === undefined ? {} : { roomMs: serverRoomMs }),
|
|
642
656
|
/* Under the reserve: the machine that takes the most put to sleep, the owner told, and its chat. */
|
|
643
657
|
sleep: (name) => { events.add({ kind: 'machine', text: `Machine of ${name} put to sleep: this server was short of room`, conversation: name }); return all.sleep(name); },
|
|
644
|
-
/*
|
|
645
|
-
force: async (name) => { events.add({ kind: 'machine', text: `Machine of ${name} forced off: this server was short of
|
|
658
|
+
/* Memory short, forced off (capacity.mjs, pressureWay: the default), or frozen and so not put to sleep: through the one lock of its machine. */
|
|
659
|
+
force: async (name) => { events.add({ kind: 'machine', text: `Machine of ${name} forced off: this server was short of memory`, conversation: name }); return (await all.machineAction(name, 'force', { wait: true }))?.ok === true; }, alert: (payload) => { events.add({ kind: 'server', text: `${payload.title}: ${payload.body ?? ''}`.trim() }); void alerts.tell(payload); },
|
|
646
660
|
/* A machine asleep but still holding its RAM (a suspend that did not free it): its memory reclaimed, only that machine touched. */
|
|
647
661
|
reclaim: (name) => { events.add({ kind: 'machine', text: `Machine of ${name}: memory reclaimed (it was asleep but still held RAM)`, conversation: name }); return vms.reclaim(name).then((r) => (r.stdout || '').trim()); },
|
|
648
662
|
say: (name, text) => { try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine' }); } catch { /* its chat may be off */ } } });
|
|
@@ -657,6 +671,8 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
657
671
|
try { talk.event(name, { kind: 'machine-problem', text, tone: 'warn', topic: 'Machine', brief: 'Out of memory', actions: ['memory', 'restart', 'terminal'] }); } catch { /* its chat may be off */ }
|
|
658
672
|
};
|
|
659
673
|
const stopWatch = capacity.start();
|
|
674
|
+
/* Settings, Machines: each machine, the VM manager, this server's choices (machinelist.mjs). */
|
|
675
|
+
machineList = new MachineList({ conversations: all, vms, capacity, vmWatch });
|
|
660
676
|
/* The curves of the resources (history.mjs): one look a minute, from what the server knows already. */
|
|
661
677
|
const history = new History({ file: `${dataDir}/history.json` });
|
|
662
678
|
const historyLook = () => capacity.room().then((room) => history.sample(room, all.list().filter((c) => c.phase === 'ready').map((c) => ({ name: c.name, vm: `clv-${c.name}`, cores: c.cpus ?? 1, memoryMb: c.memoryMb, health: health.of(c.name) })))).catch(() => {});
|
|
@@ -801,7 +817,7 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
801
817
|
answerer: answererConfig(env)?.models.length ?? 0, updates: updates.about(), team: team ? team.list().length : null,
|
|
802
818
|
screen: await quick(screenNow(), 1500, null), catalogue: await quick(catalogue.providers().catch(() => []), 1500, []),
|
|
803
819
|
}) });
|
|
804
|
-
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, features, apikeys, relayJoin: host.length ? new RelayJoin({ host: asHost }) : null, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
820
|
+
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, apikeys, relayJoin: host.length ? new RelayJoin({ host: asHost }) : null, bundles: new Bundles({ dir: `${dataDir}/imports`, folder: (name) => folders.folder(name) }), repair: (name) => repairTerminal(name) });
|
|
805
821
|
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); dockets.stop(); clearInterval(gitTimer); talk.stop(); });
|
|
806
822
|
let closing = false;
|
|
807
823
|
boxes.attach(server, WebSocketServer);
|
package/server/settingswords.mjs
CHANGED
|
@@ -238,7 +238,7 @@ export const SETTINGS_WORDS_FR = {
|
|
|
238
238
|
'set-mwhy-busy': 'Une autre action est en cours', 'set-mwhy-notready': 'Pas encore prête', 'set-mwhy-runs': 'Elle tourne déjà',
|
|
239
239
|
'set-mwhy-stopped': 'Déjà arrêtée', 'set-mwhy-asleep': 'Déjà endormie', 'set-mwhy-nothing': 'Endormie : rien ne tourne',
|
|
240
240
|
'set-mwhat-start': 'Démarre sa machine et son outil', 'set-mwhat-stop': 'L’arrête proprement, de force si ça bloque',
|
|
241
|
-
'set-mwhat-restart': 'L’arrête, puis la redémarre', 'set-mwhat-force': 'Coupe tout, comme une coupure de courant',
|
|
241
|
+
'set-mwhat-restart': 'L’arrête, puis la redémarre', 'set-mwhat-force': 'Coupe tout, comme une coupure de courant', 'set-mdanger-title': 'Si la machine est bloquée',
|
|
242
242
|
'set-mconf-stop': 'L’arrêter ? Le travail en cours s’interrompt.', 'set-mconf-restart': 'Redémarrer ? L’outil repart, fichiers gardés.',
|
|
243
243
|
'set-mconf-force': 'Comme une coupure de courant : rien n’est sauvé.', 'set-mconf-no': 'Annuler',
|
|
244
244
|
'set-mesc': 'Si un arrêt bloque', 'set-mesc-auto': 'Forcer seul', 'set-mesc-ask': 'Me demander',
|
|
@@ -253,5 +253,18 @@ export const SETTINGS_WORDS_FR = {
|
|
|
253
253
|
'set-mrep-freed': '{gb} Go rendus', 'set-mrep-replaced': 'Remplacée par Forcer l’arrêt',
|
|
254
254
|
'set-mt-stop': 'Arrêt de sa machine', 'set-mt-force': 'Arrêt forcé de sa machine', 'set-mt-sleep': 'Mise en veille', 'set-mt-start': 'Démarrage de sa machine',
|
|
255
255
|
'set-stopped-page': 'Arrêtée. Elle démarre quand vous la démarrez.',
|
|
256
|
+
/* Its watchdog (watchdog.mjs, 09-11). */
|
|
257
|
+
'set-mdog': 'Chien de garde', 'set-mdog-what': 'La redémarre si elle bloque', 'set-mdog-off': 'Désactivé', 'set-mdog-custom': 'Autre',
|
|
258
|
+
/* Settings, Machines (machinelist.mjs, 09-11): the list, the machine manager, the server's two choices. */
|
|
259
|
+
'set-ch-s-machines': 'Machines', 'set-ml-about': 'État et mémoire.', 'set-ml-none': 'Aucune machine',
|
|
260
|
+
'set-ml-now': '{n} en marche sur {all}', 'set-ml-since': 'depuis {t}', 'set-ml-busy': 'Occupée',
|
|
261
|
+
'set-ml-running': 'En marche', 'set-ml-asleep': 'Endormie', 'set-ml-stopped': 'Arrêtée', 'set-ml-starting': 'Démarre',
|
|
262
|
+
'set-ml-stopping': 'S’arrête', 'set-ml-unknown': 'Inconnu', 'set-ml-gone': 'Disparue',
|
|
263
|
+
'set-ml-manager': 'Gestionnaire de machines', 'set-ml-revive': 'Redémarrer le gestionnaire', 'set-ml-revive-yes': 'Redémarrer',
|
|
264
|
+
'set-ml-revive-q': 'Redémarrer ? Toutes les machines sont reprises.', 'set-ml-reviving': 'Redémarrage…',
|
|
265
|
+
'set-ml-answers': 'Répond', 'set-ml-last': 'redémarré {t}', 'set-ml-mute': 'Ne répond pas', 'set-ml-asked': 'attend votre accord',
|
|
266
|
+
'set-ml-force-q': 'Forcer l’arrêt de {name} ? Rien n’est sauvé.',
|
|
267
|
+
'set-ml-hang': 'S’il bloque', 'set-ml-hang-what': 'Nuit : de 0 h à 7 h', 'set-ml-night': 'La nuit', 'set-ml-always': 'Toujours', 'set-ml-ask': 'Me demander',
|
|
268
|
+
'set-ml-short': 'Manque de mémoire', 'set-ml-short-what': 'La plus grosse machine', 'set-ml-force': 'Forcer l’arrêt', 'set-ml-sleep': 'Mettre en veille', 'set-ml-alert': 'Alerter seulement',
|
|
256
269
|
};
|
|
257
270
|
export const settingsWords = (lang) => (String(lang ?? '').toLowerCase().split('-')[0] === 'fr' ? { ...SETTINGS_WORDS_FR } : {});
|
package/server/talk.mjs
CHANGED
|
@@ -536,6 +536,15 @@ export class Talk {
|
|
|
536
536
|
return { ...this.of(name), told };
|
|
537
537
|
}
|
|
538
538
|
|
|
539
|
+
/* THE OWNER PINS a message of the chat, either side (`on` false: unpinned). Kept at the top of the
|
|
540
|
+
chat, 5 at most (Parley), and read again by the tool after a restart: it is not woken for it. */
|
|
541
|
+
async pin(name, to, on = true) {
|
|
542
|
+
if (!this.of(name).on) throw new Refusal(409, 'Talking through the app is not turned on for this conversation.');
|
|
543
|
+
if (typeof to !== 'string' || typeof on !== 'boolean') throw new Refusal(400, 'Say which message (to), and on: true or false.');
|
|
544
|
+
try { this.#parley(name).pin(to, on); } catch (error) { if (error instanceof RangeError) throw new Refusal(400, error.message); throw error; }
|
|
545
|
+
return this.of(name);
|
|
546
|
+
}
|
|
547
|
+
|
|
539
548
|
/* A FILE THE PERSON ATTACHES, before the message that carries it: put in
|
|
540
549
|
the bridge folder, in a folder of its own, under the name it had.
|
|
541
550
|
Resolves with where the tool finds it. */
|
package/server/vm.mjs
CHANGED
|
@@ -136,6 +136,13 @@ export class Vms {
|
|
|
136
136
|
return [...this.prefix, 'vm', 'exec', vmName(conversation), '--', ...argv];
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
/* Every machine's state, by VM name (a Map); throws VmUnknown when the VM manager did not answer. */
|
|
140
|
+
async states({ fresh = false } = {}) {
|
|
141
|
+
const snap = await this.#states(fresh);
|
|
142
|
+
if (!snap.states) throw new VmUnknown(snap.why);
|
|
143
|
+
return new Map(snap.states);
|
|
144
|
+
}
|
|
145
|
+
|
|
139
146
|
/* "Running", "Stopped", "Suspended", ... or undefined when there is no VM. */
|
|
140
147
|
/* Its state, or undefined when the VM manager lists every machine and not this one. A VM
|
|
141
148
|
manager that does not answer (busy, timed out, restarting) says nothing of the machine:
|
package/server/vmwatch.mjs
CHANGED
|
@@ -1,56 +1,115 @@
|
|
|
1
1
|
/* THE VM MANAGER, WATCHED. Every machine goes through it; when it stops
|
|
2
2
|
* answering, nothing about a machine can be done, while this server itself
|
|
3
3
|
* must go on serving its pages. So it is asked now and then (host program:
|
|
4
|
-
* `vm ping`, bounded), and:
|
|
4
|
+
* `vm ping`: `multipass list`, bounded to 30 s), and:
|
|
5
5
|
* - while it does not answer, `ok` is false: the pages say "the machines
|
|
6
6
|
* cannot be reached just now";
|
|
7
|
-
* - when it has not answered for STUCK_MS
|
|
8
|
-
* (
|
|
9
|
-
*
|
|
7
|
+
* - when it has not answered for STUCK_MS it is HUNG, and its owner's
|
|
8
|
+
* choice (`mode`, kept here) says what is done (09-11):
|
|
9
|
+
* night (the default) its daemon restarted by itself only between
|
|
10
|
+
* NIGHT_FROM and NIGHT_UNTIL, this server's local time; by day
|
|
11
|
+
* its owner is alerted and asked (Settings, Machines);
|
|
12
|
+
* always restarted by itself, at any hour;
|
|
13
|
+
* ask never by itself: alerted and asked.
|
|
14
|
+
* By itself, ONCE (host program: `vm revive`), recorded, the owner told;
|
|
15
|
+
* not again within REVIVE_EVERY_MS, so that it never loops.
|
|
16
|
+
* - its owner may restart it by hand (`revive`), confirmed in the page:
|
|
17
|
+
* every machine is suspended and resumed, every terminal drops.
|
|
10
18
|
*/
|
|
11
19
|
export const EVERY_MS = 60_000;
|
|
12
20
|
/* Restarting it suspends and resumes EVERY machine: every terminal drops (21-10). Only when it
|
|
13
|
-
has said nothing at all for this long. */
|
|
14
|
-
export const STUCK_MS =
|
|
21
|
+
has said nothing at all for this long: mute (30 s each) on three looks in a row. */
|
|
22
|
+
export const STUCK_MS = 2 * 60_000;
|
|
15
23
|
export const REVIVE_EVERY_MS = 6 * 3600_000;
|
|
24
|
+
export const MANAGER_MODES = Object.freeze(['night', 'always', 'ask']);
|
|
25
|
+
export const NIGHT_FROM = 0;
|
|
26
|
+
export const NIGHT_UNTIL = 7;
|
|
27
|
+
/* What a look waits for the host program, which bounds `multipass list` to 30 s itself. */
|
|
28
|
+
const PING_MS = 40_000;
|
|
16
29
|
|
|
17
30
|
const said = (r) => String(r?.stderr || r?.stdout || '').trim().split('\n').filter(Boolean).pop()?.slice(0, 200) || `exit ${r?.code}`;
|
|
18
31
|
|
|
19
32
|
export class VmWatch {
|
|
20
|
-
#run; #store; #now; #log; #alert; #stuckMs; #reviveEveryMs; #downSince = null;
|
|
33
|
+
#run; #store; #now; #hour; #log; #alert; #stuckMs; #reviveEveryMs; #downSince = null; #reviving = null;
|
|
21
34
|
ok = true;
|
|
22
|
-
|
|
23
|
-
|
|
35
|
+
/* `hour()`: this server's local hour, 0-23 (injected for tests). */
|
|
36
|
+
constructor({ run, store, now = () => Date.now(), hour = () => new Date().getHours(), log = (line) => console.error(line), alert = () => {}, stuckMs = STUCK_MS, reviveEveryMs = REVIVE_EVERY_MS }) {
|
|
37
|
+
this.#run = run; this.#store = store; this.#now = now; this.#hour = hour; this.#log = log; this.#alert = alert; this.#stuckMs = stuckMs; this.#reviveEveryMs = reviveEveryMs;
|
|
24
38
|
}
|
|
25
39
|
|
|
26
|
-
/* What the last restart of the VM manager was, if any: { at, why, result }. */
|
|
27
|
-
last() { const r = this.#store.get('revive'); return r ? { at: r.at, why: r.why, result: r.result ?? null } : null; }
|
|
40
|
+
/* What the last restart of the VM manager was, if any: { at, why, result, by }. */
|
|
41
|
+
last() { const r = this.#store.get('revive'); return r ? { at: r.at, why: r.why, result: r.result ?? null, by: r.by ?? 'server' } : null; }
|
|
28
42
|
|
|
29
|
-
/*
|
|
43
|
+
/* Its owner's choice when it hangs: night (the default), always, ask. */
|
|
44
|
+
mode() { const m = this.#store.get('mode')?.mode; return MANAGER_MODES.includes(m) ? m : 'night'; }
|
|
45
|
+
setMode(mode) {
|
|
46
|
+
if (!MANAGER_MODES.includes(mode)) { const e = new Error('Choose night, always or ask.'); e.status = 400; throw e; }
|
|
47
|
+
this.#store.put({ name: 'mode', mode });
|
|
48
|
+
return this.about();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* For Settings, Machines: does it answer, since when not, what its owner chose, whether it waits for
|
|
52
|
+
its owner (`asked`), the last restart, and one running now. */
|
|
53
|
+
about() {
|
|
54
|
+
const asked = this.#store.get('asked');
|
|
55
|
+
return { ok: this.ok, downSince: this.#downSince === null ? null : new Date(this.#downSince).toISOString(), mode: this.mode(), asked: asked?.at && !this.ok ? { at: asked.at, why: asked.why } : null, last: this.last(), reviving: Boolean(this.#reviving) };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#night() { const h = this.#hour(); return h >= NIGHT_FROM && h < NIGHT_UNTIL; }
|
|
59
|
+
|
|
60
|
+
/* One look: 'ok', 'down', 'down; restarted already', 'asked', 'down; asked already', 'revived' or 'revive failed'. */
|
|
30
61
|
async look() {
|
|
31
|
-
const r = await this.#run(['vm', 'ping'], { timeoutMs:
|
|
62
|
+
const r = await this.#run(['vm', 'ping'], { timeoutMs: PING_MS }).catch((e) => ({ code: 1, stderr: e.message }));
|
|
32
63
|
if (r.code === 0) {
|
|
33
64
|
if (!this.ok) this.#log('vm manager: it answers again');
|
|
34
65
|
this.ok = true; this.#downSince = null;
|
|
66
|
+
this.#store.remove?.('asked');
|
|
35
67
|
return 'ok';
|
|
36
68
|
}
|
|
37
69
|
if (this.ok) this.#log(`vm manager: it does not answer (${said(r)})`);
|
|
38
70
|
this.ok = false;
|
|
39
71
|
this.#downSince ??= this.#now();
|
|
40
72
|
if (this.#now() - this.#downSince < this.#stuckMs) return 'down';
|
|
73
|
+
if (this.#reviving) return 'down';
|
|
74
|
+
const minutes = Math.max(1, Math.round((this.#now() - this.#downSince) / 60_000));
|
|
75
|
+
const why = `the VM manager did not answer for ${minutes} minute${minutes === 1 ? '' : 's'} (${said(r)})`;
|
|
76
|
+
const mode = this.mode();
|
|
77
|
+
/* By day (night), or never by itself (ask): its owner asked, once a hang. */
|
|
78
|
+
if (mode === 'ask' || (mode === 'night' && !this.#night())) {
|
|
79
|
+
if (this.#store.get('asked')) return 'down; asked already';
|
|
80
|
+
this.#store.put({ name: 'asked', at: new Date(this.#now()).toISOString(), why });
|
|
81
|
+
this.#log(`vm manager: ${why}: its owner is asked`);
|
|
82
|
+
this.#alert({ title: 'The machine manager is stuck', body: `${why}. Restarting it resumes every machine: Settings, Machines.`, url: '/?open=settings&at=machines' });
|
|
83
|
+
return 'asked';
|
|
84
|
+
}
|
|
41
85
|
const before = this.#store.get('revive');
|
|
42
86
|
if (before?.at && this.#now() - Date.parse(before.at) < this.#reviveEveryMs) return 'down; restarted already';
|
|
43
|
-
const minutes = Math.round((this.#now() - this.#downSince) / 60_000);
|
|
44
|
-
const why = `the VM manager did not answer for ${minutes} minutes (${said(r)})`;
|
|
45
|
-
this.#store.put({ name: 'revive', at: new Date(this.#now()).toISOString(), why, result: null });
|
|
46
87
|
this.#log(`vm manager: ${why}: its daemon is restarted, once`);
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
88
|
+
const result = await this.#revive(why, 'server');
|
|
89
|
+
this.#alert({ title: 'The machines could not be reached', body: `${why}: it was restarted (${result}).`, url: '/?open=settings&at=machines' });
|
|
90
|
+
return result === 'done' ? 'revived' : 'revive failed';
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* RESTARTED BY ITS OWNER (Settings, Machines; confirmed there): now, whatever the hour or the last one.
|
|
94
|
+
One at a time. Resolves with what the server records: { at, why, result, by }. */
|
|
95
|
+
async revive() {
|
|
96
|
+
if (this.#reviving) { const e = new Error('The machine manager is being restarted already.'); e.status = 409; throw e; }
|
|
97
|
+
this.#log('vm manager: restarted by its owner');
|
|
98
|
+
await this.#revive('asked by its owner', 'owner');
|
|
99
|
+
return this.about();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#revive(why, by) {
|
|
103
|
+
this.#reviving = (async () => {
|
|
104
|
+
this.#store.put({ name: 'revive', at: new Date(this.#now()).toISOString(), why, result: null, by });
|
|
105
|
+
const done = await this.#run(['vm', 'revive'], { timeoutMs: 180_000 }).catch((e) => ({ code: 1, stderr: e.message }));
|
|
106
|
+
const result = done.code === 0 ? 'done' : `failed: ${said(done)}`;
|
|
107
|
+
this.#store.put({ name: 'revive', at: new Date(this.#now()).toISOString(), why, result, by });
|
|
108
|
+
this.#log(`vm manager: restart ${result}`);
|
|
109
|
+
if (done.code === 0) { this.#store.remove?.('asked'); this.#downSince = null; }
|
|
110
|
+
return result;
|
|
111
|
+
})().finally(() => { this.#reviving = null; });
|
|
112
|
+
return this.#reviving;
|
|
54
113
|
}
|
|
55
114
|
|
|
56
115
|
/* Looked at every `everyMs` (0: never), one look at a time. */
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/* THE WATCHDOG OF A MACHINE (09-11): a machine that stays mute, or whose memory stays full, is forced
|
|
2
|
+
* off and started again, once, by this server -- never by its AI, which is the thing stuck.
|
|
3
|
+
*
|
|
4
|
+
* What it looks at is what health.mjs found (told each look: `judged`): the machine runs, and either it
|
|
5
|
+
* did not answer the probe, or its memory had less than FULL_PERCENT free. Nothing more is asked of it.
|
|
6
|
+
*
|
|
7
|
+
* - Its owner's setting, per conversation (conversations.mjs, watchdog): on by default, after an hour.
|
|
8
|
+
* - Seen so for the whole delay (a look that finds it well, or not running, starts the count again):
|
|
9
|
+
* forced off (`vm hardstop`, as a power cut: it is the one way that works on a frozen machine), then
|
|
10
|
+
* started -- both through the one lock of its machine (machineAction), so never during another action.
|
|
11
|
+
* - Its AI told in its chat (the tool reads it again once started), its owner alerted with the report.
|
|
12
|
+
* - NEVER A LOOP: not again on the same machine within AGAIN_MS, nor before it was seen well once
|
|
13
|
+
* since. Stuck again within that time: its owner is told, once, and nothing else is done.
|
|
14
|
+
* - A machine that is starting, being restarted or moved is not judged (health says it busy).
|
|
15
|
+
*/
|
|
16
|
+
export const FULL_PERCENT = 5;
|
|
17
|
+
export const AGAIN_MS = 6 * 3600_000;
|
|
18
|
+
|
|
19
|
+
/* "1 h", "30 min", "1 h 30". */
|
|
20
|
+
export function delayWords(minutes) {
|
|
21
|
+
const h = Math.floor(minutes / 60); const m = minutes % 60;
|
|
22
|
+
return h === 0 ? `${m} min` : m === 0 ? `${h} h` : `${h} h ${String(m).padStart(2, '0')}`;
|
|
23
|
+
}
|
|
24
|
+
const hhmm = (ms) => { const d = new Date(ms); return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`; };
|
|
25
|
+
|
|
26
|
+
/* What one look says: 'mute', 'full', 'well', or null (nothing to judge: not running, busy). */
|
|
27
|
+
export function lookOf(record) {
|
|
28
|
+
if (!record || record.busy || record.state !== 'Running') return null;
|
|
29
|
+
if (record.answering === false) return 'mute';
|
|
30
|
+
const m = record.memory;
|
|
31
|
+
if (record.answering === true && m && m.totalMb > 0 && m.availableMb < (m.totalMb * FULL_PERCENT) / 100) return 'full';
|
|
32
|
+
return record.answering === true ? 'well' : null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export class Watchdog {
|
|
36
|
+
#conversations; #store; #act; #tell; #alert; #now; #trouble = new Map(); #acting = new Set();
|
|
37
|
+
|
|
38
|
+
/* `conversations`: get(name), watchdog(name). `store`: the last time each machine was restarted
|
|
39
|
+
(kept across a restart of this server, so that it never loops). `act(name)`: forced off then
|
|
40
|
+
started, resolves with { ok, said }. `tell(name, text, started)`: its chat, read by its AI.
|
|
41
|
+
`alert(payload)`: its owner's alerts. */
|
|
42
|
+
constructor({ conversations, store, act, tell = () => {}, alert = () => {}, now = () => Date.now() }) {
|
|
43
|
+
this.#conversations = conversations; this.#store = store; this.#act = act; this.#tell = tell; this.#alert = alert; this.#now = now;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* What is known of one machine: since when it is mute or full, its last restart by the watchdog. */
|
|
47
|
+
of(name) {
|
|
48
|
+
const t = this.#trouble.get(name);
|
|
49
|
+
const last = this.#store.get(name);
|
|
50
|
+
return { trouble: t ? { kind: t.kind, since: new Date(t.since).toISOString() } : null, last: last ? { at: last.at, ok: last.ok, why: last.why } : null, acting: this.#acting.has(name) };
|
|
51
|
+
}
|
|
52
|
+
forget(name) { this.#trouble.delete(name); this.#store.remove?.(name); }
|
|
53
|
+
|
|
54
|
+
/* One look of health.mjs. Resolves with what was done: null, 'watching', 'restarted', 'failed',
|
|
55
|
+
'held' (stuck again too soon: said, not done). */
|
|
56
|
+
async judged(name, record) {
|
|
57
|
+
const c = this.#conversations.get(name);
|
|
58
|
+
const set = c ? this.#conversations.watchdog(name) : null;
|
|
59
|
+
const look = lookOf(record);
|
|
60
|
+
if (!c || !set?.on || look === null || look === 'well') {
|
|
61
|
+
this.#trouble.delete(name);
|
|
62
|
+
/* Seen well since its last restart: the watchdog may act again, after AGAIN_MS. */
|
|
63
|
+
const last = this.#store.get(name);
|
|
64
|
+
if (look === 'well' && last && !last.wellSince) this.#store.put({ ...last, wellSince: new Date(this.#now()).toISOString() });
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (this.#acting.has(name)) return null;
|
|
68
|
+
const now = this.#now();
|
|
69
|
+
const t = this.#trouble.get(name) ?? { since: now, kind: look, full: false };
|
|
70
|
+
t.kind = look; t.full ||= look === 'full';
|
|
71
|
+
this.#trouble.set(name, t);
|
|
72
|
+
if (now - t.since < set.delayMin * 60_000) return 'watching';
|
|
73
|
+
const last = this.#store.get(name);
|
|
74
|
+
if (last && (now - Date.parse(last.at) < AGAIN_MS || !last.wellSince)) {
|
|
75
|
+
if (last.held) return null;
|
|
76
|
+
this.#store.put({ ...last, held: true });
|
|
77
|
+
this.#alert({ title: `${name}: its machine is stuck again`, body: `Restarted by its watchdog at ${hhmm(Date.parse(last.at))}, stuck again: not restarted twice. Force stop or restart it yourself.`, url: `/?c=${encodeURIComponent(name)}&open=settings` });
|
|
78
|
+
return 'held';
|
|
79
|
+
}
|
|
80
|
+
return this.#restart(name, set, t);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async #restart(name, set, t) {
|
|
84
|
+
this.#acting.add(name);
|
|
85
|
+
const at = this.#now();
|
|
86
|
+
const why = t.kind === 'mute' ? (t.full ? 'memory full' : 'no answer') : 'memory full';
|
|
87
|
+
this.#store.put({ name, at: new Date(at).toISOString(), why, ok: null });
|
|
88
|
+
try {
|
|
89
|
+
const report = await Promise.resolve(this.#act(name)).catch((error) => ({ ok: false, said: String(error?.message ?? error) }));
|
|
90
|
+
const when = hhmm(this.#now());
|
|
91
|
+
const head = t.kind === 'mute' ? `Your machine did not answer for ${delayWords(set.delayMin)}${t.full ? ' (memory full)' : ''}` : `Your machine's memory stayed full for ${delayWords(set.delayMin)}`;
|
|
92
|
+
const text = report?.ok ? `${head}: it was restarted automatically at ${when}.` : `${head}: it was forced off at ${when} but did not start again. ${report?.said ?? ''}`.trim();
|
|
93
|
+
this.#store.put({ name, at: new Date(at).toISOString(), why, ok: Boolean(report?.ok) });
|
|
94
|
+
try { this.#tell(name, text, Boolean(report?.ok)); } catch { /* its chat may be off */ }
|
|
95
|
+
this.#alert({ title: report?.ok ? `${name}: restarted by its watchdog` : `${name}: its watchdog could not restart it`, body: `${text}${report?.said ? ` ${report.said}` : ''}`.slice(0, 200), url: `/?c=${encodeURIComponent(name)}&open=settings` });
|
|
96
|
+
return report?.ok ? 'restarted' : 'failed';
|
|
97
|
+
} finally {
|
|
98
|
+
this.#trouble.delete(name);
|
|
99
|
+
this.#acting.delete(name);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
package/web/app.js
CHANGED
|
@@ -289,7 +289,7 @@
|
|
|
289
289
|
now.title = uiSaid('set-m-force-now-why', 'Ends this step, starts the next');
|
|
290
290
|
now.addEventListener('click', () => void machineAct('force-now'));
|
|
291
291
|
const force = document.createElement('button'); force.type = 'button'; force.className = 'danger m-force-stop'; force.textContent = uiSaid('set-m-force', 'Force stop');
|
|
292
|
-
force.addEventListener('click', () => askMachine('force'));
|
|
292
|
+
force.addEventListener('click', () => askMachine('force', row));
|
|
293
293
|
row.append(now, force);
|
|
294
294
|
el.replaceChildren(ol, row);
|
|
295
295
|
}
|
|
@@ -1104,6 +1104,7 @@
|
|
|
1104
1104
|
$('quick-wake').hidden = !c || c.asleep !== true;
|
|
1105
1105
|
$('hand-terminal').hidden = !usable || noTerminal();
|
|
1106
1106
|
$('panel-actions').hidden = DEVICE || !c;
|
|
1107
|
+
$('m-danger').hidden = DEVICE || !c;
|
|
1107
1108
|
/* Its own sheet is there as soon as it exists: archiving one that failed is done from it. */
|
|
1108
1109
|
$('folders').hidden = DEVICE || !c;
|
|
1109
1110
|
}
|
|
@@ -1135,8 +1136,11 @@
|
|
|
1135
1136
|
restart: () => [uiSaid('set-mconf-restart', 'Restart it? The tool restarts; its files stay.'), uiSaid('set-m-restart', 'Restart')],
|
|
1136
1137
|
force: () => [uiSaid('set-mconf-force', 'Like a power cut: nothing is saved.'), uiSaid('set-m-force', 'Force stop')],
|
|
1137
1138
|
};
|
|
1138
|
-
|
|
1139
|
+
/* `near`: where it was asked (the zone apart, the steps over the chat): the question comes right under it. */
|
|
1140
|
+
function askMachine(kind, near) {
|
|
1139
1141
|
const [line, yes] = MCONFIRM[kind]();
|
|
1142
|
+
const where = near ?? (kind === 'force' ? $('m-danger') : $('panel-actions'));
|
|
1143
|
+
where.after($('m-confirm'));
|
|
1140
1144
|
$('m-confirm-text').textContent = line;
|
|
1141
1145
|
$('m-confirm-yes').textContent = yes;
|
|
1142
1146
|
$('m-confirm-yes').className = kind === 'force' ? 'danger' : 'primary';
|
|
@@ -2929,6 +2933,8 @@
|
|
|
2929
2933
|
for (const b of $('resume-on').children) b.setAttribute('aria-pressed', String((b.dataset.on === 'true') === (here?.resume !== false)));
|
|
2930
2934
|
/* A stop that hangs: forced by itself (the default), or asked first. */
|
|
2931
2935
|
for (const b of $('m-escalate').children) b.setAttribute('aria-pressed', String((b.dataset.on === 'true') === (here?.stopEscalate !== false)));
|
|
2936
|
+
/* Its watchdog: off, or how long it waits (a custom one shown in its field). */
|
|
2937
|
+
paintWatchdog(here);
|
|
2932
2938
|
/* Whether its tool asks before acting -- for a tool that can be given every right in its machine. */
|
|
2933
2939
|
$('rights-box').hidden = DEVICE || !here?.rights;
|
|
2934
2940
|
for (const b of $('ask-first').children) b.setAttribute('aria-pressed', String((b.dataset.on === 'true') === (here?.askFirst === true)));
|
|
@@ -3273,6 +3279,8 @@
|
|
|
3273
3279
|
schemes: { mail: { icon: 'mail', open: (ref, label) => { void openMailRef(ref, { label, of: name }); } } },
|
|
3274
3280
|
/* A reaction to one of its messages: wherever the chat may be written in. */
|
|
3275
3281
|
...(!DEVICE || deviceParts.chat === 'write' ? { react: (to, reaction) => post(talkPath(name, '/react'), { to, reaction }) } : {}),
|
|
3282
|
+
/* A message pinned at the top of the chat (5 at most, either side): wherever the chat may be written in. */
|
|
3283
|
+
...(!DEVICE || deviceParts.chat === 'write' ? { pin: (to, on) => post(talkPath(name, '/pin'), { to, on }) } : {}),
|
|
3276
3284
|
/* A message attached to a card (#180), from its menu: its id, as the card opens it again. */
|
|
3277
3285
|
...(!DEVICE ? { card: (m) => attachToCard({ kind: 'message', ref: m.id, title: String(m.short || m.text || '').replace(/\s+/g, ' ').trim().slice(0, 80) }) } : {}),
|
|
3278
3286
|
/* The buttons of a line of the machine: what this screen may do. */
|
|
@@ -7263,7 +7271,7 @@
|
|
|
7263
7271
|
if ($('settings-wifi-top').open) void paintWifi();
|
|
7264
7272
|
if ($('settings-mesh-top').open) void paintScreen();
|
|
7265
7273
|
if ($('settings-usage-top').open) void paintUsage();
|
|
7266
|
-
await Promise.all([paintHosts(), paintShelf(), paintServer(), paintUpdates()]);
|
|
7274
|
+
await Promise.all([paintHosts(), paintShelf(), paintServer(), paintUpdates(), paintMachines()]);
|
|
7267
7275
|
await paintSettingsStates();
|
|
7268
7276
|
}
|
|
7269
7277
|
|
|
@@ -8500,6 +8508,87 @@
|
|
|
8500
8508
|
try { await post(`${API}/server/reserve`, { diskMb, diskPercent, memoryMb, memoryPercent }); $('reserve-saved').textContent = 'Saved.'; } catch (error) { $('reserve-error').textContent = error.message; $('reserve-error').hidden = false; return; }
|
|
8501
8509
|
await paintServer(); void paintGauge();
|
|
8502
8510
|
});
|
|
8511
|
+
/* SETTINGS, MACHINES (server/machinelist.mjs): each machine, its state, the memory its qemu holds, since
|
|
8512
|
+
when, and Force stop (confirmed here); the machine manager, and Restart the manager (confirmed: every
|
|
8513
|
+
machine is resumed); what is done when it hangs, and when memory is short. */
|
|
8514
|
+
const ML_STATE = { Running: ['set-ml-running', 'Running', 'ok'], Suspended: ['set-ml-asleep', 'Asleep', 'ok'], Stopped: ['set-ml-stopped', 'Stopped', 'ok'],
|
|
8515
|
+
Starting: ['set-ml-starting', 'Starting', 'warn'], Stopping: ['set-ml-stopping', 'Stopping', 'warn'], Unknown: ['set-ml-unknown', 'Unknown', 'warn'], Gone: ['set-ml-gone', 'Gone', 'bad'] };
|
|
8516
|
+
const sinceSaid = (iso) => {
|
|
8517
|
+
const d = new Date(iso);
|
|
8518
|
+
const today = d.toDateString() === new Date().toDateString();
|
|
8519
|
+
return uiSaid('set-ml-since', 'since {t}', { t: today ? d.toLocaleTimeString([], { timeStyle: 'short' }) : d.toLocaleDateString([], { day: 'numeric', month: 'short' }) });
|
|
8520
|
+
};
|
|
8521
|
+
let machinesAsk = null;
|
|
8522
|
+
let machinesTimer;
|
|
8523
|
+
async function paintMachines() {
|
|
8524
|
+
clearTimeout(machinesTimer);
|
|
8525
|
+
if (DEVICE) { $('settings-ch-machines').hidden = true; return; }
|
|
8526
|
+
const r = await fetch(`${API}/server/machines`).then((x) => (x.ok ? x.json() : null)).catch(() => null);
|
|
8527
|
+
$('settings-ch-machines').hidden = !r;
|
|
8528
|
+
if (!r) return;
|
|
8529
|
+
const running = r.machines.filter((m) => m.state === 'Running').length;
|
|
8530
|
+
chapterNow('s-machines', uiSaid('set-ml-now', '{n} running of {all}', { n: running, all: r.machines.length }));
|
|
8531
|
+
const rows = $('machines-rows'); rows.replaceChildren();
|
|
8532
|
+
$('machines-none').hidden = r.machines.length > 0;
|
|
8533
|
+
for (const m of r.machines) {
|
|
8534
|
+
const row = el('div', 'list-item machine-item'); row.dataset.name = m.name;
|
|
8535
|
+
const [key, en, tone] = ML_STATE[m.state] ?? ['set-ml-unknown', m.state, 'warn'];
|
|
8536
|
+
const what = el('div', 'set-what');
|
|
8537
|
+
what.append(el('b', '', machineTitle(m.name)));
|
|
8538
|
+
const line = el('small', 'status-line'); line.dataset.tone = tone;
|
|
8539
|
+
line.textContent = [m.action ? uiSaid('set-ml-busy', 'Busy') : uiSaid(key, en), m.rssMb > 0 ? GB(m.rssMb) : '', m.since ? sinceSaid(m.since) : ''].filter(Boolean).join(' · ');
|
|
8540
|
+
what.append(line);
|
|
8541
|
+
const acts = el('div', 'set-control');
|
|
8542
|
+
const force = el('button', 'danger', uiSaid('set-m-force', 'Force stop')); force.type = 'button'; force.dataset.act = 'force';
|
|
8543
|
+
force.disabled = m.state === 'Stopped' || m.state === 'Gone';
|
|
8544
|
+
force.addEventListener('click', () => askMachines({ kind: 'force', name: m.name }));
|
|
8545
|
+
acts.append(force);
|
|
8546
|
+
row.append(what, acts);
|
|
8547
|
+
rows.append(row);
|
|
8548
|
+
}
|
|
8549
|
+
/* The machine manager: does it answer, since when not, waiting for its owner, the last restart. */
|
|
8550
|
+
const g = r.manager;
|
|
8551
|
+
const ml = $('manager-line');
|
|
8552
|
+
if (g) {
|
|
8553
|
+
ml.dataset.tone = g.reviving ? 'warn' : g.ok ? 'ok' : 'bad';
|
|
8554
|
+
ml.textContent = g.reviving ? uiSaid('set-ml-reviving', 'Restarting…')
|
|
8555
|
+
: g.ok ? [uiSaid('set-ml-answers', 'Answers'), g.last?.at ? uiSaid('set-ml-last', 'restarted {t}', { t: agoSaid(g.last.at) }) : ''].filter(Boolean).join(' · ')
|
|
8556
|
+
: [uiSaid('set-ml-mute', 'Not answering'), g.downSince ? sinceSaid(g.downSince) : '', g.asked ? uiSaid('set-ml-asked', 'waits for you') : ''].filter(Boolean).join(' · ');
|
|
8557
|
+
$('manager-restart').disabled = Boolean(g.reviving);
|
|
8558
|
+
$('manager-restart').classList.toggle('primary', Boolean(g.asked));
|
|
8559
|
+
for (const b of $('manager-mode').children) b.setAttribute('aria-pressed', String(b.dataset.mode === g.mode));
|
|
8560
|
+
}
|
|
8561
|
+
$('manager-row').hidden = !g;
|
|
8562
|
+
for (const b of $('pressure-way').children) b.setAttribute('aria-pressed', String(b.dataset.way === r.pressure));
|
|
8563
|
+
/* While it is in sight and something moves (an action, a restart of the manager): looked at again. */
|
|
8564
|
+
if ($('settings-ch-machines').open && !$('settings').hidden && (g?.reviving || r.machines.some((m) => m.action))) machinesTimer = setTimeout(() => { void paintMachines(); }, 3000);
|
|
8565
|
+
}
|
|
8566
|
+
/* Asked in the page, in one line: what is lost. */
|
|
8567
|
+
function askMachines(ask) {
|
|
8568
|
+
machinesAsk = ask;
|
|
8569
|
+
$('machines-confirm-text').textContent = ask.kind === 'force'
|
|
8570
|
+
? uiSaid('set-ml-force-q', 'Force stop {name}? Nothing is saved.', { name: machineTitle(ask.name) })
|
|
8571
|
+
: uiSaid('set-ml-revive-q', 'Restart the manager? All machines are resumed.');
|
|
8572
|
+
$('machines-confirm-yes').textContent = ask.kind === 'force' ? uiSaid('set-m-force', 'Force stop') : uiSaid('set-ml-revive-yes', 'Restart');
|
|
8573
|
+
$('machines-confirm').hidden = false;
|
|
8574
|
+
$('machines-confirm-yes').focus();
|
|
8575
|
+
}
|
|
8576
|
+
async function machinesPost(path, body) {
|
|
8577
|
+
$('machines-error').hidden = true;
|
|
8578
|
+
try { await post(`${API}${path}`, body); } catch (error) { $('machines-error').textContent = error.message; $('machines-error').hidden = false; }
|
|
8579
|
+
await paintMachines();
|
|
8580
|
+
}
|
|
8581
|
+
$('machines-confirm-no').addEventListener('click', () => { machinesAsk = null; $('machines-confirm').hidden = true; });
|
|
8582
|
+
$('machines-confirm-yes').addEventListener('click', () => {
|
|
8583
|
+
const ask = machinesAsk; machinesAsk = null; $('machines-confirm').hidden = true;
|
|
8584
|
+
if (!ask) return;
|
|
8585
|
+
if (ask.kind === 'force') void machinesPost(`/server/machines/${encodeURIComponent(ask.name)}/force`, {});
|
|
8586
|
+
else { $('manager-restart').disabled = true; $('manager-line').dataset.tone = 'warn'; $('manager-line').textContent = uiSaid('set-ml-reviving', 'Restarting…'); void machinesPost('/server/vm-manager/restart', { confirm: true }); }
|
|
8587
|
+
});
|
|
8588
|
+
$('manager-restart').addEventListener('click', () => askMachines({ kind: 'revive' }));
|
|
8589
|
+
for (const b of $('manager-mode').children) b.addEventListener('click', () => void machinesPost('/server/vm-manager', { mode: b.dataset.mode }));
|
|
8590
|
+
for (const b of $('pressure-way').children) b.addEventListener('click', () => void machinesPost('/server/pressure', { way: b.dataset.way }));
|
|
8591
|
+
$('settings-ch-machines').addEventListener('toggle', () => { if ($('settings-ch-machines').open) void paintMachines(); });
|
|
8503
8592
|
/* THE SMALL GAUGE at the bottom of the list: only when disk or memory is
|
|
8504
8593
|
short. A click opens Settings, at This server. */
|
|
8505
8594
|
async function paintGauge() {
|
|
@@ -11663,6 +11752,39 @@
|
|
|
11663
11752
|
catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
|
|
11664
11753
|
});
|
|
11665
11754
|
}
|
|
11755
|
+
/* ITS WATCHDOG (server/watchdog.mjs): Off, 30 min, 1 h (the default), 2 h, or minutes of its own. */
|
|
11756
|
+
const DOG_CHOICES = [30, 60, 120];
|
|
11757
|
+
function paintWatchdog(here) {
|
|
11758
|
+
const on = here?.watchdog?.on !== false;
|
|
11759
|
+
const min = Number.isInteger(here?.watchdog?.delayMin) ? here.watchdog.delayMin : 60;
|
|
11760
|
+
const custom = on && !DOG_CHOICES.includes(min);
|
|
11761
|
+
if ($('m-dog').dataset.of !== (here?.name ?? '')) { $('m-dog').dataset.of = here?.name ?? ''; $('m-dog').dataset.custom = 'false'; }
|
|
11762
|
+
const choosing = $('m-dog').dataset.custom === 'true';
|
|
11763
|
+
for (const b of $('m-dog').children) {
|
|
11764
|
+
const pressed = b.dataset.min === '0' ? !on : b.dataset.min === 'custom' ? custom || (on && choosing) : on && !choosing && Number(b.dataset.min) === min;
|
|
11765
|
+
b.setAttribute('aria-pressed', String(pressed));
|
|
11766
|
+
}
|
|
11767
|
+
$('m-dog-custom').hidden = !(custom || (on && choosing));
|
|
11768
|
+
if (document.activeElement !== $('m-dog-min')) $('m-dog-min').value = String(min);
|
|
11769
|
+
}
|
|
11770
|
+
async function setWatchdog(watchdog) {
|
|
11771
|
+
$('panel-error').hidden = true;
|
|
11772
|
+
try { await post(`${API}/conversations/${encodeURIComponent(current)}/machine`, { watchdog }); await refresh(); paintMachine(conversations.find((x) => x.name === current)); }
|
|
11773
|
+
catch (error) { $('panel-error').textContent = error.message; $('panel-error').hidden = false; }
|
|
11774
|
+
}
|
|
11775
|
+
for (const b of $('m-dog').children) {
|
|
11776
|
+
b.addEventListener('click', () => {
|
|
11777
|
+
const m = b.dataset.min;
|
|
11778
|
+
$('m-dog').dataset.custom = String(m === 'custom');
|
|
11779
|
+
if (m === 'custom') { paintWatchdog({ ...conversations.find((x) => x.name === current), watchdog: { on: true, delayMin: Number($('m-dog-min').value) || 60 } }); $('m-dog-min').focus(); return; }
|
|
11780
|
+
void setWatchdog(m === '0' ? { on: false } : { on: true, delayMin: Number(m) });
|
|
11781
|
+
});
|
|
11782
|
+
}
|
|
11783
|
+
$('m-dog-min').addEventListener('change', () => {
|
|
11784
|
+
const n = Math.round(Number($('m-dog-min').value));
|
|
11785
|
+
if (!Number.isFinite(n)) return;
|
|
11786
|
+
void setWatchdog({ on: true, delayMin: Math.min(1440, Math.max(10, n)) });
|
|
11787
|
+
});
|
|
11666
11788
|
/* The quick actions at the top of the panel do the same as the Machine chapter's. */
|
|
11667
11789
|
$('hand-terminal').addEventListener('click', () => { leavePanel(); seeTerminal(); });
|
|
11668
11790
|
$('quick-wake').addEventListener('click', () => { leavePanel(); seeTerminal(); });
|
package/web/index.html
CHANGED
|
@@ -137,7 +137,6 @@
|
|
|
137
137
|
<button type="button" id="m-stop" data-said="set-m-stop">Stop</button>
|
|
138
138
|
<button type="button" id="restart" data-said="set-restart-dots">Restart…</button>
|
|
139
139
|
<button type="button" id="sleep" title="Freezes the tool as it is; it wakes when you open the conversation" data-said="set-sleep">Sleep</button>
|
|
140
|
-
<button type="button" id="m-force" class="danger" data-said="set-m-force">Force stop</button>
|
|
141
140
|
<button type="button" id="hand-terminal" data-said="set-terminal">Terminal</button>
|
|
142
141
|
</div>
|
|
143
142
|
<!-- Asked in the page, in one line: what is lost. -->
|
|
@@ -145,6 +144,11 @@
|
|
|
145
144
|
<!-- The action under way, step by step (the escalation, in one line), then its report. -->
|
|
146
145
|
<div id="m-live" class="m-live" hidden></div>
|
|
147
146
|
<p id="m-report" class="hint m-report" role="status" hidden></p>
|
|
147
|
+
<!-- THE DANGEROUS ONE, APART (10-11): away from the buttons of every day, said what it does, confirmed here. -->
|
|
148
|
+
<div id="m-danger" class="m-danger" hidden>
|
|
149
|
+
<span class="m-danger-title" data-said="set-mdanger-title">If the machine is stuck</span>
|
|
150
|
+
<div class="m-danger-row"><button type="button" id="m-force" class="danger" data-said="set-m-force">Force stop</button><span class="hint" data-said="set-mwhat-force">Cuts it off, like a power cut</span></div>
|
|
151
|
+
</div>
|
|
148
152
|
</section>
|
|
149
153
|
<nav id="panel-tabs" class="settings-tabs" role="tablist" aria-label="Categories of its settings">
|
|
150
154
|
<button type="button" role="tab" data-group="general" data-said="set-tab-general">General</button>
|
|
@@ -205,6 +209,8 @@
|
|
|
205
209
|
</div>
|
|
206
210
|
<!-- A STOP THAT HANGS: forced by itself (the default), or asked first (conversations.mjs, stopEscalate). -->
|
|
207
211
|
<div class="set-row"><div class="set-what"><b data-said="set-mesc">If a stop hangs</b></div><div class="set-control"><div class="levels" id="m-escalate" role="group" aria-label="If a stop hangs"><button type="button" data-on="true" data-said="set-mesc-auto">Force it</button><button type="button" data-on="false" data-said="set-mesc-ask">Ask me</button></div></div></div>
|
|
212
|
+
<!-- ITS WATCHDOG (server/watchdog.mjs): mute or full that long, forced off then started, once. -->
|
|
213
|
+
<div class="set-row" id="m-dog-row"><div class="set-what"><b data-said="set-mdog">Watchdog</b><small data-said="set-mdog-what">Restarts it if stuck</small></div><div class="set-control"><div class="levels" id="m-dog" role="group" aria-label="Watchdog"><button type="button" data-min="0" data-said="set-mdog-off">Off</button><button type="button" data-min="30">30 min</button><button type="button" data-min="60">1 h</button><button type="button" data-min="120">2 h</button><button type="button" data-min="custom" data-said="set-mdog-custom">Custom</button></div><label class="m-dog-min" id="m-dog-custom" hidden><input type="number" id="m-dog-min" min="10" max="1440" step="5" inputmode="numeric" aria-label="Minutes"> min</label></div></div>
|
|
208
214
|
<div class="panel-top"><b>Memory, cores and disk</b></div>
|
|
209
215
|
<form id="machine-size" autocomplete="off">
|
|
210
216
|
<label for="machine-memory">Memory</label>
|
|
@@ -1057,7 +1063,7 @@
|
|
|
1057
1063
|
<span class="hint" id="reserve-saved" role="status"></span>
|
|
1058
1064
|
</div>
|
|
1059
1065
|
<p class="server-note" id="reserve-now"></p>
|
|
1060
|
-
<p class="hint"><span>The larger of the two</span><span class="tip" hidden>No machine is created, started or enlarged into it. Below it you are alerted and the largest running machine is
|
|
1066
|
+
<p class="hint"><span>The larger of the two</span><span class="tip" hidden>No machine is created, started or enlarged into it. Below it you are alerted, and the largest running machine is forced off (Machines). Waking is always allowed, to clean up.</span></p>
|
|
1061
1067
|
<p class="server-note promised" id="promised-disk" hidden></p>
|
|
1062
1068
|
<p class="server-note promised" id="promised-memory" hidden></p>
|
|
1063
1069
|
<p id="reserve-error" class="error" role="alert" hidden></p>
|
|
@@ -1067,6 +1073,23 @@
|
|
|
1067
1073
|
(server/updates.mjs; the updater, as root: deploy/updater.mjs). -->
|
|
1068
1074
|
</div>
|
|
1069
1075
|
</details>
|
|
1076
|
+
<!-- MACHINES (server/machinelist.mjs): each one, its state, the memory its qemu holds, since when, and
|
|
1077
|
+
Force stop; the machine manager, restarted when confirmed; what is done when it hangs, when memory is short. -->
|
|
1078
|
+
<details class="chapter" id="settings-ch-machines" data-chapter="s-machines">
|
|
1079
|
+
<summary><span class="chapter-title" data-said="set-ch-s-machines">Machines</span><span class="chapter-about" data-said="set-ml-about">State and memory.</span></summary>
|
|
1080
|
+
<div class="chapter-body">
|
|
1081
|
+
<div id="machines-rows"></div>
|
|
1082
|
+
<p id="machines-none" class="hint" data-said="set-ml-none" hidden>No machine yet</p>
|
|
1083
|
+
<div id="machines-confirm" class="callout confirm" role="alertdialog" aria-labelledby="machines-confirm-text" hidden>
|
|
1084
|
+
<b id="machines-confirm-text"></b>
|
|
1085
|
+
<div class="action-row"><button type="button" id="machines-confirm-no" data-said="set-mconf-no">Cancel</button><button type="button" id="machines-confirm-yes" class="danger"></button></div>
|
|
1086
|
+
</div>
|
|
1087
|
+
<div class="set-row" id="manager-row"><div class="set-what"><b data-said="set-ml-manager">Machine manager</b><p class="status-line" id="manager-line" role="status"></p></div><div class="set-control"><button type="button" id="manager-restart" data-said="set-ml-revive">Restart the manager</button></div></div>
|
|
1088
|
+
<div class="set-row"><div class="set-what"><b data-said="set-ml-hang">If it hangs</b><small data-said="set-ml-hang-what">Night: 0 to 7 h</small></div><div class="set-control"><div class="levels" id="manager-mode" role="group" aria-label="If it hangs"><button type="button" data-mode="night" data-said="set-ml-night">At night</button><button type="button" data-mode="always" data-said="set-ml-always">Always</button><button type="button" data-mode="ask" data-said="set-ml-ask">Ask me</button></div></div></div>
|
|
1089
|
+
<div class="set-row"><div class="set-what"><b data-said="set-ml-short">Memory short</b><small data-said="set-ml-short-what">The largest machine</small></div><div class="set-control"><div class="levels" id="pressure-way" role="group" aria-label="Memory short"><button type="button" data-way="force" data-said="set-ml-force">Force stop</button><button type="button" data-way="sleep" data-said="set-ml-sleep">Sleep</button><button type="button" data-way="alert" data-said="set-ml-alert">Alert only</button></div></div></div>
|
|
1090
|
+
<p id="machines-error" class="error" role="alert" hidden></p>
|
|
1091
|
+
</div>
|
|
1092
|
+
</details>
|
|
1070
1093
|
</section>
|
|
1071
1094
|
<section class="settings-group" id="settings-group-access" data-group="access" role="tabpanel" aria-label="Access">
|
|
1072
1095
|
<!-- WHO MAY SIGN IN (server/operators.mjs): hidden on this machine alone. -->
|
package/web/style.css
CHANGED
|
@@ -2990,6 +2990,12 @@ button.kit-switch[aria-checked="true"]::after { left: 18px; background: var(--ok
|
|
|
2990
2990
|
two ways to hurry it right under. A list down the page on a phone. */
|
|
2991
2991
|
.m-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: .875rem; }
|
|
2992
2992
|
.m-confirm[hidden], .m-live[hidden], .m-report[hidden] { display: none; }
|
|
2993
|
+
/* Force stop, apart from the buttons of every day (10-11). */
|
|
2994
|
+
.m-danger { display: grid; gap: 6px; margin-top: 14px; padding: 10px 12px; border: 1px dashed var(--danger); border-radius: 10px; background: color-mix(in srgb, var(--danger) 8%, transparent); }
|
|
2995
|
+
.m-danger[hidden] { display: none; }
|
|
2996
|
+
.m-danger-title { font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--danger); }
|
|
2997
|
+
.m-danger-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
|
|
2998
|
+
.m-danger-row .hint { margin: 0; }
|
|
2993
2999
|
.m-confirm span { flex: 1 1 14rem; }
|
|
2994
3000
|
.m-live { display: grid; gap: 8px; margin-top: 10px; justify-items: start; }
|
|
2995
3001
|
#notice .m-live { justify-items: center; margin: 0; }
|
|
@@ -3012,3 +3018,10 @@ button.kit-switch[aria-checked="true"]::after { left: 18px; background: var(--ok
|
|
|
3012
3018
|
.mstep li.arr { display: none; }
|
|
3013
3019
|
#notice .m-live { justify-items: stretch; }
|
|
3014
3020
|
}
|
|
3021
|
+
|
|
3022
|
+
/* ITS WATCHDOG's own minutes (a conversation's Machine chapter), and SETTINGS, MACHINES (machinelist.mjs). */
|
|
3023
|
+
.m-dog-min { display: inline-flex; align-items: center; gap: 6px; font-size: .875rem; color: var(--ink2); }
|
|
3024
|
+
.m-dog-min input { width: 5.5em; min-height: 40px; font: .875rem var(--sans); color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; }
|
|
3025
|
+
.list-item.machine-item > .set-what > small.status-line { font-size: .75rem; margin: 0; }
|
|
3026
|
+
#manager-row .status-line { margin: 2px 0 0; font-size: .75rem; }
|
|
3027
|
+
#machines-confirm { margin: 8px 16px; }
|