fix(cli): sys.path-Fix für direktes Skript-Aufrufen + Wrapper voice-agent-admin

- cli.py fügt lxc-frontend/ zu sys.path hinzu, sodass
  `python /pfad/zu/cli.py <cmd>` aus jedem Verzeichnis funktioniert
  (vorher nur via `python -m app.cli` aus dem App-Verzeichnis)
- install.sh legt /usr/local/bin/voice-agent-admin als Wrapper an,
  damit man einfach `sudo voice-agent-admin list` aufrufen kann
This commit is contained in:
root 2026-05-14 02:47:28 +00:00
parent 44528ef655
commit a681ca871b
2 changed files with 25 additions and 7 deletions

View File

@ -68,6 +68,14 @@ rm -f /etc/nginx/sites-enabled/default
nginx -t nginx -t
systemctl reload nginx systemctl reload nginx
echo "[+] CLI-Wrapper /usr/local/bin/voice-agent-admin"
cat > /usr/local/bin/voice-agent-admin <<'WRAPPER'
#!/usr/bin/env bash
exec sudo -u deploy /var/www/voice-agent/lxc-frontend/.venv/bin/python \
/var/www/voice-agent/lxc-frontend/app/cli.py "$@"
WRAPPER
chmod 0755 /usr/local/bin/voice-agent-admin
echo echo
echo "Fertig. Health-Check:" echo "Fertig. Health-Check:"
echo " curl -s http://localhost/health" echo " curl -s http://localhost/health"

View File

@ -1,7 +1,11 @@
"""CLI-Tool für Notfall-User-Verwaltung. """CLI-Tool für Notfall-User-Verwaltung.
Aufruf am LXC: Aufruf am LXC (von überall, absoluter Pfad):
sudo -u deploy /var/www/voice-agent/lxc-frontend/.venv/bin/python -m app.cli <befehl> [...] sudo -u deploy /var/www/voice-agent/lxc-frontend/.venv/bin/python \\
/var/www/voice-agent/lxc-frontend/app/cli.py <befehl> [...]
Bequemer ist der Wrapper (vom install.sh angelegt):
sudo voice-agent-admin <befehl> [...]
Befehle: Befehle:
list alle User auflisten list alle User auflisten
@ -14,13 +18,19 @@ Befehle:
from __future__ import annotations from __future__ import annotations
import sys import sys
from pathlib import Path
from sqlmodel import Session, select # Damit Skript auch ohne `cd` und ohne `-m` läuft: lxc-frontend/ auf sys.path.
_LXC_FRONTEND = Path(__file__).resolve().parent.parent
if str(_LXC_FRONTEND) not in sys.path:
sys.path.insert(0, str(_LXC_FRONTEND))
from app.core.auth import hash_password, verify_password from sqlmodel import Session, select # noqa: E402
from app.core.db import engine, init_db
from app.core.migrate import run_migrations from app.core.auth import hash_password, verify_password # noqa: E402
from app.models.user import User from app.core.db import engine, init_db # noqa: E402
from app.core.migrate import run_migrations # noqa: E402
from app.models.user import User # noqa: E402
def _setup() -> None: def _setup() -> None: