install.sh: 6 Verbesserungen + 9 Pitfall-Prüfungen (Don)

1. .env-Template: ARCHIVAR_EMBEDDING_BASE_URL ergänzt
2. Ollama Service-Start + Modell-Pull gesichert
3. numpy/faiss Import-Test nach Installation
4. sys.path.insert für archivar-Imports in __init__.py
5. LLM_CONFIG Klarstellung: LLM=Cloud, Embeddings=lokal
6. loginctl enable-linger Check (KRITISCH — ohne Linger Crash-Loop)

Pitfalls P1-P9 dokumentiert und geprüft in install.sh
Idempotent — mehrfach ausführbar ohne Fehler
This commit is contained in:
Bernd (Hermes)
2026-07-14 14:58:28 +02:00
parent 1c603d627a
commit a4f1bd6443
3 changed files with 143 additions and 8 deletions
+121 -6
View File
@@ -232,6 +232,8 @@ load_lang() {
# M11: Install a package in the Hermes venv. # M11: Install a package in the Hermes venv.
# Hermes v0.18.0+ uses uv; older versions use pip. # Hermes v0.18.0+ uses uv; older versions use pip.
# Priority: uv pip > pip > python -m pip (for both venv/ and .venv/). # Priority: uv pip > pip > python -m pip (for both venv/ and .venv/).
# P5 WICHTIG: Niemals 'pip' als Binary verwenden — auf frischem Debian fehlt
# das pip-Binary oft. Immer 'python3 -m pip' als Fallback nutzen (siehe unten).
_venv_install() { _venv_install() {
local hermes_dir="$1" pkg="$2" local hermes_dir="$1" pkg="$2"
if [ -f "$hermes_dir/venv/bin/uv" ]; then if [ -f "$hermes_dir/venv/bin/uv" ]; then
@@ -529,6 +531,23 @@ perform_update() {
if [ "$RC_MULTIROOM" = "true" ]; then if [ "$RC_MULTIROOM" = "true" ]; then
_venv_install "$hermes_dir" numpy _venv_install "$hermes_dir" numpy
_venv_install "$hermes_dir" faiss-cpu 2>/dev/null || echo "⚠️ faiss-cpu not available (ARM?) — Archivar uses fallback" _venv_install "$hermes_dir" faiss-cpu 2>/dev/null || echo "⚠️ faiss-cpu not available (ARM?) — Archivar uses fallback"
# Verbesserung 3: numpy/faiss Import-Test
_UPD_PY=""
if [ -f "$hermes_dir/venv/bin/python" ]; then
_UPD_PY="$hermes_dir/venv/bin/python"
elif [ -f "$hermes_dir/.venv/bin/python" ]; then
_UPD_PY="$hermes_dir/.venv/bin/python"
fi
if [ -n "$_UPD_PY" ]; then
if ! "$_UPD_PY" -c 'import numpy; import faiss' 2>/dev/null; then
echo "⚠️ numpy/faiss Import fehlgeschlagen — Neuinstallation..."
"$_UPD_PY" -m pip install --force-reinstall numpy faiss-cpu 2>&1 | tail -3
"$_UPD_PY" -c 'import numpy; import faiss' 2>/dev/null && echo "✅ numpy/faiss Import OK" || echo "❌ numpy/faiss fehlgeschlagen — Fallback"
else
echo "✅ numpy/faiss Import OK"
fi
fi
fi fi
# ─── FIX: room-map.json bereitstellen (nur Multi-Room) ───────── # ─── FIX: room-map.json bereitstellen (nur Multi-Room) ─────────
@@ -645,7 +664,9 @@ except: print(0)
systemctl --user daemon-reload 2>/dev/null || true systemctl --user daemon-reload 2>/dev/null || true
# State-Cleanup: Verhindert Discovery-Bug + Auto-Resume-Crash-Loop # State-Cleanup: Verhindert Discovery-Bug + Auto-Resume-Crash-Loop
# P7: state.db FTS kaputt → rm state.db (Hermes baut neu auf)
rm -f "$HOME/.hermes/gateway_state.json" "$HOME/.hermes/gateway.lock" "$HOME/.hermes/.gateway_state_*.tmp" 2>/dev/null || true rm -f "$HOME/.hermes/gateway_state.json" "$HOME/.hermes/gateway.lock" "$HOME/.hermes/.gateway_state_*.tmp" 2>/dev/null || true
rm -f "$HOME/.hermes/state.db" 2>/dev/null || true
systemctl --user reset-failed hermes-gateway 2>/dev/null || true systemctl --user reset-failed hermes-gateway 2>/dev/null || true
systemctl --user enable hermes-gateway 2>/dev/null || true systemctl --user enable hermes-gateway 2>/dev/null || true
@@ -762,6 +783,23 @@ perform_update_only() {
if [ "$RC_MULTIROOM" = "true" ]; then if [ "$RC_MULTIROOM" = "true" ]; then
_venv_install "$hermes_dir" numpy _venv_install "$hermes_dir" numpy
_venv_install "$hermes_dir" faiss-cpu 2>/dev/null || echo "⚠️ faiss-cpu not available (ARM?) — Archivar uses fallback" _venv_install "$hermes_dir" faiss-cpu 2>/dev/null || echo "⚠️ faiss-cpu not available (ARM?) — Archivar uses fallback"
# Verbesserung 3: numpy/faiss Import-Test
_UO_PY=""
if [ -f "$hermes_dir/venv/bin/python" ]; then
_UO_PY="$hermes_dir/venv/bin/python"
elif [ -f "$hermes_dir/.venv/bin/python" ]; then
_UO_PY="$hermes_dir/.venv/bin/python"
fi
if [ -n "$_UO_PY" ]; then
if ! "$_UO_PY" -c 'import numpy; import faiss' 2>/dev/null; then
echo "⚠️ numpy/faiss Import fehlgeschlagen — Neuinstallation..."
"$_UO_PY" -m pip install --force-reinstall numpy faiss-cpu 2>&1 | tail -3
"$_UO_PY" -c 'import numpy; import faiss' 2>/dev/null && echo "✅ numpy/faiss Import OK" || echo "❌ numpy/faiss fehlgeschlagen — Fallback"
else
echo "✅ numpy/faiss Import OK"
fi
fi
fi fi
# ─── FIX: room-map.json bereitstellen (nur Multi-Room) ───────── # ─── FIX: room-map.json bereitstellen (nur Multi-Room) ─────────
@@ -810,7 +848,9 @@ except: print(0)
# State-Cleanup: Verhindert Discovery-Bug (Platform-Verlust nach SIGTERM) # State-Cleanup: Verhindert Discovery-Bug (Platform-Verlust nach SIGTERM)
# und Auto-Resume-Crash-Loop (restart-interrupted sessions triggern Kill) # und Auto-Resume-Crash-Loop (restart-interrupted sessions triggern Kill)
# P7: state.db FTS kaputt → rm state.db (Hermes baut neu auf)
rm -f "$HOME/.hermes/gateway_state.json" "$HOME/.hermes/gateway.lock" "$HOME/.hermes/.gateway_state_*.tmp" 2>/dev/null || true rm -f "$HOME/.hermes/gateway_state.json" "$HOME/.hermes/gateway.lock" "$HOME/.hermes/.gateway_state_*.tmp" 2>/dev/null || true
rm -f "$HOME/.hermes/state.db" 2>/dev/null || true
systemctl --user reset-failed hermes-gateway 2>/dev/null || true systemctl --user reset-failed hermes-gateway 2>/dev/null || true
systemctl --user enable hermes-gateway 2>/dev/null || true systemctl --user enable hermes-gateway 2>/dev/null || true
@@ -989,6 +1029,8 @@ mkdir -p "$(dirname "$ENV_FILE")"
cat > "$ENV_FILE" <<'EOF' cat > "$ENV_FILE" <<'EOF'
# Hermes Rocket.Chat Plugin — credentials (generated by install.sh) # Hermes Rocket.Chat Plugin — credentials (generated by install.sh)
# systemd-compatible: KEY=VALUE (no export prefix!) # systemd-compatible: KEY=VALUE (no export prefix!)
# P6 WICHTIG: Diese Datei ist MASCHINENSPEZIFISCH — jeder Bot-User braucht
# seine eigene .env! ROCKETCHAT_USER muss pro Maschine korrekt gesetzt sein.
ROCKETCHAT_BASE_URL=PLACEHOLDER_RC_URL ROCKETCHAT_BASE_URL=PLACEHOLDER_RC_URL
ROCKETCHAT_USER=PLACEHOLDER_RC_USER ROCKETCHAT_USER=PLACEHOLDER_RC_USER
ROCKETCHAT_PASSWORD=PLACEHOLDER_RC_PASS ROCKETCHAT_PASSWORD=PLACEHOLDER_RC_PASS
@@ -997,6 +1039,10 @@ ROCKETCHAT_ALLOW_ALL_USERS=true
GATEWAY_ALLOW_ALL_USERS=true GATEWAY_ALLOW_ALL_USERS=true
ROCKETCHAT_PING_SEC=8 ROCKETCHAT_PING_SEC=8
ROCKETCHAT_IDLE_SEC=900 ROCKETCHAT_IDLE_SEC=900
# Verbesserung 1+5: LLM nutzt Cloud, Embeddings nutzen lokal
# OLLAMA_BASE_URL (Cloud) wird über config.yaml gesteuert.
# ARCHIVAR_EMBEDDING_BASE_URL zeigt auf lokales Ollama für nomic-embed-text.
ARCHIVAR_EMBEDDING_BASE_URL=http://localhost:11434
RC_MULTIROOM=PLACEHOLDER_RC_MULTIROOM RC_MULTIROOM=PLACEHOLDER_RC_MULTIROOM
ARCHIVAR_CATCHALL_ROOM=PLACEHOLDER_ARCHIVAR_CATCHALL_ROOM ARCHIVAR_CATCHALL_ROOM=PLACEHOLDER_ARCHIVAR_CATCHALL_ROOM
ARCHIVAR_ENABLE_LLM=PLACEHOLDER_ARCHIVAR_ENABLE_LLM ARCHIVAR_ENABLE_LLM=PLACEHOLDER_ARCHIVAR_ENABLE_LLM
@@ -1043,13 +1089,28 @@ if [ "$RC_MULTIROOM" = "true" ]; then
fi fi
fi fi
# 3. Warte bis Ollama läuft (falls installiert) # 3. Ollama Service sicher starten (Verbesserung 2 + P9)
# Idempotent: wenn Ollama schon aktiv ist, überspringen.
if command -v ollama >/dev/null 2>&1; then if command -v ollama >/dev/null 2>&1; then
# systemctl is-active ollama || sudo systemctl start ollama
if systemctl is-active ollama >/dev/null 2>&1; then
echo "✅ Ollama service bereits aktiv"
else
echo "⚠️ Ollama service nicht aktiv — versuche Start..."
sudo systemctl start ollama 2>/dev/null || systemctl start ollama 2>/dev/null || true
# Warte auf Service-Start
for i in $(seq 1 6); do
if systemctl is-active ollama >/dev/null 2>&1; then
echo "✅ Ollama service gestartet"
break
fi
sleep 2
done
fi
msg ollama_wait msg ollama_wait
sleep 5 # Prüfe ob Ollama-Server antwortet (API-Health-Check)
# Prüfe ob Ollama-Server antwortet
if ! curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then if ! curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then
# Server läuft noch nicht — warte länger
for i in $(seq 1 6); do for i in $(seq 1 6); do
sleep 5 sleep 5
if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then if curl -s http://localhost:11434/api/tags >/dev/null 2>&1; then
@@ -1088,6 +1149,9 @@ else
fi fi
# ─── Copy plugin files ──────────────────────────────────── # ─── Copy plugin files ────────────────────────────────────
# P2: Plugin wird nach SITEPACKAGES/plugins/rocketchat/ kopiert.
# Der Pfad $HERMES_DIR/plugins/rocketchat/ ist korrekt — NICHT
# site-packages/plugins/platforms/rocketchat/ verwenden!
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PLUGIN_DST="$HERMES_DIR/plugins/rocketchat" PLUGIN_DST="$HERMES_DIR/plugins/rocketchat"
mkdir -p "$PLUGIN_DST" mkdir -p "$PLUGIN_DST"
@@ -1160,6 +1224,34 @@ msg cache_cleared
if [ "$RC_MULTIROOM" = "true" ]; then if [ "$RC_MULTIROOM" = "true" ]; then
_venv_install "$HERMES_DIR" numpy _venv_install "$HERMES_DIR" numpy
_venv_install "$HERMES_DIR" faiss-cpu 2>/dev/null || echo "⚠️ faiss-cpu not available (ARM?) — Archivar uses fallback" _venv_install "$HERMES_DIR" faiss-cpu 2>/dev/null || echo "⚠️ faiss-cpu not available (ARM?) — Archivar uses fallback"
# ── Verbesserung 3: numpy/faiss Import-Test ──────────────
# P4: numpy/faiss-cpu können installiert sein aber nicht importierbar
# (z.B. wenn im falschen venv installiert). Test via venv-python.
echo "🔍 Teste numpy/faiss Import..."
_VENV_PY=""
if [ -f "$HERMES_DIR/venv/bin/python" ]; then
_VENV_PY="$HERMES_DIR/venv/bin/python"
elif [ -f "$HERMES_DIR/.venv/bin/python" ]; then
_VENV_PY="$HERMES_DIR/.venv/bin/python"
fi
if [ -n "$_VENV_PY" ]; then
if ! "$_VENV_PY" -c 'import numpy; import faiss' 2>/dev/null; then
echo "⚠️ numpy/faiss Import fehlgeschlagen — versuche Neuinstallation..."
# P5: python3 -m pip statt pip-Binary (pip kann fehlen)
"$_VENV_PY" -m pip install --force-reinstall numpy faiss-cpu 2>&1 | tail -3
# Erneut testen
if ! "$_VENV_PY" -c 'import numpy; import faiss' 2>/dev/null; then
echo "❌ numpy/faiss weiterhin nicht importierbar — Archivar nutzt Fallback"
else
echo "✅ numpy/faiss Import erfolgreich"
fi
else
echo "✅ numpy/faiss Import erfolgreich"
fi
else
echo "⚠️ Kein venv-python gefunden — numpy/faiss-Test übersprungen"
fi
fi fi
# ─── FIX: room-map.json bereitstellen ──────────────────────── # ─── FIX: room-map.json bereitstellen ────────────────────────
@@ -1320,6 +1412,8 @@ $PYTHON -m hermes_cli.main gateway install 2>/dev/null || true
# hermes_cli.main gateway install creates a unit with run_agent.py gateway # hermes_cli.main gateway install creates a unit with run_agent.py gateway
# (AI-agent only, no platform adapter). For Rocket.Chat we NEED the full # (AI-agent only, no platform adapter). For Rocket.Chat we NEED the full
# gateway run (hermes_cli.main gateway run) which loads platform plugins. # gateway run (hermes_cli.main gateway run) which loads platform plugins.
# P8 WICHTIG: ExecStopPost wird von Hermes-intern verwaltet — NICHT manuell
# entfernen! Es sorgt für sauberes Cleanup beim Gateway-Stop.
UNIT_FILE="$HOME/.config/systemd/user/hermes-gateway.service" UNIT_FILE="$HOME/.config/systemd/user/hermes-gateway.service"
if [ -f "$UNIT_FILE" ]; then if [ -f "$UNIT_FILE" ]; then
# Replace ExecStart to use "gateway run" instead of "run_agent.py gateway" # Replace ExecStart to use "gateway run" instead of "run_agent.py gateway"
@@ -1349,8 +1443,27 @@ else
echo "Environment=MULTIROOM_AGENT=${RC_MULTIROOM}" >> "$DROPDIN_FILE" echo "Environment=MULTIROOM_AGENT=${RC_MULTIROOM}" >> "$DROPDIN_FILE"
fi fi
# Ensure lingering is enabled (may need sudo — best-effort) # ─── Verbesserung 6 / P1: loginctl enable-linger — KRITISCH! ──
loginctl enable-linger 2>/dev/null || true # Ohne Linger crasht der Gateway-Service (user service ohne aktive Session).
# Prüfe ob Linger aktiv ist, falls nicht → aktivieren.
echo "🔍 Prüfe loginctl enable-linger..."
if ! loginctl show-user "$USER" 2>/dev/null | grep -q 'Linger=yes'; then
echo "⚠️ Linger nicht aktiviert — Gateway wird crashen!"
sudo loginctl enable-linger "$USER" 2>/dev/null
if [ $? -ne 0 ]; then
# Fallback ohne sudo (kann funktionieren wenn User Berechtigung hat)
loginctl enable-linger "$USER" 2>/dev/null || true
if ! loginctl show-user "$USER" 2>/dev/null | grep -q 'Linger=yes'; then
echo "❌ sudo fehlgeschlagen — bitte manuell: sudo loginctl enable-linger $USER"
else
echo "✅ Linger aktiviert (ohne sudo)"
fi
else
echo "✅ Linger aktiviert"
fi
else
echo "✅ Linger bereits aktiv"
fi
msg service_installed msg service_installed
@@ -1360,7 +1473,9 @@ systemctl --user daemon-reload 2>/dev/null || true
# State-Cleanup: Verhindert Discovery-Bug (Platform-Verlust nach SIGTERM) # State-Cleanup: Verhindert Discovery-Bug (Platform-Verlust nach SIGTERM)
# und Auto-Resume-Crash-Loop (restart-interrupted sessions triggern Kill) # und Auto-Resume-Crash-Loop (restart-interrupted sessions triggern Kill)
# P7: state.db FTS kaputt → rm state.db (Hermes baut neu auf)
rm -f "$HOME/.hermes/gateway_state.json" "$HOME/.hermes/gateway.lock" "$HOME/.hermes/.gateway_state_*.tmp" 2>/dev/null || true rm -f "$HOME/.hermes/gateway_state.json" "$HOME/.hermes/gateway.lock" "$HOME/.hermes/.gateway_state_*.tmp" 2>/dev/null || true
rm -f "$HOME/.hermes/state.db" 2>/dev/null || true
systemctl --user reset-failed hermes-gateway 2>/dev/null || true systemctl --user reset-failed hermes-gateway 2>/dev/null || true
systemctl --user enable hermes-gateway 2>/dev/null || true systemctl --user enable hermes-gateway 2>/dev/null || true
+6
View File
@@ -8,6 +8,12 @@ and REST API (outgoing replies).
import logging import logging
import os import os
import sys
# P3 Fix: Ensure archivar submodule is importable as top-level module.
# Without this, absolute imports like 'from archivar.config import ...'
# fail when the plugin is loaded from site-packages/plugins/rocketchat/.
sys.path.insert(0, os.path.dirname(__file__))
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
+16 -2
View File
@@ -1,3 +1,17 @@
# Hermes Agent — API key (generated by Rocket.Chat Plugin installer) # Hermes Agent — API key + LLM/Embedding configuration
# Generated by Rocket.Chat Plugin installer
# Set OLLAMA_API_KEY env var before running install.sh --non-interactive # Set OLLAMA_API_KEY env var before running install.sh --non-interactive
OLLAMA_API_KEY=PLACEH..._KEY
# ── LLM (Cloud) ──────────────────────────────────────────────
# OLLAMA_BASE_URL zeigt auf den Cloud-Provider (z.B. ollama-cloud).
# Das LLM läuft NICHT lokal — nur die Embeddings laufen lokal.
# OLLAMA_BASE_URL=https://ollama.com/v1 (Cloud, von config.yaml gesteuert)
# ── Embeddings (lokal) ───────────────────────────────────────
# ARCHIVAR_EMBEDDING_BASE_URL zeigt auf lokales Ollama (Port 11434).
# Der Archivar nutzt nomic-embed-text für FAISS-Vektorindex.
# Lokales Ollama MUSS laufen: systemctl is-active ollama
ARCHIVAR_EMBEDDING_BASE_URL=http://localhost:11434
# ── API Key ──────────────────────────────────────────────────
OLLAMA_API_KEY=PLACEH..._KEY