chore(2.0): Deploy als sudo-freier systemd-USER-Dienst (Home, :9001)

mission-control-2.service auf %h/mission-control-v2 umgestellt (kein /opt/
sudo); deploy.sh = Erstinstall+Update als User-Dienst (clone/pull, venv,
systemctl --user, linger). Nordstern: kein Passwort/SSH-Gefummel.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hitonabi
2026-06-25 08:30:40 +02:00
parent 1f4c987652
commit 1b332f86e6
2 changed files with 28 additions and 30 deletions
+20 -25
View File
@@ -1,38 +1,33 @@
#!/usr/bin/env bash
# Deploy AUF DER BOX: git pull (Source) → venv-Sync → rsync nach /opt → Restart.
# Läuft als User hitonabi. KEIN eingebettetes Passwort — der Restart nutzt die
# NOPASSWD-sudoers-Whitelist (nur `systemctl restart mission-control-2`).
# Deploy AUF DER BOX als systemd-USER-Dienst — KEIN sudo, KEIN /opt, KEIN Passwort.
# Erstinstallation + Updates in einem. Läuft als User hitonabi.
#
# Voraussetzungen (einmalig):
# - Gitea-Repo angelegt + hier geklont nach ~/mission-control-2
# - sudoers: hitonabi ALL=(root) NOPASSWD: /usr/bin/systemctl restart mission-control-2
# - systemd-Unit installiert (siehe mission-control-2.service)
# Erstinstallation (einmalig):
# git clone https://git.tobisniceshomelab.ddnsfree.com/Hitonabi/mission-control-v2 ~/mission-control-v2
# bash ~/mission-control-v2/deploy/deploy.sh
set -euo pipefail
SRC="${MC2_SRC:-$HOME/mission-control-2}"
PROD="${MC2_PROD:-/opt/mission-control-2}"
SRC="${MC2_SRC:-$HOME/mission-control-v2}"
cd "$SRC"
git fetch -q origin
git reset -q --hard origin/main
git fetch -q origin && git reset -q --hard origin/main
# Backend-venv auf der Box sicherstellen + Abhängigkeiten aktuell halten.
# venv + Abhängigkeiten
if [ ! -d "$SRC/backend/.venv" ]; then
python3 -m venv "$SRC/backend/.venv"
fi
"$SRC/backend/.venv/bin/python" -m pip install -q --upgrade pip
"$SRC/backend/.venv/bin/python" -m pip install -q -r "$SRC/backend/requirements.txt"
# Nach /opt spiegeln (Frontend-dist kommt aus dem Repo mit).
sudo rsync -a --delete \
--exclude '.git' --exclude 'node_modules' \
"$SRC/" "$PROD/"
# systemd-USER-Unit installieren/aktualisieren
mkdir -p "$HOME/.config/systemd/user"
cp "$SRC/deploy/mission-control-2.service" "$HOME/.config/systemd/user/mission-control-2.service"
systemctl --user daemon-reload
systemctl --user enable mission-control-2 >/dev/null 2>&1 || true
loginctl enable-linger "$USER" >/dev/null 2>&1 || true
systemctl --user restart mission-control-2
# venv separat syncen (rsync oben schließt sie nicht aus, aber Pfade im venv sind
# absolut — daher venv direkt im PROD neu aufbauen, robust):
if [ ! -d "$PROD/backend/.venv" ]; then
sudo python3 -m venv "$PROD/backend/.venv"
fi
sudo "$PROD/backend/.venv/bin/python" -m pip install -q -r "$PROD/backend/requirements.txt"
sudo systemctl restart mission-control-2
echo "OK — Mission Control 2.0 neu gestartet (:9001)."
sleep 2
echo "--- Health ---"
curl -sf http://127.0.0.1:9001/api/health && echo
echo "OK — Mission Control 2.0 läuft auf :9001 (User-Dienst, sudo-frei)."
+8 -5
View File
@@ -1,6 +1,9 @@
# systemd-Unit für Mission Control 2.0 (läuft PARALLEL zu v1 auf eigenem Port 9001).
# Ablage: ~/.config/systemd/user/ (user-Dienst) ODER /etc/systemd/system/ (system, User=hitonabi).
# Aktivieren: systemctl --user enable --now mission-control-2 (bzw. system-weit)
# systemd-USER-Unit für Mission Control 2.0 (PARALLEL zu v1, Port 9001).
# Läuft sudo-frei aus dem Home-Verzeichnis (Nordstern: kein Passwort/sudo).
# Ablage: ~/.config/systemd/user/mission-control-2.service ; dann:
# systemctl --user daemon-reload
# systemctl --user enable --now mission-control-2
# loginctl enable-linger hitonabi # läuft auch ohne aktive Session
[Unit]
Description=Mission Control 2.0 (Cockpit)
@@ -9,8 +12,8 @@ Wants=network-online.target
[Service]
Type=simple
WorkingDirectory=/opt/mission-control-2/backend
ExecStart=/opt/mission-control-2/backend/.venv/bin/python -m uvicorn app:app --host 0.0.0.0 --port 9001
WorkingDirectory=%h/mission-control-v2/backend
ExecStart=%h/mission-control-v2/backend/.venv/bin/python -m uvicorn app:app --host 0.0.0.0 --port 9001
Environment=MC_PORT=9001
Environment=MC_LLAMA_SWAP_URL=http://127.0.0.1:8080
Environment=MC_CONFIG_PATH=/etc/llama-swap/config.yaml