diff --git a/DEPLOYMENT.md b/DEPLOYMENT.md index b5ac8ab..cab4ae8 100644 --- a/DEPLOYMENT.md +++ b/DEPLOYMENT.md @@ -932,6 +932,32 @@ sudo systemctl daemon-reload sudo systemctl enable --now voice-assistant ``` +#### 2.7.1 Admin-Rechte: Log lesen & Gateway neu starten + +Der Dienst läuft als **System**-Dienst unter dem User `voice`. Damit das Admin-Panel +(a) den Live-Log anzeigen und (b) das Gateway neu starten kann, braucht `voice` zwei +eng begrenzte Rechte. **Ohne diese beiden Schritte bleiben der Log-Tab leer und der +Neustart-Button wirkungslos.** + +```bash +# (a) Log lesen: voice darf das System-Journal lesen +sudo usermod -aG systemd-journal voice + +# (b) Neustart: voice darf AUSSCHLIESSLICH den eigenen Dienst neu starten +sudo tee /etc/sudoers.d/voice-assistant > /dev/null <<'SUDO' +# Erlaubt dem voice-User ausschließlich den Neustart des eigenen Dienstes +# (für den "Gateway neu starten"-Button im Admin-Panel). Sonst nichts. +voice ALL=(root) NOPASSWD: /usr/bin/systemctl restart voice-assistant.service +SUDO +sudo chmod 0440 /etc/sudoers.d/voice-assistant +sudo visudo -cf /etc/sudoers.d/voice-assistant # validieren + +# Dienst neu starten, damit der Prozess die neue Gruppe übernimmt +sudo systemctl restart voice-assistant +``` + +Rückgängig: `sudo gpasswd -d voice systemd-journal` bzw. `sudo rm /etc/sudoers.d/voice-assistant`. + ### 2.8 nginx-Konfiguration `/etc/nginx/sites-available/voice.jamulix.de` **Wichtig:** `X-Forwarded-For` muss leer gesetzt werden (`""`), da uvicorn diff --git a/app/admin_llm.py b/app/admin_llm.py index 8cb21cc..76f72a6 100644 --- a/app/admin_llm.py +++ b/app/admin_llm.py @@ -1,6 +1,6 @@ """Read-only Statusabfragen rund um das lokale LLM-Backend (fuer das Admin-Panel). -Alles nur lesend, ohne sudo: `docker ps`, `ollama ps`, `nvidia-smi`, `systemctl --user`. +Status-Abfragen sind read-only: `docker ps`, `ollama ps`, `nvidia-smi`, `systemctl is-active`. Fehlende Tools oder Fehler fuehren zu sicheren Defaults (None/[]), nie zu Exceptions. """ @@ -97,7 +97,7 @@ async def _gpus() -> list[dict]: async def _gateway_service_active() -> bool: - out = await _run(["systemctl", "--user", "is-active", "voice-assistant.service"], timeout=4.0) + out = await _run(["systemctl", "is-active", "voice-assistant.service"], timeout=4.0) return bool(out and out.strip() == "active") @@ -177,11 +177,13 @@ async def switch_backend(backend: str, model: str | None = None) -> dict: def restart_gateway_detached() -> dict: - """Startet das Gateway als systemd-User-Dienst neu (losgelöst, Self-Restart-sicher).""" - xdg = os.environ.get("XDG_RUNTIME_DIR", f"/run/user/{os.getuid()}") + """Startet das Gateway (System-Dienst) neu — losgelöst, Self-Restart-sicher. + + Nutzt eine eng begrenzte sudo-Regel (/etc/sudoers.d/voice-assistant): + `voice ALL=(root) NOPASSWD: /usr/bin/systemctl restart voice-assistant.service`. + """ subprocess.Popen( - ["bash", "-c", - f"sleep 1; XDG_RUNTIME_DIR={xdg} systemctl --user restart voice-assistant.service"], + ["bash", "-c", "sleep 1; sudo -n systemctl restart voice-assistant.service"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True, diff --git a/app/api/admin.py b/app/api/admin.py index 2aa500e..cf2ed37 100644 --- a/app/api/admin.py +++ b/app/api/admin.py @@ -369,7 +369,7 @@ async def admin_log_ws(websocket: WebSocket, key: str | None = None): # und der Log-Tab bliebe sonst kommentarlos leer. try: check = await asyncio.create_subprocess_exec( - "systemctl", "--user", "is-active", "voice-assistant.service", + "systemctl", "is-active", "voice-assistant.service", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.DEVNULL, ) out, _ = await check.communicate() @@ -378,13 +378,13 @@ async def admin_log_ws(websocket: WebSocket, key: str | None = None): "⚠ Der systemd-Dienst 'voice-assistant.service' ist nicht aktiv — " "die laufende Instanz wurde vermutlich manuell gestartet (uvicorn --reload). " "Live-Logs erscheinen hier nur, wenn das Gateway als Dienst läuft " - "(systemctl --user start voice-assistant.service). Manuelle Starts loggen ins Terminal." + "(sudo systemctl start voice-assistant.service). Manuelle Starts loggen ins Terminal." ) except Exception: pass proc = await asyncio.create_subprocess_exec( - "journalctl", "--user", "-f", "-u", "voice-assistant.service", + "journalctl", "-f", "-u", "voice-assistant.service", "-n", "100", "--no-pager", "-o", "short", stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT, diff --git a/app/web/app.js b/app/web/app.js index 7ed07cf..c94ef0c 100644 --- a/app/web/app.js +++ b/app/web/app.js @@ -1282,61 +1282,6 @@ async function loadEmergencyEvents() { // TAB: STATUS // ════════════════════════════════════════ // LLM-/GPU-Status-Karte (read-only) für den Status-Tab. -function renderLlmCard(llm) { - if (!llm) return ""; - const backendLabel = { ollama: "Ollama", llamacpp: "llama.cpp", unknown: "—" }[llm.backend] || llm.backend; - const dot = (on) => ``; - const row = (label, val) => - `
keine GPU-Daten (nvidia-smi)
'; - - return ` -Hinweis: Wirkt vollständig nur, wenn das Gateway als systemd-Dienst läuft (sonst .env/Backend umgestellt, aber Gateway manuell neu starten).
-lade …
'; try { - const [cfg, met, llm] = await Promise.all([ + const [cfg, met, runtimeCfg] = await Promise.all([ fetch("/api/config").then((r) => r.json()), fetch("/api/metrics").then((r) => r.json()), - adminFetch("/api/admin/llm/status"), + adminFetch("/api/admin/config"), ]); + const cfgByKey = Object.fromEntries((runtimeCfg || []).map((d) => [d.key, d.effective_value])); + const llmModel = cfgByKey["openrouter_llm_model"] || "—"; const route = cfg.default_route || {}; const counters = met.counters || {}; const turnsTotal = counters["turns_total"] || 0; @@ -1418,14 +1349,23 @@ async function loadStatus() {Startet den Gateway-Dienst neu (z. B. nach Einstellungen, die einen Neustart erfordern).
+Fehler beim Laden.
';