feat: add --upgrade one-liner and improve upgrade.sh
get.sh --upgrade: - Re-downloads installer files (compose.yaml, upgrade.sh, etc.) so the on-disk scripts are always current before upgrading - Then execs upgrade.sh with any passthrough flags (e.g. --image TAG) upgrade.sh improvements: - Platform-aware backup dir (Linux: /var/backups/triton, macOS: ~/Library/Application Support/triton/backups) - Reads POSTGRES_USER/POSTGRES_DB from .env instead of hardcoding - Uses detected runtime (podman/docker) for pg_dump exec - Explicit messaging that DB migrations run automatically on startup - Health check success confirms migrations applied - Prints rollback command pointing at the backup file Usage: curl -fsSL .../get.sh | sudo bash -s -- --upgrade curl -fsSL .../get.sh | sudo bash -s -- --upgrade --image ...:1.2.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
ffa10f9171
commit
bacccd9550
2 changed files with 64 additions and 14 deletions
29
get.sh
29
get.sh
|
|
@ -12,6 +12,14 @@
|
||||||
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
|
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
|
||||||
# | sudo bash -s -- --gateway-hostname manage.example.com --manage-host-ip 10.0.0.5
|
# | sudo bash -s -- --gateway-hostname manage.example.com --manage-host-ip 10.0.0.5
|
||||||
#
|
#
|
||||||
|
# Upgrade (pull latest image, run DB migrations, keep data):
|
||||||
|
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
|
||||||
|
# | sudo bash -s -- --upgrade
|
||||||
|
#
|
||||||
|
# Upgrade to a specific image tag:
|
||||||
|
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
|
||||||
|
# | sudo bash -s -- --upgrade --image ghcr.io/primatekuntech/triton-manage-server:1.2.0
|
||||||
|
#
|
||||||
# Uninstall (stop containers, keep data):
|
# Uninstall (stop containers, keep data):
|
||||||
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
|
# curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh \
|
||||||
# | sudo bash -s -- --uninstall
|
# | sudo bash -s -- --uninstall
|
||||||
|
|
@ -36,10 +44,12 @@ banner() { printf "\n${BOLD}%s${RESET}\n\n" "$*"; }
|
||||||
|
|
||||||
# ── arg pre-scan (before any output) ─────────────────────────────────────
|
# ── arg pre-scan (before any output) ─────────────────────────────────────
|
||||||
UNINSTALL=0
|
UNINSTALL=0
|
||||||
|
UPGRADE=0
|
||||||
PASSTHROUGH=()
|
PASSTHROUGH=()
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
--uninstall) UNINSTALL=1 ;;
|
--uninstall) UNINSTALL=1 ;;
|
||||||
|
--upgrade) UPGRADE=1 ;;
|
||||||
*) PASSTHROUGH+=("$arg") ;;
|
*) PASSTHROUGH+=("$arg") ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
@ -70,6 +80,25 @@ if [[ $UNINSTALL -eq 1 ]]; then
|
||||||
exec bash "${INSTALL_DIR}/uninstall.sh" "${PASSTHROUGH[@]}"
|
exec bash "${INSTALL_DIR}/uninstall.sh" "${PASSTHROUGH[@]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# ── upgrade shortcut ──────────────────────────────────────────────────────
|
||||||
|
if [[ $UPGRADE -eq 1 ]]; then
|
||||||
|
banner "▶ Triton Manage Server — Upgrade"
|
||||||
|
info "platform: $PLATFORM"
|
||||||
|
if [[ "$PLATFORM" == "linux" && $EUID -ne 0 ]]; then
|
||||||
|
die "run as root on Linux:\n\n curl -fsSL https://raw.githubusercontent.com/primatekuntech/triton-install/main/get.sh | sudo bash -s -- --upgrade"
|
||||||
|
fi
|
||||||
|
[[ -d "$INSTALL_DIR" ]] \
|
||||||
|
|| die "Triton Manage Server does not appear to be installed (${INSTALL_DIR} not found)"
|
||||||
|
info "refreshing installer files..."
|
||||||
|
for f in "${INSTALLER_FILES[@]}"; do
|
||||||
|
curl -fsSL "${REPO_BASE}/${f}" -o "${INSTALL_DIR}/${f}"
|
||||||
|
done
|
||||||
|
chmod +x "${INSTALL_DIR}/install.sh" "${INSTALL_DIR}/upgrade.sh" "${INSTALL_DIR}/uninstall.sh"
|
||||||
|
ok "installer files refreshed"
|
||||||
|
echo ""
|
||||||
|
exec bash "${INSTALL_DIR}/upgrade.sh" "${PASSTHROUGH[@]}"
|
||||||
|
fi
|
||||||
|
|
||||||
banner "▶ Triton Manage Server — Installer"
|
banner "▶ Triton Manage Server — Installer"
|
||||||
info "platform: $PLATFORM"
|
info "platform: $PLATFORM"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# upgrade.sh — pull the latest manage-server image and restart.
|
# upgrade.sh — pull the latest manage-server image and restart.
|
||||||
#
|
#
|
||||||
# Takes a pre-upgrade pg_dump. DB schema migrations run on startup.
|
# Takes a pre-upgrade pg_dump backup. DB schema migrations run automatically
|
||||||
|
# on container startup — no manual migration step required.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# sudo bash upgrade.sh # latest from ghcr.io
|
# sudo bash upgrade.sh # latest from ghcr.io
|
||||||
# sudo bash upgrade.sh --image TAG # pin a specific image
|
# sudo bash upgrade.sh --image TAG # pin a specific image tag
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
|
||||||
|
|
@ -17,6 +18,7 @@ die() { printf '[manage-server] error: %s\n' "$*" >&2; exit 1; }
|
||||||
[[ $EUID -eq 0 ]] || die "must run as root"
|
[[ $EUID -eq 0 ]] || die "must run as root"
|
||||||
[[ -f .env ]] || die ".env not found — run install.sh first"
|
[[ -f .env ]] || die ".env not found — run install.sh first"
|
||||||
|
|
||||||
|
# ── arg parsing ───────────────────────────────────────────────────────────
|
||||||
IMAGE=""
|
IMAGE=""
|
||||||
while [[ $# -gt 0 ]]; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
|
@ -26,39 +28,58 @@ while [[ $# -gt 0 ]]; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# ── runtime detection ─────────────────────────────────────────────────────
|
||||||
|
if command -v podman-compose >/dev/null 2>&1; then COMPOSE=(podman-compose); RUNTIME=podman
|
||||||
|
elif podman compose version >/dev/null 2>&1; then COMPOSE=(podman compose); RUNTIME=podman
|
||||||
|
elif docker compose version >/dev/null 2>&1; then COMPOSE=(docker compose); RUNTIME=docker
|
||||||
|
else die "no compose runtime found"; fi
|
||||||
|
|
||||||
|
# ── pin image if requested ────────────────────────────────────────────────
|
||||||
if [[ -n "$IMAGE" ]]; then
|
if [[ -n "$IMAGE" ]]; then
|
||||||
sed -i "s|^TRITON_MANAGE_IMAGE=.*|TRITON_MANAGE_IMAGE=$IMAGE|" .env
|
sed -i "s|^TRITON_MANAGE_IMAGE=.*|TRITON_MANAGE_IMAGE=$IMAGE|" .env
|
||||||
info "pinned image to $IMAGE"
|
info "pinned image to $IMAGE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if command -v podman-compose >/dev/null 2>&1; then COMPOSE=(podman-compose)
|
# ── pre-upgrade DB backup ─────────────────────────────────────────────────
|
||||||
elif podman compose version >/dev/null 2>&1; then COMPOSE=(podman compose)
|
case "$(uname -s)" in
|
||||||
elif docker compose version >/dev/null 2>&1; then COMPOSE=(docker compose)
|
Linux) BACKUP_DIR="/var/backups/triton" ;;
|
||||||
else die "no compose runtime found"; fi
|
Darwin) BACKUP_DIR="${HOME}/Library/Application Support/triton/backups" ;;
|
||||||
|
*) BACKUP_DIR="$SCRIPT_DIR/backups" ;;
|
||||||
|
esac
|
||||||
|
mkdir -p "$BACKUP_DIR"
|
||||||
|
DUMP_FILE="${BACKUP_DIR}/manage-pre-upgrade-$(date +%F-%H%M%S).sql.gz"
|
||||||
|
|
||||||
info "pre-upgrade DB backup..."
|
info "pre-upgrade DB backup..."
|
||||||
mkdir -p /var/backups/triton
|
PG_USER=$(grep -E '^POSTGRES_USER=' .env | cut -d= -f2)
|
||||||
DUMP_FILE="/var/backups/triton/manage-pre-upgrade-$(date +%F-%H%M%S).sql.gz"
|
PG_USER=${PG_USER:-triton}
|
||||||
podman exec triton-manage-db pg_dump -U triton triton_manage 2>/dev/null \
|
PG_DB=$(grep -E '^POSTGRES_DB=' .env | cut -d= -f2)
|
||||||
| gzip > "$DUMP_FILE" || die "pg_dump failed — aborting upgrade"
|
PG_DB=${PG_DB:-triton_manage}
|
||||||
info " saved: $DUMP_FILE"
|
|
||||||
|
|
||||||
|
"$RUNTIME" exec triton-manage-db pg_dump -U "$PG_USER" "$PG_DB" 2>/dev/null \
|
||||||
|
| gzip > "$DUMP_FILE" || die "pg_dump failed — aborting upgrade (DB container may not be running)"
|
||||||
|
info " backup saved: $DUMP_FILE"
|
||||||
|
|
||||||
|
# ── pull new image ────────────────────────────────────────────────────────
|
||||||
info "pulling latest image..."
|
info "pulling latest image..."
|
||||||
"${COMPOSE[@]}" --env-file .env pull manage-server
|
"${COMPOSE[@]}" --env-file .env pull manage-server
|
||||||
|
|
||||||
|
# ── recreate container (DB migrations run on startup) ─────────────────────
|
||||||
info "recreating manage-server container..."
|
info "recreating manage-server container..."
|
||||||
|
info " DB schema migrations will run automatically on startup"
|
||||||
"${COMPOSE[@]}" --env-file .env up -d --no-deps manage-server
|
"${COMPOSE[@]}" --env-file .env up -d --no-deps manage-server
|
||||||
|
|
||||||
|
# ── wait for healthy (confirms migrations succeeded) ──────────────────────
|
||||||
HOST_PORT=$(grep -E '^TRITON_MANAGE_HOST_PORT=' .env | cut -d= -f2)
|
HOST_PORT=$(grep -E '^TRITON_MANAGE_HOST_PORT=' .env | cut -d= -f2)
|
||||||
HOST_PORT=${HOST_PORT:-8082}
|
HOST_PORT=${HOST_PORT:-8082}
|
||||||
|
|
||||||
info "waiting for new container to become healthy..."
|
info "waiting for server to become healthy on :${HOST_PORT}..."
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${HOST_PORT}/" || echo "000")
|
CODE=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:${HOST_PORT}/" || echo "000")
|
||||||
if [[ "$CODE" == "302" || "$CODE" == "200" ]]; then
|
if [[ "$CODE" == "302" || "$CODE" == "200" ]]; then
|
||||||
info "upgrade complete"
|
info "upgrade complete — server is healthy (migrations applied)"
|
||||||
|
info " rollback if needed: gunzip -c ${DUMP_FILE} | $RUNTIME exec -i triton-manage-db psql -U ${PG_USER} ${PG_DB}"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
sleep 2
|
sleep 2
|
||||||
done
|
done
|
||||||
die "new container did not become healthy in 60s — check logs"
|
die "server did not become healthy in 60s — check logs: $RUNTIME logs triton-manageserver"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue