deploy: systemd-Unit, Install- und Deploy-Skript
This commit is contained in:
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/bash
|
||||
# AI Profile Router – Deployment vom Coding-System auf das Zielsystem.
|
||||
# Überträgt die Deploy-Dateien per SCP und führt install.sh per SSH aus.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
TARGET="${TARGET:-root@192.168.1.196}"
|
||||
SSH_KEY="${SSH_KEY:-$HOME/.ssh/lmstudio_unraid}"
|
||||
STAGE="/tmp/ai-profile-router-$$"
|
||||
|
||||
mkdir -p "$STAGE"
|
||||
cp router/ai_profile_router.py deploy/install.sh deploy/mike-ai-profile-router.service "$STAGE/"
|
||||
|
||||
echo "== Übertrage Dateien nach ${TARGET}:/tmp/ai-profile-router/"
|
||||
ssh -i "$SSH_KEY" "$TARGET" 'mkdir -p /tmp/ai-profile-router'
|
||||
scp -i "$SSH_KEY" "$STAGE"/* "$TARGET:/tmp/ai-profile-router/"
|
||||
rm -rf "$STAGE"
|
||||
|
||||
echo "== Führe Installation auf dem Zielsystem aus"
|
||||
ssh -i "$SSH_KEY" "$TARGET" 'bash /tmp/ai-profile-router/install.sh'
|
||||
Executable
+50
@@ -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 =="
|
||||
@@ -0,0 +1,22 @@
|
||||
[Unit]
|
||||
Description=Mike AI Profile Router (OpenAI-kompatibler Proxy, Port 8081)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/python3 /opt/mike-ai/ai-profile-router/ai_profile_router.py
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
Environment=ROUTER_HOST=0.0.0.0
|
||||
Environment=ROUTER_PORT=8081
|
||||
Environment=UPSTREAM_URL=http://127.0.0.1:8080
|
||||
Environment=PROFILE_SCRIPT=/usr/local/bin/llama-profile
|
||||
Environment=PROFILE_DIR=/etc/systemd/system/mike-ai-llama-ui.service.d
|
||||
Environment=SWITCH_TIMEOUT=600
|
||||
Environment=REQUEST_TIMEOUT=600
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Reference in New Issue
Block a user