Add Plutonium version checks and scheduled rolling restarts

This commit is contained in:
2026-09-21 18:47:24 -04:00
parent 424d6cefb6
commit 47d6dc07b7
10 changed files with 583 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
import { json } from '@sveltejs/kit';
import { cancelMaintenance, checkPlutonium, plutoniumStatus, queueMaintenance, saveMaintenanceSchedule } from '$lib/server/fleet/plutonium.js';
export function GET() { return json(plutoniumStatus()); }
export async function POST({ request }: { request: Request }) {
let body;
try { body = await request.json(); } catch { return json({ error: 'Invalid JSON.' }, { status: 400 }); }
if (!body || typeof body !== 'object') return json({ error: 'Invalid request.' }, { status: 400 });
if (body.action === 'check') {
await checkPlutonium();
} else if (body.action === 'schedule') {
if (typeof body.enabled !== 'boolean' || typeof body.time !== 'string' || !/^([01]\d|2[0-3]):[0-5]\d$/.test(body.time)) {
return json({ error: 'Provide enabled and a valid UTC time (HH:mm).' }, { status: 400 });
}
saveMaintenanceSchedule(body.enabled, body.time);
} else if (body.action === 'restart') {
if (!Array.isArray(body.servers) || !body.servers.length || body.servers.some((s: unknown) => typeof s !== 'string')) {
return json({ error: 'Choose servers to restart.' }, { status: 400 });
}
try { queueMaintenance(body.servers); }
catch (err) { return json({ error: (err as Error).message }, { status: 400 }); }
} else if (body.action === 'cancel') {
if (!Number.isSafeInteger(body.id) || !cancelMaintenance(body.id)) return json({ error: 'Only queued restarts can be cancelled.' }, { status: 409 });
} else return json({ error: 'Unknown action.' }, { status: 400 });
return json(plutoniumStatus());
}