import { api } from "../core/api.js"; import { $, toast } from "../core/ui.js"; import { track } from "./jobs.js"; function refreshSoon() { document.dispatchEvent(new Event("mc:refresh")); } function mount() { $("#wartung").innerHTML = `

Dienste & Applikation

Dienste starten via passwortlosem Sudo neu.

Betriebssystem (Bosgame)

Für tiefe Eingriffe fragt das Dashboard einmalig das sudo-Passwort ab.
`; $("#w-restart-swap").addEventListener("click", () => restartService("llama-swap")); $("#w-restart-mc").addEventListener("click", () => restartService("mission-control")); $("#w-update").addEventListener("click", update); $("#w-unload").addEventListener("click", unloadAll); $("#w-os-update").addEventListener("click", osUpdate); $("#w-reboot").addEventListener("click", rebootServer); } async function restartService(name) { try { await api("/api/service/" + name + "/restart", { method: "POST" }); toast("Neustart ausgelöst: " + name); setTimeout(refreshSoon, 2000); } catch (e) { toast(e.message, true); } } async function osUpdate() { const pwd = window.prompt("Bitte sudo Passwort eingeben (für apt-get update & upgrade):"); if (!pwd) return; try { const r = await api("/api/os-update", { method: "POST", body: JSON.stringify({ password: pwd }) }); toast("OS-Update gestartet."); track(r.job_id); } catch (e) { toast(e.message, true); } } async function rebootServer() { if (!window.confirm("ACHTUNG: Server wird komplett neu gestartet. Fortfahren?")) return; const pwd = window.prompt("Bitte sudo Passwort eingeben (für reboot):"); if (!pwd) return; try { await api("/api/reboot", { method: "POST", body: JSON.stringify({ password: pwd }) }); toast("Reboot ausgelöst. UI ist gleich offline."); } catch (e) { toast(e.message, true); } } async function update() { try { const r = await api("/api/update", { method: "POST" }); toast("Update läuft."); track(r.job_id); } catch (e) { toast(e.message, true); } } async function unloadAll() { try { await api("/api/unload", { method: "POST" }); toast("Alle Modelle entladen."); setTimeout(refreshSoon, 600); } catch (e) { toast(e.message, true); } } export default { id: "maintenance", mount };