This commit is contained in:
DigitalInfinity committed 2026-10-17 23:15:26 +02:00
1 parent 796a63671b
commit 571652f480
8 files changed
+247 -25

No files matched your search

+5 -2
View File
@@ -1,12 +1,15 @@
#!/usr/bin/env bash
# Einmalig ausführen: sudo ./scripts/firewall-ufw.sh
# Öffnet den Caddy-Port nur für LAN und NetBird (wt0). Caddy filtert zusätzlich selbst.
# Öffnet die Caddy-Ports (API + Web-Chat) nur für LAN und NetBird (wt0). Caddy filtert zusätzlich selbst.
set -euo pipefail
PORT="${LISTEN_PORT:-8800}"
WEBUI_PORT="${WEBUI_PORT:-8801}"
LAN="${LAN_NET:-192.168.178.0/24}"
VPN_IF="${VPN_IF:-wt0}"
ufw allow from "$LAN" to any port "$PORT" proto tcp comment 'localai LAN'
ufw allow in on "$VPN_IF" to any port "$PORT" proto tcp comment 'localai NetBird'
ufw status numbered | grep -E "$PORT" || true
ufw allow from "$LAN" to any port "$WEBUI_PORT" proto tcp comment 'localai webchat LAN'
ufw allow in on "$VPN_IF" to any port "$WEBUI_PORT" proto tcp comment 'localai webchat NetBird'
ufw status numbered | grep -E "$PORT|$WEBUI_PORT" || true
+35 -12
View File
@@ -47,6 +47,7 @@ if [[ ! -f .env ]]; then
warn ".env fehlt – wird aus .env.example erzeugt"
cp .env.example .env
sed -i "s/^LLM_API_KEY=.*/LLM_API_KEY=$(openssl rand -hex 32)/" .env
sed -i "s/^WEBUI_SECRET_KEY=.*/WEBUI_SECRET_KEY=$(openssl rand -hex 32)/" .env
sed -i "s/^HOST_UID=.*/HOST_UID=$(id -u)/; s/^HOST_GID=.*/HOST_GID=$(id -g)/" .env
rg=$(getent group render | cut -d: -f3 || true); vg=$(getent group video | cut -d: -f3 || true)
[[ -n "$rg" ]] && sed -i "s/^RENDER_GID=.*/RENDER_GID=$rg/" .env
@@ -55,21 +56,30 @@ if [[ ! -f .env ]]; then
warn "Bitte ALLOWED_NETS in .env prüfen (LAN-/NetBird-Netz)"
fi
# ältere .env ohne Web-Chat-Einträge ergänzen
if ! grep -q '^WEBUI_SECRET_KEY=' .env; then
printf '\nWEBUI_PORT=8801\nWEBUI_BACKEND_PORT=3000\nWEBUI_SECRET_KEY=%s\n' "$(openssl rand -hex 32)" >> .env
warn "Web-Chat-Einträge (WEBUI_*) in .env ergänzt"
fi
set -a; . ./.env; set +a
LISTEN_PORT="${LISTEN_PORT:-8800}"
BACKEND_PORT="${BACKEND_PORT:-8080}"
WEBUI_PORT="${WEBUI_PORT:-8801}"
WEBUI_BACKEND_PORT="${WEBUI_BACKEND_PORT:-3000}"
[[ -n "${LLM_API_KEY:-}" && "$LLM_API_KEY" != "CHANGE_ME" ]] || die "LLM_API_KEY in .env setzen (openssl rand -hex 32)"
[[ -n "${WEBUI_SECRET_KEY:-}" && "$WEBUI_SECRET_KEY" != "CHANGE_ME" ]] || die "WEBUI_SECRET_KEY in .env setzen (openssl rand -hex 32)"
ok ".env geladen"
# Ports dürfen nur von unserem eigenen Stack belegt sein
running=$(docker compose ps --status running -q 2>/dev/null | wc -l)
if [[ "$running" -eq 0 ]]; then
for p in "$LISTEN_PORT" "$BACKEND_PORT"; do
for p in "$LISTEN_PORT" "$BACKEND_PORT" "$WEBUI_PORT" "$WEBUI_BACKEND_PORT"; do
if ss -Htln "sport = :$p" | grep -q .; then
die "Port $p ist bereits belegt: $(ss -Htlnp "sport = :$p" | awk '{print $NF}' | head -1) – in .env ändern"
fi
done
ok "Ports $LISTEN_PORT und $BACKEND_PORT frei"
ok "Ports $LISTEN_PORT, $BACKEND_PORT, $WEBUI_PORT und $WEBUI_BACKEND_PORT frei"
fi
if systemctl is-active --quiet ollama 2>/dev/null; then
@@ -77,9 +87,11 @@ if systemctl is-active --quiet ollama 2>/dev/null; then
fi
if command -v ufw >/dev/null && systemctl is-active --quiet ufw 2>/dev/null; then
if [[ -r /etc/ufw/user.rules ]] && ! grep -q "dport $LISTEN_PORT" /etc/ufw/user.rules; then
warn "Keine ufw-Freigabe für Port $LISTEN_PORT gefunden → sudo ./scripts/firewall-ufw.sh"
fi
for p in "$LISTEN_PORT" "$WEBUI_PORT"; do
if [[ -r /etc/ufw/user.rules ]] && ! grep -q "dport $p" /etc/ufw/user.rules; then
warn "Keine ufw-Freigabe für Port $p gefunden → sudo ./scripts/firewall-ufw.sh"
fi
done
fi
mkdir -p models
@@ -113,6 +125,14 @@ code=$(curl -s -o /dev/null -m 5 -w '%{http_code}' -H "Authorization: Bearer $LL
[[ "$code" == "200" ]] || die "API mit Key liefert HTTP $code"
ok "Caddy bereit (Auth aktiv)"
# Open WebUI braucht beim ersten Start etwas länger (Datenbank anlegen)
for i in $(seq 1 120); do
curl -fsS -m 2 "http://127.0.0.1:$WEBUI_PORT/health" >/dev/null 2>&1 && break
(( i == 120 )) && die "Web-Chat antwortet nicht – docker compose logs open-webui"
sleep 1
done
ok "Web-Chat bereit"
# ---------------------------------------------------------------- Preload
if (( PRELOAD )); then
step "Lade Modelle vor (erster Start lädt ggf. von Hugging Face herunter)"
@@ -149,14 +169,17 @@ step "Verbindung"
lan_ip=$(ip -4 -o addr show scope global | awk '$2 !~ /^(wt|docker|virbr|br-|veth)/ {split($4,a,"/"); print a[1]; exit}')
nb_ip=$(ip -4 -o addr show wt0 2>/dev/null | awk '{split($4,a,"/"); print a[1]}')
nb_fqdn=$(netbird status 2>/dev/null | awk '/^FQDN:/{print $2}' || true)
echo " lokal: http://127.0.0.1:$LISTEN_PORT/v1"
[[ -n "$lan_ip" ]] && echo " LAN: http://$lan_ip:$LISTEN_PORT/v1"
[[ -n "$nb_ip" ]] && echo " NetBird: http://$nb_ip:$LISTEN_PORT/v1${nb_fqdn:+ (http://$nb_fqdn:$LISTEN_PORT/v1)}"
echo " API lokal: http://127.0.0.1:$LISTEN_PORT/v1"
[[ -n "$lan_ip" ]] && echo " API LAN: http://$lan_ip:$LISTEN_PORT/v1"
[[ -n "$nb_ip" ]] && echo " API NetBird: http://$nb_ip:$LISTEN_PORT/v1${nb_fqdn:+ (http://$nb_fqdn:$LISTEN_PORT/v1)}"
echo " Chat lokal: http://127.0.0.1:$WEBUI_PORT"
[[ -n "$lan_ip" ]] && echo " Chat LAN: http://$lan_ip:$WEBUI_PORT"
[[ -n "$nb_ip" ]] && echo " Chat NetBird: http://$nb_ip:$WEBUI_PORT${nb_fqdn:+ (http://$nb_fqdn:$WEBUI_PORT)}"
if (( SHOW_KEY )); then
echo " API-Key: $LLM_API_KEY"
echo " API-Key: $LLM_API_KEY"
else
echo " API-Key: ${LLM_API_KEY:0:6}… (vollständig: --show-key)"
echo " API-Key: ${LLM_API_KEY:0:6}… (vollständig: --show-key)"
fi
echo " Web-UI: http://127.0.0.1:$BACKEND_PORT/ui (nur lokal)"
echo " llama-swap: http://127.0.0.1:$BACKEND_PORT/ui (nur lokal)"
echo
echo " Clients einrichten: docs/opencode.md, docs/continue.md"
echo " Clients einrichten: docs/opencode.md, docs/continue.md, docs/webchat.md"