60 lines
1.8 KiB
Bash
Executable File
60 lines
1.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Update aus dem Checkout (nach git pull): Backup, Code, Abhängigkeiten, Neustart, Health-Check.
|
|
set -euo pipefail
|
|
|
|
SELF=$(readlink -f "${BASH_SOURCE[0]}")
|
|
# shellcheck source=lib/common.sh
|
|
source "$(dirname "$SELF")/lib/common.sh"
|
|
|
|
usage() {
|
|
cat <<USAGE
|
|
Aufruf: sudo deploy/update.sh [--help]
|
|
|
|
Aktualisiert eine bestehende Installation aus dem aktuellen Checkout (vorher git pull).
|
|
Ablauf: DB-Backup, rsync nach $APP_DIR, pip install, systemd-Units, Neustart, /health-Check.
|
|
USAGE
|
|
}
|
|
|
|
current_rev() {
|
|
git -c safe.directory="$REPO_DIR" -C "$REPO_DIR" rev-parse --short HEAD 2>/dev/null || true
|
|
}
|
|
|
|
rollback_hint() {
|
|
local previous backup
|
|
previous=$(cat "$DEPLOYED_REV_FILE" 2>/dev/null || true)
|
|
backup=$(latest_backup)
|
|
warn "Update fehlgeschlagen. Logs: journalctl -u $SERVICE_NAME -n 100 --no-pager"
|
|
warn "Rollback: im Checkout auf den vorherigen Stand wechseln${previous:+ (zuletzt ausgerollt: $previous)} und update.sh erneut ausführen."
|
|
if [[ -n $backup ]]; then
|
|
warn "Bei Schema- oder Datenproblemen Dienst stoppen und Backup zurückspielen: $backup (siehe deploy/README.md, Abschnitt Restore)."
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
case ${1:-} in -h|--help) usage; return 0 ;; "") ;; *) usage >&2; return 2 ;; esac
|
|
require_root
|
|
[[ -d $APP_DIR/.venv ]] || die "Keine Installation unter $APP_DIR gefunden. Zuerst deploy/setup-lxc.sh ausführen."
|
|
check_python_version
|
|
|
|
if [[ -f $(db_file) ]]; then
|
|
"$APP_DIR/deploy/backup.sh"
|
|
else
|
|
warn "Keine Datenbank vorhanden, Backup übersprungen."
|
|
fi
|
|
|
|
sync_code
|
|
ensure_venv
|
|
install_units
|
|
systemctl restart "$SERVICE_NAME"
|
|
|
|
if wait_health; then
|
|
current_rev > "$DEPLOYED_REV_FILE.tmp" && mv -f "$DEPLOYED_REV_FILE.tmp" "$DEPLOYED_REV_FILE"
|
|
log "Update erfolgreich."
|
|
else
|
|
rollback_hint
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
main "$@"
|