deploy: systemd-Unit, Install- und Deploy-Skript

This commit is contained in:
Mikei386
2026-08-18 22:52:48 +02:00
parent aefd7be035
commit 70dba6fcb2
3 changed files with 92 additions and 0 deletions
+50
View File
@@ -0,0 +1,50 @@
#!/bin/bash
# AI Profile Router – Installation/Update auf dem Zielsystem.
# Wird als root auf dem Zielsystem ausgeführt (per SSH, vgl. deploy.sh).
# Erwartet ai_profile_router.py und mike-ai-profile-router.service
# im selben Verzeichnis wie dieses Skript.
set -euo pipefail
DIR="$(cd "$(dirname "$0")" && pwd)"
INSTALL_DIR=/opt/mike-ai/ai-profile-router
SERVICE=mike-ai-profile-router.service
OLD_SERVICE=mike-ai-local-llm-router.service
OLD_DIR=/opt/mike-ai/local-llm-router
BACKUP_DIR=/opt/mike-ai/.backup-ai-profile-router-$(date +%Y%m%d-%H%M%S)
echo "== AI Profile Router: Installation/Update =="
# --- 1. Bestehenden (alten) Router entfernen, mit Backup -------------------
if [ -f "/etc/systemd/system/${OLD_SERVICE}" ]; then
echo "-- Entferne alten Router ${OLD_SERVICE} (Backup: ${BACKUP_DIR})"
mkdir -p "$BACKUP_DIR"
systemctl stop "$OLD_SERVICE" 2>/dev/null || true
systemctl disable "$OLD_SERVICE" 2>/dev/null || true
mv "/etc/systemd/system/${OLD_SERVICE}" "$BACKUP_DIR/"
if [ -d "$OLD_DIR" ]; then
mv "$OLD_DIR" "$BACKUP_DIR/local-llm-router"
fi
else
echo "-- Kein alter Router gefunden"
fi
# --- 2. Neue Dateien installieren -------------------------------------------
mkdir -p "$INSTALL_DIR"
install -m 0755 "$DIR/ai_profile_router.py" "$INSTALL_DIR/ai_profile_router.py"
install -m 0644 "$DIR/${SERVICE}" "/etc/systemd/system/${SERVICE}"
# --- 3. Service aktivieren und starten ---------------------------------------
systemctl daemon-reload
systemctl enable "$SERVICE"
systemctl restart "$SERVICE"
# --- 4. Verifikation ----------------------------------------------------------
sleep 1
if ! systemctl is-active --quiet "$SERVICE"; then
echo "-- FEHLER: Service läuft nicht" >&2
journalctl -u "$SERVICE" -n 20 --no-pager >&2
exit 1
fi
echo "-- Service läuft"
curl -sf "http://127.0.0.1:8081/status" | python3 -m json.tool
echo "== Fertig =="