diff --git a/scripts/deploy-srv04.sh b/scripts/deploy-srv04.sh new file mode 100755 index 0000000..6212a8d --- /dev/null +++ b/scripts/deploy-srv04.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +# Baut das musl-Binary und legt es mit dem Installationsskript auf srv04 ab. +# Es verändert auf srv04 nur den Ordner /tmp/nexus-deploy (als Benutzer stephan). +# Die eigentliche Installation (root) startest du danach selbst: +# ssh -t srv04 'sudo VERSION= bash /tmp/nexus-deploy/install.sh' +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/.." +HOST="${HOST:-srv04}" + +cargo build --release --target x86_64-unknown-linux-musl -p nexus +BIN=target/x86_64-unknown-linux-musl/release/nexus +VERSION="$("$BIN" version | awk '{print $2}')" +echo "Gebaut: nexus $VERSION ($(stat -c %s "$BIN") Bytes, $(file -b "$BIN" | cut -d, -f1-2,5 | cut -c1-60))" + +ssh -o BatchMode=yes "$HOST" 'mkdir -p /tmp/nexus-deploy' +scp -q "$BIN" "$HOST:/tmp/nexus-deploy/nexus" +scp -q scripts/srv04-install.sh "$HOST:/tmp/nexus-deploy/install.sh" +# Läuft das statische Binary dort überhaupt? (Nur Version anzeigen, ändert nichts.) +ssh -o BatchMode=yes "$HOST" 'chmod +x /tmp/nexus-deploy/nexus && /tmp/nexus-deploy/nexus version' +echo +echo "Abgelegt unter $HOST:/tmp/nexus-deploy. Zum Installieren (braucht dein sudo-Passwort):" +echo " ssh -t $HOST 'sudo VERSION=$VERSION bash /tmp/nexus-deploy/install.sh'" diff --git a/scripts/srv04-install.sh b/scripts/srv04-install.sh new file mode 100755 index 0000000..b320218 --- /dev/null +++ b/scripts/srv04-install.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env bash +# Installiert Nexus auf srv04. Läuft AUF srv04 und braucht root (sudo). +# +# Was es tut (und nichts anderes): +# 1. legt /srv/apps/nexus/{releases/,data} an (Besitzer svc-scotty) +# 2. kopiert das Binary nach releases//nexus und schaltet den +# Symlink /srv/apps/nexus/current darauf um (die alte Version bleibt) +# 3. legt /srv/apps/nexus/config.toml an, NUR wenn es sie noch nicht gibt +# 4. schreibt /etc/systemd/system/nexus.service und lädt systemd neu +# Es startet und aktiviert den Dienst NICHT, außer mit --start bzw. --enable. +# Es ändert keine bestehende Engine-Installation und keine Modelle. +# +# Aufruf: sudo VERSION=0.1.0-dev bash install.sh [--start] [--enable] +# sudo bash install.sh --rollback (vorherige Version, Dienst neu starten) +set -euo pipefail + +USER_NAME="svc-scotty" +BASE="/srv/apps/nexus" +UNIT="/etc/systemd/system/nexus.service" +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +LISTEN="${LISTEN:-127.0.0.1:8080}" + +[ "$(id -u)" -eq 0 ] || { echo "Bitte mit sudo ausführen." >&2; exit 1; } +id "$USER_NAME" >/dev/null 2>&1 || { echo "Benutzer $USER_NAME fehlt." >&2; exit 1; } + +as_user() { sudo -u "$USER_NAME" "$@"; } + +if [ "${1:-}" = "--rollback" ]; then + [ -d "$BASE/releases" ] || { echo "Keine Releases unter $BASE/releases." >&2; exit 1; } + current="$(basename "$(readlink -f "$BASE/current")")" + previous="$(ls -1t "$BASE/releases" | grep -vx "$current" | head -n 1 || true)" + [ -n "$previous" ] || { echo "Es gibt keine ältere Version für den Rückfall." >&2; exit 1; } + ln -sfn "$BASE/releases/$previous" "$BASE/current.new" + mv -T "$BASE/current.new" "$BASE/current" + echo "Rückfall: current zeigt jetzt auf $previous (vorher $current)." + if systemctl is-active --quiet nexus; then systemctl restart nexus && echo "Dienst neu gestartet."; fi + exit 0 +fi + +VERSION="${VERSION:?VERSION fehlt (zum Beispiel VERSION=0.1.0-dev)}" +[ -x "$HERE/nexus" ] || { echo "$HERE/nexus fehlt oder ist nicht ausführbar." >&2; exit 1; } +"$HERE/nexus" version | grep -q "$VERSION" || { echo "Das Binary meldet nicht die Version $VERSION." >&2; exit 1; } + +install -d -o "$USER_NAME" -g "$USER_NAME" -m 0755 "$BASE" "$BASE/releases" "$BASE/releases/$VERSION" +install -d -o "$USER_NAME" -g "$USER_NAME" -m 0750 "$BASE/data" +install -o "$USER_NAME" -g "$USER_NAME" -m 0755 "$HERE/nexus" "$BASE/releases/$VERSION/nexus" +ln -sfn "$BASE/releases/$VERSION" "$BASE/current.new" +mv -T "$BASE/current.new" "$BASE/current" +echo "Version $VERSION installiert, current zeigt darauf." + +if [ -e "$BASE/config.toml" ]; then + echo "config.toml existiert und bleibt unverändert." +else + cat >"$BASE/config.toml" <"$UNIT" <