clavarium 0.2.299-next.1 → 0.2.300-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deploy/clavarium-host +30 -0
- package/deploy/maintenance.html +5 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/api.mjs +2 -1
- package/server/events.mjs +1 -0
- package/server/main.mjs +3 -0
- package/server/serverlogs.mjs +6 -0
- package/web/app.js +14 -11
- package/web/index.html +2 -1
package/deploy/clavarium-host
CHANGED
|
@@ -994,6 +994,36 @@ case "$AREA $VERB" in
|
|
|
994
994
|
if [ "$SAY" = "yes" ]; then echo "systemd-run --on-active=2 systemctl restart clavarium.service"; exit 0; fi
|
|
995
995
|
systemd-run --quiet --collect --unit="clavarium-restart-$(date +%s)" --on-active=2 /usr/bin/systemctl restart clavarium.service
|
|
996
996
|
exit 0 ;;
|
|
997
|
+
"server reboot")
|
|
998
|
+
# THE WHOLE SERVER STARTED AGAIN, asked from the page (Settings, This server), after a
|
|
999
|
+
# confirmation there: in five seconds, by systemd, so that the page is answered first.
|
|
1000
|
+
# Every machine stops with it (cleanly, by the VM manager) and starts again after.
|
|
1001
|
+
[ $# -eq 0 ] || usage
|
|
1002
|
+
if [ "$SAY" = "yes" ]; then echo "systemd-run --on-active=5 systemctl reboot"; exit 0; fi
|
|
1003
|
+
systemd-run --quiet --collect --unit="clavarium-reboot-$(date +%s)" --on-active=5 /usr/bin/systemctl reboot
|
|
1004
|
+
exit 0 ;;
|
|
1005
|
+
"server protect")
|
|
1006
|
+
# WHAT KEEPS THE SERVER IN HAND (04-11), at each start of the server: should memory run out,
|
|
1007
|
+
# the kernel stops a machine first, never this server, its front or ssh. Made so for the next
|
|
1008
|
+
# start of each (a drop-in) and at once for what runs (choom). No argument; done again is the same.
|
|
1009
|
+
[ $# -eq 0 ] || usage
|
|
1010
|
+
if [ "$SAY" = "yes" ]; then echo "OOMScoreAdjust=-900 for clavarium caddy dex oauth2-proxy ssh"; exit 0; fi
|
|
1011
|
+
changed=no
|
|
1012
|
+
for unit in clavarium caddy dex oauth2-proxy ssh; do
|
|
1013
|
+
systemctl cat "$unit.service" >/dev/null 2>&1 || continue
|
|
1014
|
+
dir="/etc/systemd/system/$unit.service.d"; file="$dir/clavarium-oom.conf"
|
|
1015
|
+
want='# Written by clavarium-host (server protect): stopped last should memory run out.
|
|
1016
|
+
[Service]
|
|
1017
|
+
OOMScoreAdjust=-900'
|
|
1018
|
+
if [ "$(cat "$file" 2>/dev/null)" != "$want" ]; then
|
|
1019
|
+
mkdir -p "$dir" && printf '%s\n' "$want" > "$file" && changed=yes
|
|
1020
|
+
fi
|
|
1021
|
+
pid=$(systemctl show -p MainPID --value "$unit.service" 2>/dev/null)
|
|
1022
|
+
[ -n "$pid" ] && [ "$pid" != 0 ] && choom -n -900 -p "$pid" >/dev/null 2>&1 || true
|
|
1023
|
+
done
|
|
1024
|
+
[ "$changed" = no ] || systemctl daemon-reload
|
|
1025
|
+
echo "protected"
|
|
1026
|
+
exit 0 ;;
|
|
997
1027
|
"server room")
|
|
998
1028
|
# WHAT THE SERVER HAS LEFT, for Settings (This server) and for the
|
|
999
1029
|
# reserve that creating, starting, waking or growing a machine must
|
package/deploy/maintenance.html
CHANGED
|
@@ -56,17 +56,20 @@ const VERSION = /^\d{1,4}\.\d{1,4}\.\d{1,6}(-[0-9A-Za-z.-]{1,40})?$/;
|
|
|
56
56
|
when the server still announces an update about to stop it. */
|
|
57
57
|
const next = ({ kind, startedAt, now, seenDown, answer }) => {
|
|
58
58
|
const up = !!answer && !answer.down && !answer.update && !(answer.status >= 502 && answer.status <= 504);
|
|
59
|
-
|
|
59
|
+
/* The whole server (reboot): five seconds before it stops, a minute of grace. */
|
|
60
|
+
const grace = kind === 'reboot' ? 4 * RESTART_GRACE_MS : kind === 'restart' ? RESTART_GRACE_MS : 0;
|
|
61
|
+
if (up && !(grace && !seenDown && now - startedAt < grace)) return 'back';
|
|
60
62
|
return now - startedAt > STUCK_MS ? 'stuck' : 'wait';
|
|
61
63
|
};
|
|
62
64
|
|
|
63
|
-
/* WHAT IT SAYS, from its address (?kind=update|back|restart&to=<version>): the edge serves
|
|
65
|
+
/* WHAT IT SAYS, from its address (?kind=update|back|restart|reboot&to=<version>): the edge serves
|
|
64
66
|
it at any address, with none of these: then it cannot know which. */
|
|
65
67
|
const title = (kind, to) => {
|
|
66
68
|
const v = VERSION.test(to ?? '') ? to : '';
|
|
67
69
|
if (kind === 'update') return v ? `Updating Clavarium to ${v}...` : 'Updating Clavarium...';
|
|
68
70
|
if (kind === 'back') return v ? `Going back to Clavarium ${v}...` : 'Going back to the previous Clavarium...';
|
|
69
71
|
if (kind === 'restart') return 'Restarting Clavarium...';
|
|
72
|
+
if (kind === 'reboot') return 'Restarting the server: every machine starts again in a few minutes...';
|
|
70
73
|
return 'Clavarium is being updated or restarted...';
|
|
71
74
|
};
|
|
72
75
|
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.300-next.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.300-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/api.mjs
CHANGED
|
@@ -109,7 +109,7 @@
|
|
|
109
109
|
* GET /api/history?of=server|<name>&span=1h|24h|7d the curves of memory, CPU and disk (and the reserve, for the server)
|
|
110
110
|
* GET /api/history/all?span=1h|24h|7d Settings, Usage: the server and every machine (asleep too) on one time axis,
|
|
111
111
|
* in GB and cores: {t, capacity, server, itself, machines: [{name, alloc, asleep, ...}]}
|
|
112
|
-
* GET /api/server/logs?source=&span= what the server's programs said POST /api/server/restart
|
|
112
|
+
* GET /api/server/logs?source=&span= what the server's programs said POST /api/server/restart POST /api/server/reboot (the whole server)
|
|
113
113
|
* GET /api/operators who may sign in POST /api/operators {email} -> {email, password}: shown once
|
|
114
114
|
* POST /api/operators/<email>/password -> {email, password} POST /api/operators/<email>/disable|enable|remove
|
|
115
115
|
* POST /api/conversations/<name>/secrets {secret, attached}
|
|
@@ -552,6 +552,7 @@ export async function handleApi(request, response, conversations, headers, resou
|
|
|
552
552
|
if (reactSet && reacting) { const n = decodeURIComponent(reactSet[1]); if (!conversations.list().some((c) => c.name === n)) throw new Refusal(404, 'No such conversation.'); return send(200, reacting.set(n, body)), true; }
|
|
553
553
|
if (pathname === '/api/machines/move' && machinesMove) return send(202, await machinesMove.move(String(body.to ?? ''))), true;
|
|
554
554
|
if (pathname === '/api/server/restart' && serverLogs) return send(202, await serverLogs.restart()), true;
|
|
555
|
+
if (pathname === '/api/server/reboot' && serverLogs) return send(202, await serverLogs.reboot()), true;
|
|
555
556
|
if (pathname === '/api/machines/grow' && machinesMove) return send(200, await machinesMove.grow(String(body.mount ?? ''))), true;
|
|
556
557
|
if (pathname === '/api/machines/mount' && machinesMove) return send(200, await machinesMove.mount(String(body.path ?? ''))), true;
|
|
557
558
|
if (pathname === '/api/machines/prepare' && machinesMove) return send(200, await machinesMove.prepare(String(body.path ?? ''), body.typed)), true;
|
package/server/events.mjs
CHANGED
|
@@ -51,6 +51,7 @@ const SAID = [
|
|
|
51
51
|
[/^\/api\/updates\/back$/, 'update', (m, b) => `Going back to ${clip(b.version, 30)} asked`],
|
|
52
52
|
[/^\/api\/updates\/settings$/, 'update', (m, b) => `Updates set: ${['mode', 'channel', 'window'].filter((k) => b[k]).map((k) => `${k} ${clip(b[k], 20)}`).join(', ')}`],
|
|
53
53
|
[/^\/api\/server\/restart$/, 'server', () => 'This server restarted'],
|
|
54
|
+
[/^\/api\/server\/reboot$/, 'server', () => 'The whole server restarted'],
|
|
54
55
|
[/^\/api\/server\/reserve$/, 'server', (m, b) => `Reserve set${b.diskMb !== undefined ? `: disk ${b.diskMb} MB` : ''}${b.memoryMb !== undefined ? `, memory ${b.memoryMb} MB` : ''}`],
|
|
55
56
|
[/^\/api\/machines\/move$/, 'server', (m, b) => `All the machines moved to ${clip(b.to, 60)}`],
|
|
56
57
|
[/^\/api\/machines\/prepare$/, 'server', (m, b) => `Disk ${clip(b.path, 40)} erased and prepared for the machines`],
|
package/server/main.mjs
CHANGED
|
@@ -325,6 +325,9 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
325
325
|
/* Not in place is said, not fatal: no machine is then given /tools. */
|
|
326
326
|
await toolbox.prepare().catch((error) => console.error(error.message));
|
|
327
327
|
await Promise.resolve(all.ensureWork?.()).catch((error) => console.error(`work folders: ${error.message}`));
|
|
328
|
+
/* Should memory run out, a machine is stopped first, never this server, its front or ssh (04-11). */
|
|
329
|
+
const kept = await asHost(['server', 'protect'], { timeoutMs: 30_000 }).catch(() => ({ code: 1, stderr: 'not run' }));
|
|
330
|
+
if (kept.code) console.error(`protect: ${String(kept.stderr ?? '').trim() || `exit ${kept.code}`}`);
|
|
328
331
|
})();
|
|
329
332
|
const bounded = (promise, ms, what) => {
|
|
330
333
|
let timer;
|
package/server/serverlogs.mjs
CHANGED
|
@@ -67,4 +67,10 @@ export class ServerLogs {
|
|
|
67
67
|
if (r.code !== 0) throw new Refusal(502, `This server could not be started again: ${String(r.stderr ?? '').trim().split('\n').pop()?.slice(0, 200) || `exit ${r.code}`}`);
|
|
68
68
|
return { restarting: true };
|
|
69
69
|
}
|
|
70
|
+
/* THE WHOLE SERVER STARTED AGAIN (04-11): its machines stop with it and start again after. */
|
|
71
|
+
async reboot() {
|
|
72
|
+
const r = await this.#host(['server', 'reboot']);
|
|
73
|
+
if (r.code !== 0) throw new Refusal(502, `This server could not be restarted: ${String(r.stderr ?? '').trim().split('\n').pop()?.slice(0, 200) || `exit ${r.code}`}`);
|
|
74
|
+
return { rebooting: true };
|
|
75
|
+
}
|
|
70
76
|
}
|
package/web/app.js
CHANGED
|
@@ -6630,17 +6630,20 @@
|
|
|
6630
6630
|
document.body.append(a); a.click(); a.remove();
|
|
6631
6631
|
setTimeout(() => URL.revokeObjectURL(a.href), 60_000);
|
|
6632
6632
|
});
|
|
6633
|
-
/*
|
|
6634
|
-
|
|
6635
|
-
|
|
6636
|
-
|
|
6637
|
-
|
|
6638
|
-
|
|
6639
|
-
|
|
6640
|
-
|
|
6641
|
-
|
|
6642
|
-
|
|
6643
|
-
|
|
6633
|
+
/* CLAVARIUM, OR THE WHOLE SERVER, STARTED AGAIN: asked twice (the second says what it does).
|
|
6634
|
+
Clavarium: its program only, machines go on. The server (04-11): every machine stops with it. */
|
|
6635
|
+
for (const [id, path, kind, sure, label] of [['server-restart', 'restart', 'restart', 'Yes: restart Clavarium now', 'Restart Clavarium...'], ['server-reboot', 'reboot', 'reboot', 'Yes: stop every machine and restart the server', 'Restart the server...']]) {
|
|
6636
|
+
$(id).addEventListener('click', () => {
|
|
6637
|
+
const go = $(id);
|
|
6638
|
+
if (go.dataset.sure !== 'yes') { go.dataset.sure = 'yes'; go.textContent = sure; return; }
|
|
6639
|
+
go.disabled = true;
|
|
6640
|
+
void post(`${API}/server/${path}`, {}).then(() => {
|
|
6641
|
+
$(`${id}-said`).textContent = 'Restarting: this page comes back by itself.';
|
|
6642
|
+
/* The maintenance page waits for it (it answers a moment more before it stops), then comes back here. */
|
|
6643
|
+
location.replace(`/maintenance.html?${new URLSearchParams({ kind, back: location.pathname + location.search })}`);
|
|
6644
|
+
}).catch((error) => { $(`${id}-said`).textContent = error.message; go.disabled = false; delete go.dataset.sure; go.textContent = label; });
|
|
6645
|
+
});
|
|
6646
|
+
}
|
|
6644
6647
|
/* THE CURVES (server/history.mjs): memory, CPU and disk over time, one small chart each, one
|
|
6645
6648
|
line each on one scale (0 to 100 %); the reserve as a dotted level; a dot where a program
|
|
6646
6649
|
was stopped for lack of memory. Hovered or touched: the value and the time under it. */
|
package/web/index.html
CHANGED
|
@@ -1188,7 +1188,8 @@
|
|
|
1188
1188
|
<div class="row" id="logs-acts" hidden><button type="button" id="logs-copy">Copy all</button><button type="button" id="logs-save">Download</button></div>
|
|
1189
1189
|
<pre id="logs-text" class="logs-text" tabindex="0" hidden></pre>
|
|
1190
1190
|
<p class="hint">Secrets are masked. Newest at the bottom.</p>
|
|
1191
|
-
<div class="set-row"><div class="set-what"><span>Restart
|
|
1191
|
+
<div class="set-row"><div class="set-what"><span>Restart Clavarium</span><small id="server-restart-said" role="status">A few seconds; machines keep running</small></div><div class="set-control"><button type="button" class="danger" id="server-restart">Restart Clavarium...</button></div></div>
|
|
1192
|
+
<div class="set-row"><div class="set-what"><span>Restart the server</span><small id="server-reboot-said" role="status">A few minutes; every machine stops and starts again</small></div><div class="set-control"><button type="button" class="danger" id="server-reboot">Restart the server...</button></div></div>
|
|
1192
1193
|
</div>
|
|
1193
1194
|
</details>
|
|
1194
1195
|
<details class="chapter" id="settings-ch-about" data-chapter="s-about">
|