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)."