Files
timemaster/server-update.sh
T
patrickandClaude Opus 4.8 f24b25b22d
Security Audit / Python Dependency Audit (push) Has been cancelled
Security Audit / Node.js Dependency Audit (push) Has been cancelled
chore(deploy): entkoppelte Self-Update-Skripte pro Server
Jeder Server aktualisiert sich eigenstaendig aus dem Repo – kein
Cross-Server-SSH, kein "both". 137 und 164 komplett getrennt.

- server-update.sh: laeuft AUF dem Server (git pull --ff-only → alembic
  upgrade head → restart → health). Guard: bricht ab wenn venv fehlt.
- push-frontend.sh: lokal, baut Frontend + rsync dist/ an EINEN Server
  (Node laeuft nicht auf den Servern, dist ist gitignored). Guard gegen
  Ausfuehrung auf einem Zielserver.
- deploy.sh + update.sh stillgelegt (Abbruch-Stubs): deploy.sh rsyncte den
  Arbeitsbaum in den Server-git-Baum und verschmutzte ihn (git pull brach);
  update.sh koppelte beide Server ("both").

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 16:29:43 +02:00

69 lines
3.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# =============================================================================
# server-update.sh AUF dem jeweiligen Server ausführen (nicht lokal!)
#
# Aktualisiert GENAU DIESEN Server eigenständig aus dem Gitea-Repo:
# git pull → alembic upgrade head → service restart → health-check
#
# Jeder Server macht sich selbst kein Cross-Server-SSH, kein "both".
# 137 und 164 sind komplett entkoppelt.
#
# Frontend: wird NICHT hier gebaut (kein Node auf den Servern, dist ist
# gitignored). Frontend liefert der Dev-Rechner separat per push-frontend.sh.
#
# Usage (auf dem Server):
# cd /opt/timemaster && ./server-update.sh
# ./server-update.sh --no-migrate # nur pull + restart
# =============================================================================
set -euo pipefail
REMOTE="/opt/timemaster"
SERVICE="timemaster"
HEALTH_URL="http://localhost:8000/health"
GREEN='\033[0;32m'; RED='\033[0;31m'; YELLOW='\033[1;33m'; NC='\033[0m'
log() { echo -e "${GREEN}==>${NC} $*"; }
warn() { echo -e "${YELLOW}[!]${NC} $*"; }
die() { echo -e "${RED}[FEHLER]${NC} $*" >&2; exit 1; }
DO_MIGRATE=true
[[ "${1:-}" == "--no-migrate" ]] && DO_MIGRATE=false
# ── Sicherstellen, dass wir wirklich auf einem Server sind ────────────────────
[[ -d "$REMOTE/backend/venv" ]] || die "venv fehlt ($REMOTE/backend/venv) falscher Host? Dieses Skript läuft AUF dem Server."
cd "$REMOTE"
git config --global --add safe.directory "$REMOTE" 2>/dev/null || true
# ── 1. Repo aktualisieren ─────────────────────────────────────────────────────
log "git pull --ff-only origin main"
if ! git pull --ff-only origin main; then
die "git pull fehlgeschlagen. Arbeitsbaum sauber? ('git status' prüfen, ggf. 'git stash')."
fi
log "Jetzt auf: $(git log --oneline -1)"
# ── 2. Migration ──────────────────────────────────────────────────────────────
if $DO_MIGRATE; then
log "alembic upgrade head"
( cd "$REMOTE/backend" && source venv/bin/activate && alembic upgrade head ) \
|| die "Migration fehlgeschlagen Service wird NICHT neugestartet (Schema evtl. inkonsistent)."
else
warn "Migration übersprungen (--no-migrate)"
fi
# ── 3. Service neustarten ─────────────────────────────────────────────────────
log "systemctl restart $SERVICE"
systemctl restart "$SERVICE"
sleep 2
state="$(systemctl is-active "$SERVICE" || true)"
[[ "$state" == "active" ]] || { journalctl -u "$SERVICE" -n 30 --no-pager; die "Service nicht aktiv ($state)."; }
log "Service aktiv"
# ── 4. Health-Check ───────────────────────────────────────────────────────────
if curl -sf --max-time 10 "$HEALTH_URL" >/dev/null; then
log "Health OK ($HEALTH_URL)"
else
warn "Health-Check fehlgeschlagen Logs prüfen: journalctl -u $SERVICE -n 50"
fi
log "✓ Update abgeschlossen auf $(hostname)"