feat: Skripte für Build und Installation auf srv04 (ungetestet)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
109
scripts/srv04-install.sh
Executable file
109
scripts/srv04-install.sh
Executable file
@ -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/<version>,data} an (Besitzer svc-scotty)
|
||||
# 2. kopiert das Binary nach releases/<version>/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" <<CONF
|
||||
# Nexus auf srv04. Enthält keine Geheimnisse.
|
||||
listen = "$LISTEN"
|
||||
data_dir = "$BASE/data"
|
||||
log_level = "info"
|
||||
|
||||
[llama_cpp]
|
||||
binary = "/srv/apps/llama.cpp/build/bin/llama-server"
|
||||
model_roots = ["/srv/models/gguf"]
|
||||
port_from = 18080
|
||||
port_to = 18180
|
||||
ready_timeout_secs = 300
|
||||
gpu_layers = 99
|
||||
CONF
|
||||
chown "$USER_NAME:$USER_NAME" "$BASE/config.toml"
|
||||
chmod 0640 "$BASE/config.toml"
|
||||
echo "config.toml angelegt (listen = $LISTEN)."
|
||||
fi
|
||||
|
||||
cat >"$UNIT" <<UNITFILE
|
||||
[Unit]
|
||||
Description=Nexus AI Gateway
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER_NAME
|
||||
Group=$USER_NAME
|
||||
WorkingDirectory=$BASE
|
||||
ExecStart=$BASE/current/nexus serve --config $BASE/config.toml
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
KillSignal=SIGTERM
|
||||
TimeoutStopSec=60
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
UNITFILE
|
||||
systemctl daemon-reload
|
||||
echo "Dienst nexus.service geschrieben und systemd neu geladen."
|
||||
|
||||
for arg in "$@"; do
|
||||
case "$arg" in
|
||||
--enable) systemctl enable nexus && echo "Dienst aktiviert (startet beim Booten)." ;;
|
||||
--start) systemctl restart nexus && echo "Dienst gestartet." ;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo
|
||||
echo "Nächste Schritte (als $USER_NAME):"
|
||||
echo " sudo -u $USER_NAME $BASE/current/nexus model add --name bonsai --path /srv/models/gguf/Bonsai-1.7B-Q1_0.gguf --gpus 0 --config $BASE/config.toml"
|
||||
echo " sudo -u $USER_NAME $BASE/current/nexus key create --name test --config $BASE/config.toml"
|
||||
echo " sudo systemctl start nexus && journalctl -u nexus -f"
|
||||
Reference in New Issue
Block a user