Promote v0.11.0 to production
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
# # worker (enroll against a controller with a single-use token from its UI):
|
||||
# sudo ./deployments/install/gpuk install --mode worker \
|
||||
# --controller wss://controller.lan:8443 --enroll-token - \
|
||||
# --cache-dir /mnt/models --binary apps/worker/target/release/gpu-kitchen-worker
|
||||
# --cache-dir /mnt/models --binary target/release-worker/gpu-kitchen-worker
|
||||
#
|
||||
# Control:
|
||||
# gpuk status | apply | update | enroll | logs | manifest | uninstall
|
||||
@@ -57,6 +57,12 @@ RETIRE_UNIT="$(dirname "$UNIT_DEST")/$RETIRE_SERVICE.service"
|
||||
RETIRE_TIMER="$(dirname "$UNIT_DEST")/$RETIRE_SERVICE.timer"
|
||||
RETIRE_PENDING="$ETC_DIR/beta-retirement-pending"
|
||||
RETIRE_STATE="$ETC_DIR/beta-retirement-state"
|
||||
# [OPS-136] The optional daily backup: written only by `gpuk backup-timer on`.
|
||||
BACKUP_SERVICE="gpu-kitchen-backup"
|
||||
BACKUP_UNIT="$(dirname "$UNIT_DEST")/$BACKUP_SERVICE.service"
|
||||
BACKUP_TIMER="$(dirname "$UNIT_DEST")/$BACKUP_SERVICE.timer"
|
||||
# [OPS-97] The off-site copy tool, put on a controller by `gpuk install` and `gpuk update`.
|
||||
OFFSITE_DEST="$(dirname "$BIN_DEST")/gpuk-offsite-restic"
|
||||
# Outside ETC_DIR: purge must not replace the inode used to serialize lifecycle commands.
|
||||
LIFECYCLE_LOCK="$ETC_DIR.lifecycle.lock"
|
||||
|
||||
@@ -64,6 +70,11 @@ LIFECYCLE_LOCK="$ETC_DIR.lifecycle.lock"
|
||||
GPUK_RELEASE_BASE="${GPUK_RELEASE_BASE:-}"
|
||||
|
||||
die() { echo "gpuk: $*" >&2; exit 1; }
|
||||
# A token written on the command line shows in `ps` and the shell history: `-` reads it from
|
||||
# the terminal, out of both.
|
||||
token_on_command_line() {
|
||||
[ "$1" = "-" ] || echo "==> warning: the enrollment token is on the command line, where ps and the shell history keep it. Pass --enroll-token - to type it instead." >&2
|
||||
}
|
||||
|
||||
# Root, or able to do the job anyway. Fail with a clear message BEFORE touching
|
||||
# /etc, /usr/local/bin or systemd. Against a user-owned prefix it simply works.
|
||||
@@ -222,6 +233,258 @@ install_cli() {
|
||||
echo "==> installed $CLI_DEST"
|
||||
}
|
||||
|
||||
# [OPS-97] The off-site tool ships inside this very gpuk, whose sha256 the signed channel
|
||||
# vouches for: a controller gets it from `gpuk install`, its new release from `gpuk update`,
|
||||
# never from a copy made by hand. tests/gates/gpuk-backup-offsite.test.mjs keeps the copy
|
||||
# below equal to tools/offsite-restic.sh, byte for byte.
|
||||
install_offsite_tool() {
|
||||
[ ! -L "$OFFSITE_DEST" ] || die "refusing a symlink for the off-site tool at $OFFSITE_DEST"
|
||||
if [ -f "$OFFSITE_DEST" ] && offsite_tool_source | cmp -s - "$OFFSITE_DEST"; then return 0; fi
|
||||
rm -f "$OFFSITE_DEST.new"
|
||||
{ offsite_tool_source > "$OFFSITE_DEST.new" && chmod 0755 "$OFFSITE_DEST.new" \
|
||||
&& mv -f "$OFFSITE_DEST.new" "$OFFSITE_DEST"; } \
|
||||
|| { rm -f "$OFFSITE_DEST.new"; die "cannot install the off-site tool at $OFFSITE_DEST"; }
|
||||
echo "==> installed $OFFSITE_DEST (the off-site copy of gpuk backup --offsite)"
|
||||
}
|
||||
|
||||
# BEGIN OFF-SITE TOOL — tools/offsite-restic.sh, byte for byte; edit that file, then copy it here
|
||||
offsite_tool_source() {
|
||||
cat <<'GPUK_OFFSITE_RESTIC'
|
||||
#!/usr/bin/env bash
|
||||
# [OPS-05][OPS-89][OPS-90] The off-site copy of a GPU Kitchen backup: one validated archive
|
||||
# directory into an encrypted restic repository on S3-compatible storage, then the retention
|
||||
# policy, then a check. One tool for both scopes:
|
||||
#
|
||||
# hub run from the hub deployment directory (installed there by every hub
|
||||
# deployment); settings read alone from its .env through ./hub-env.sh. It is
|
||||
# the GPUK_BACKUP_OFFSITE_CMD of the daily unit, probed by every hub deployment.
|
||||
# controller GPUK_OFFSITE_ENV names a settings file (mode 0600, root's), by default
|
||||
# /etc/gpu-kitchen/offsite.env; `gpuk backup --offsite` calls this tool.
|
||||
# [OPS-97] deployments/install/gpuk carries this file byte for byte and installs it
|
||||
# as gpuk-offsite-restic: a change here is copied there too (a gate compares them).
|
||||
#
|
||||
# offsite-restic.sh ARCHIVE_DIR copy one archive, prune, check (exit 0 = copied)
|
||||
# offsite-restic.sh snapshots list what the repository holds for this scope
|
||||
# offsite-restic.sh age seconds since the newest daily snapshot
|
||||
# offsite-restic.sh restore SNAPSHOT DEST restore one snapshot (an id, or `latest` daily)
|
||||
# into DEST, which must not exist — the restore drill
|
||||
#
|
||||
# Settings:
|
||||
# GPUK_OFFSITE_RESTIC_REPOSITORY s3:https://<endpoint>/<bucket>[/<prefix>] — S3-compatible
|
||||
# only, never on this host
|
||||
# GPUK_OFFSITE_RESTIC_PASSWORD encrypts the repository; ALSO keep it in the recovery set
|
||||
# (OPS-04): without it no copy can be read
|
||||
# GPUK_OFFSITE_S3_ACCESS_KEY_ID a key restricted to that bucket
|
||||
# GPUK_OFFSITE_S3_SECRET_ACCESS_KEY
|
||||
# GPUK_OFFSITE_S3_REGION optional (default: the endpoint's)
|
||||
# GPUK_OFFSITE_KEEP_DAILY/WEEKLY/MONTHLY optional retention of the daily archives
|
||||
# (default 7 / 5 / 12, OPS-05)
|
||||
# GPUK_OFFSITE_HOST controller only: the snapshot host name (default
|
||||
# gpu-kitchen-controller-<short hostname>)
|
||||
# GPUK_OFFSITE_CACHE controller only: restic's cache (default
|
||||
# /var/cache/gpu-kitchen-offsite)
|
||||
#
|
||||
# restic runs from a pinned image, so the host needs Docker only. Every snapshot of a scope
|
||||
# is taken from the same mount point under one fixed host name, so retention groups across
|
||||
# days and survives a move to another server. restic keeps a local cache per user (root for
|
||||
# the units, the deploy user for deployments), so a daily prune does not download the
|
||||
# repository's indexes again (OPS-89).
|
||||
set -euo pipefail
|
||||
|
||||
RESTIC_IMAGE="restic/restic:0.18.1@sha256:39d9072fb5651c80d75c7a811612eb60b4c06b32ffe87c2e9f3c7222e1797e76"
|
||||
|
||||
die() {
|
||||
echo "offsite-restic: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
sed -n '12,16p' "$0" | sed 's/^# //' >&2
|
||||
exit 2
|
||||
}
|
||||
|
||||
command -v docker >/dev/null 2>&1 || die "docker is required"
|
||||
|
||||
if [ -n "${GPUK_OFFSITE_ENV:-}" ]; then
|
||||
SCOPE=controller
|
||||
[ -f "$GPUK_OFFSITE_ENV" ] || die "no settings file at $GPUK_OFFSITE_ENV"
|
||||
case "$(stat -c %a "$GPUK_OFFSITE_ENV")" in
|
||||
600 | 400) ;;
|
||||
*) die "$GPUK_OFFSITE_ENV holds secrets: make it mode 0600" ;;
|
||||
esac
|
||||
# One variable at a time, quotes removed, nothing interpolated (same form as hub-env.sh).
|
||||
setting() {
|
||||
local value
|
||||
value=$(sed -n "s/^$1=//p" "$GPUK_OFFSITE_ENV" | tail -n 1)
|
||||
value=${value#\'}
|
||||
value=${value%\'}
|
||||
printf '%s\n' "$value"
|
||||
}
|
||||
SNAPSHOT_HOST=$(setting GPUK_OFFSITE_HOST)
|
||||
SNAPSHOT_HOST=${SNAPSHOT_HOST:-gpu-kitchen-controller-$(hostname -s)}
|
||||
TAG=gpuk-controller
|
||||
CACHE_ROOT=$(setting GPUK_OFFSITE_CACHE)
|
||||
CACHE_ROOT=${CACHE_ROOT:-/var/cache/gpu-kitchen-offsite}
|
||||
WHERE="$GPUK_OFFSITE_ENV"
|
||||
else
|
||||
SCOPE=hub
|
||||
[ -f .env ] && [ -x ./hub-env.sh ] \
|
||||
|| die "run it from the hub deployment directory (.env and hub-env.sh), or set GPUK_OFFSITE_ENV"
|
||||
setting() { ./hub-env.sh get "$1"; }
|
||||
SNAPSHOT_HOST=gpu-kitchen-hub
|
||||
TAG=gpuk-hub
|
||||
CACHE_ROOT="$PWD/.restic-cache"
|
||||
WHERE=.env
|
||||
fi
|
||||
MOUNT="/$TAG-archive"
|
||||
|
||||
RESTIC_REPOSITORY=$(setting GPUK_OFFSITE_RESTIC_REPOSITORY)
|
||||
RESTIC_PASSWORD=$(setting GPUK_OFFSITE_RESTIC_PASSWORD)
|
||||
AWS_ACCESS_KEY_ID=$(setting GPUK_OFFSITE_S3_ACCESS_KEY_ID)
|
||||
AWS_SECRET_ACCESS_KEY=$(setting GPUK_OFFSITE_S3_SECRET_ACCESS_KEY)
|
||||
AWS_DEFAULT_REGION=$(setting GPUK_OFFSITE_S3_REGION)
|
||||
[ -n "$RESTIC_REPOSITORY" ] || die "GPUK_OFFSITE_RESTIC_REPOSITORY is not set in $WHERE"
|
||||
case "$RESTIC_REPOSITORY" in
|
||||
s3:*) ;;
|
||||
*) die "GPUK_OFFSITE_RESTIC_REPOSITORY must be an s3: repository: a copy on this host is not off-site" ;;
|
||||
esac
|
||||
[ -n "$RESTIC_PASSWORD" ] || die "GPUK_OFFSITE_RESTIC_PASSWORD is not set in $WHERE"
|
||||
[ -n "$AWS_ACCESS_KEY_ID" ] && [ -n "$AWS_SECRET_ACCESS_KEY" ] \
|
||||
|| die "GPUK_OFFSITE_S3_ACCESS_KEY_ID and GPUK_OFFSITE_S3_SECRET_ACCESS_KEY must be set in $WHERE"
|
||||
# Handed to docker by name only: a secret never appears on a command line.
|
||||
export RESTIC_REPOSITORY RESTIC_PASSWORD AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY
|
||||
[ -n "$AWS_DEFAULT_REGION" ] && export AWS_DEFAULT_REGION
|
||||
|
||||
count() {
|
||||
local value
|
||||
value=$(setting "$1")
|
||||
value=${value:-$2}
|
||||
[[ "$value" =~ ^[0-9]+$ ]] || die "$1 must be a whole number (got '$value')"
|
||||
printf '%s' "$value"
|
||||
}
|
||||
|
||||
# One cache per user: the root unit and the deploy user never share files.
|
||||
CACHE_DIR="$CACHE_ROOT/$(id -u)"
|
||||
mkdir -p "$CACHE_DIR"
|
||||
chmod 0700 "$CACHE_DIR"
|
||||
|
||||
# restic [docker args…] -- [restic args…]; runs as the calling user.
|
||||
restic() {
|
||||
local docker_args=()
|
||||
while [ "$#" -gt 0 ] && [ "$1" != "--" ]; do
|
||||
docker_args+=("$1")
|
||||
shift
|
||||
done
|
||||
shift
|
||||
local env_args=(-e RESTIC_REPOSITORY -e RESTIC_PASSWORD -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY)
|
||||
[ -n "${AWS_DEFAULT_REGION:-}" ] && env_args+=(-e AWS_DEFAULT_REGION)
|
||||
docker run --rm -i --user "$(id -u):$(id -g)" "${env_args[@]}" -v "$CACHE_DIR:/cache" \
|
||||
"${docker_args[@]}" "$RESTIC_IMAGE" --cache-dir /cache --retry-lock 10m "$@"
|
||||
}
|
||||
|
||||
ensure_repository() {
|
||||
local status=0
|
||||
restic -- cat config >/dev/null 2>&1 || status=$?
|
||||
case "$status" in
|
||||
0) ;;
|
||||
10)
|
||||
echo "offsite-restic: initialising the encrypted repository"
|
||||
restic -- init >/dev/null
|
||||
;;
|
||||
*) die "the repository cannot be opened (restic exit $status): check the endpoint, the key and the password" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
kind_of() {
|
||||
case "$SCOPE:$1" in
|
||||
hub:daily-*) echo daily ;;
|
||||
hub:predeploy-*) echo predeploy ;;
|
||||
hub:offsite-probe-*) echo offsite-probe ;;
|
||||
# `gpuk backup`'s own name, a UTC stamp: the controller's periodic archive.
|
||||
controller:[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]Z) echo daily ;;
|
||||
*) echo other ;;
|
||||
esac
|
||||
}
|
||||
|
||||
copy() {
|
||||
local archive="$1" absolute kind snapshot keep_daily keep_weekly keep_monthly
|
||||
[ -d "$archive" ] || die "$archive is not a directory"
|
||||
absolute=$(cd "$archive" && pwd -P)
|
||||
kind=$(kind_of "$(basename "$absolute")")
|
||||
keep_daily=$(count GPUK_OFFSITE_KEEP_DAILY 7)
|
||||
keep_weekly=$(count GPUK_OFFSITE_KEEP_WEEKLY 5)
|
||||
keep_monthly=$(count GPUK_OFFSITE_KEEP_MONTHLY 12)
|
||||
|
||||
ensure_repository
|
||||
snapshot=$(restic -v "$absolute:$MOUNT:ro" -- backup --json --quiet \
|
||||
--host "$SNAPSHOT_HOST" --tag "$TAG" --tag "$kind" "$MOUNT" \
|
||||
| sed -n 's/.*"message_type":"summary".*"snapshot_id":"\([0-9a-f]*\)".*/\1/p' | tail -n 1)
|
||||
[ -n "$snapshot" ] || die "restic reported no snapshot for $archive"
|
||||
|
||||
# The copy is only claimed once the repository gives back what was sent: every file's
|
||||
# size, and the checksums file byte for byte.
|
||||
local file local_size remote_size
|
||||
for file in $(cd "$absolute" && find . -type f | sed 's|^\./||' | sort); do
|
||||
local_size=$(stat -c %s "$absolute/$file")
|
||||
remote_size=$(restic -- ls --json "$snapshot" "$MOUNT/$file" \
|
||||
| grep '"struct_type":"node"' | sed -n 's/.*"size":\([0-9]*\).*/\1/p' | head -n 1)
|
||||
[ "$remote_size" = "$local_size" ] || die "$file: $local_size bytes here, '${remote_size:-none}' in snapshot $snapshot"
|
||||
done
|
||||
if [ -f "$absolute/SHA256SUMS" ]; then
|
||||
restic -- dump "$snapshot" "$MOUNT/SHA256SUMS" | cmp -s - "$absolute/SHA256SUMS" \
|
||||
|| die "SHA256SUMS in snapshot $snapshot differs from $archive"
|
||||
fi
|
||||
|
||||
# Retention (OPS-05), applied by a daily run only: the daily archives keep the policy and
|
||||
# one deployment probe is enough. Only those two tags are ever forgotten: any other snapshot
|
||||
# (a pre-deploy archive, or a pre-fresh one from before OPS-112) is never pruned here.
|
||||
if [ "$kind" = daily ]; then
|
||||
restic -- forget --quiet --host "$SNAPSHOT_HOST" --tag "$TAG,offsite-probe" \
|
||||
--group-by host,tags --keep-last 1
|
||||
local pruned
|
||||
pruned=$(restic -- forget --quiet --host "$SNAPSHOT_HOST" --tag "$TAG,daily" \
|
||||
--group-by host,tags --keep-daily "$keep_daily" --keep-weekly "$keep_weekly" \
|
||||
--keep-monthly "$keep_monthly" --prune 2>&1) \
|
||||
|| die "the retention policy could not be applied: $pruned"
|
||||
fi
|
||||
restic -- check --quiet || die "restic check failed after copying $archive"
|
||||
echo "offsite-restic: $archive is snapshot $snapshot ($kind)"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
"" | -h | --help) usage ;;
|
||||
snapshots)
|
||||
[ "$#" -eq 1 ] || usage
|
||||
restic -- snapshots --host "$SNAPSHOT_HOST" --tag "$TAG"
|
||||
;;
|
||||
age)
|
||||
[ "$#" -eq 1 ] || usage
|
||||
newest=$(restic -- snapshots --json --latest 1 --host "$SNAPSHOT_HOST" --tag "$TAG,daily" \
|
||||
| grep -o '"time":"[^"]*"' | sed 's/"time":"//; s/"$//' | sort | tail -n 1)
|
||||
[ -n "$newest" ] || die "the repository holds no daily snapshot"
|
||||
echo $(($(date -u +%s) - $(date -u -d "$newest" +%s)))
|
||||
;;
|
||||
restore)
|
||||
[ "$#" -eq 3 ] || usage
|
||||
[ ! -e "$3" ] || die "$3 already exists"
|
||||
mkdir -p "$3"
|
||||
dest=$(cd "$3" && pwd -P)
|
||||
# `latest` is the latest DAILY archive, never a deployment probe.
|
||||
tags="$TAG"
|
||||
[ "$2" = latest ] && tags="$TAG,daily"
|
||||
restic -v "$dest:/restore" -- \
|
||||
restore "$2:$MOUNT" --host "$SNAPSHOT_HOST" --tag "$tags" --target /restore
|
||||
echo "offsite-restic: snapshot $2 restored into $3"
|
||||
;;
|
||||
*)
|
||||
[ "$#" -eq 1 ] || usage
|
||||
copy "$1"
|
||||
;;
|
||||
esac
|
||||
GPUK_OFFSITE_RESTIC
|
||||
}
|
||||
# END OFF-SITE TOOL
|
||||
|
||||
gen_secret() { head -c 32 /dev/urandom | base64 | tr '+/' '-_' | tr -d '='; }
|
||||
|
||||
# BEGIN GENERATED INTERNET REACHABILITY — tools/gen-install-reachability.mjs from deployments/install/reachability.sh.in and packages/contracts/data/public-address-ranges.json; DO NOT EDIT
|
||||
@@ -720,7 +983,7 @@ cmd_install() {
|
||||
# `--token` is an ENROLLMENT token (single-use or shared), NOT a bearer:
|
||||
# the worker↔controller channel is cert-only since D11. `--token` is kept as
|
||||
# a spelling of `--enroll-token`.
|
||||
--enroll-token|--token) ENROLL_TOKEN="$2"; shift 2 ;;
|
||||
--enroll-token|--token) ENROLL_TOKEN="$2"; token_on_command_line "$2"; shift 2 ;;
|
||||
--health-port) HEALTH_PORT="$2"; shift 2 ;;
|
||||
--http-port) HTTP_PORT="$2"; shift 2 ;;
|
||||
--mtls-port) MTLS_PORT="$2"; shift 2 ;;
|
||||
@@ -923,6 +1186,7 @@ cmd_install() {
|
||||
if [ "$MODE" = "controller" ]; then
|
||||
prepare_claim_key
|
||||
[ ! -s "$CLAIM_KEY_FILE" ] || CLAIM_KEY_AVAILABLE=1
|
||||
install_offsite_tool
|
||||
fi
|
||||
|
||||
umask 077
|
||||
@@ -1061,7 +1325,7 @@ JSON
|
||||
# fresh render no longer carries it (a profile change drops GPUK_HSTS); any other
|
||||
# key was pushed by the controller and is kept. Keep this list in step with
|
||||
# render_controller_manifest.
|
||||
INSTALL_ENV_KEYS="NODE_ENV,TZ,GPUK_CLUSTER,GPUK_SELF_ENROLL_FILE,HF_HOME,GPUK_DATA_ROOT,GPUK_INSTALL_PROFILE,GPUK_HSTS,GPUK_SESSION_COOKIE_SECURE,GPUK_BOOTSTRAP_MUST_CHANGE,BACKEND_DOCKER_NETWORK,GPUK_PORT,GPUK_PUBLIC_PORT,GPUK_MTLS_PORT,GPUK_PUBLIC_MTLS_PORT,GPUK_PROXY_PUBLIC_PORT,GPUK_UI_BIND,GPUK_PROXY_PUBLIC_URL,GPUK_DOMAIN,GPUK_ALLOWED_HOSTS,GPUK_TRUST_PROXY,GPUK_TRUSTED_PROXY_CIDRS,GPUK_ACCEPT_SOURCE_CIDRS,GPUK_HOST_PUBLIC_IPV4"
|
||||
INSTALL_ENV_KEYS="NODE_ENV,TZ,GPUK_CLUSTER,GPUK_SELF_ENROLL_FILE,HF_HOME,GPUK_DATA_ROOT,GPUK_SECURITY_PROFILE,GPUK_HSTS,GPUK_SESSION_COOKIE_SECURE,GPUK_BOOTSTRAP_MUST_CHANGE,BACKEND_DOCKER_NETWORK,GPUK_PORT,GPUK_PUBLIC_PORT,GPUK_MTLS_PORT,GPUK_PUBLIC_MTLS_PORT,GPUK_PROXY_PUBLIC_PORT,GPUK_UI_BIND,GPUK_PROXY_PUBLIC_URL,GPUK_DOMAIN,GPUK_ALLOWED_HOSTS,GPUK_TRUST_PROXY,GPUK_TRUSTED_PROXY_CIDRS,GPUK_ACCEPT_SOURCE_CIDRS,GPUK_HOST_PUBLIC_IPV4"
|
||||
|
||||
# Write the manifest — or, when one exists, MERGE into it (INS-03). Re-running the
|
||||
# installer is the update path, and the manifest is not ours alone: since the first
|
||||
@@ -1116,7 +1380,7 @@ render_controller_manifest() {
|
||||
EXTRA_ENV="$EXTRA_ENV,\"GPUK_DATA_ROOT\":\"$(json_str "$DATA_ROOT")\""
|
||||
HOST_TZ=$(host_timezone)
|
||||
[ -z "$HOST_TZ" ] || EXTRA_ENV="$EXTRA_ENV,\"TZ\":\"$(json_str "$HOST_TZ")\""
|
||||
[ -z "$PROFILE" ] || EXTRA_ENV="$EXTRA_ENV,\"GPUK_INSTALL_PROFILE\":\"$(json_str "$PROFILE")\""
|
||||
[ -z "$PROFILE" ] || EXTRA_ENV="$EXTRA_ENV,\"GPUK_SECURITY_PROFILE\":\"$(json_str "$PROFILE")\""
|
||||
[ -z "${HOST_PUBLIC_IPV4:-}" ] \
|
||||
|| EXTRA_ENV="$EXTRA_ENV,\"GPUK_HOST_PUBLIC_IPV4\":\"$(json_str "$HOST_PUBLIC_IPV4")\""
|
||||
if [ "$PROFILE" = "public" ]; then
|
||||
@@ -1124,7 +1388,7 @@ render_controller_manifest() {
|
||||
EXTRA_ENV="$EXTRA_ENV,\"GPUK_SESSION_COOKIE_SECURE\":\"true\""
|
||||
fi
|
||||
# SEC-16: the DNS-rebinding Host guard stays on during the anonymous first run even
|
||||
# under `enforced`, so the operator's own name must be a known host of the install
|
||||
# under `enforced`, so the operator's own name must be a known host of the cluster
|
||||
# before the wizard can load through it — whatever the profile. SEC-15: that name
|
||||
# is served through a reverse proxy, whose X-Forwarded-For carries the real client.
|
||||
# [INS-85] [PRX-97] The same front serves inference.$DOMAIN: the proxy container must read
|
||||
@@ -1291,6 +1555,11 @@ image_repo() {
|
||||
esac
|
||||
}
|
||||
|
||||
# The epoch of a release tag: its first two numbers (vX.Y.Z → X.Y), empty for any other form.
|
||||
release_epoch() {
|
||||
printf '%s\n' "$1" | sed -n 's/^v\{0,1\}\([0-9][0-9]*\.[0-9][0-9]*\)\.[0-9][0-9]*$/\1/p'
|
||||
}
|
||||
|
||||
image_tag() {
|
||||
# `repo:tag@sha256:…` keeps the human-readable tag next to the content pin —
|
||||
# docker resolves by digest and ignores the tag. Strip the digest, then parse.
|
||||
@@ -1370,6 +1639,22 @@ ensure_minisign() { # $1 = 1 when nothing may be installed (dry run)
|
||||
die "minisign is required to verify the release and could not be installed automatically. Nothing was changed: run '$(minisign_manual_command)' as root, then re-run — or set GPUK_CHANNEL_INSECURE=1"
|
||||
}
|
||||
|
||||
# [OPS-20] A signed channel document carries a sequence that only grows, a rollback included
|
||||
# (a new document naming an older release): one below the highest this host accepted is an old
|
||||
# document replayed, refused. The highest is kept beside the installation's settings.
|
||||
check_channel_sequence() { # $1 = the verified document, $2 = 1 to remember it
|
||||
_seq=$(sed -n 's/.*"sequence"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' "$1" | head -1)
|
||||
_seen=$(cat "$ETC_DIR/channel-sequence" 2>/dev/null || true)
|
||||
case "$_seen" in '' | *[!0-9]*) _seen=0 ;; esac
|
||||
[ -n "$_seq" ] || _seq=0
|
||||
[ "$_seq" -ge "$_seen" ] \
|
||||
|| die "the release channel document is older than one this host already read (sequence $_seq, seen $_seen) — refusing a replayed document (OPS-20)"
|
||||
if [ "${2:-0}" = 1 ] && [ "$_seq" -gt "$_seen" ] && [ -d "$ETC_DIR" ] && [ -w "$ETC_DIR" ]; then
|
||||
printf '%s\n' "$_seq" > "$ETC_DIR/channel-sequence.tmp" \
|
||||
&& mv "$ETC_DIR/channel-sequence.tmp" "$ETC_DIR/channel-sequence"
|
||||
fi
|
||||
}
|
||||
|
||||
# Fetch latest.json AND its minisign signature, verify, and leave the verified
|
||||
# document at $CHANNEL_DOC. Fail-closed: no signature, bad signature, no
|
||||
# minisign CLI or no pinned key are all fatal — GPUK_CHANNEL_INSECURE=1 is the
|
||||
@@ -1395,6 +1680,7 @@ channel_fetch() {
|
||||
die "latest.json signature verification FAILED — refusing the channel document (OPS-20)"
|
||||
fi
|
||||
rm -f "$_sig"
|
||||
check_channel_sequence "$CHANNEL_DOC" "$([ "$(id -u 2>/dev/null)" = 0 ] && echo 1)"
|
||||
}
|
||||
|
||||
channel_field() {
|
||||
@@ -1406,26 +1692,17 @@ channel_version() {
|
||||
channel_field "$CHANNEL_DOC" version
|
||||
}
|
||||
|
||||
# [OPS-10] [OPS-102] After a cold stop: start the daemon, then bring the app container back by
|
||||
# [OPS-102] After the carry-over's stop: start the daemon, then bring the app container back by
|
||||
# applying the manifest, as `gpuk apply` does. Starting the daemon alone does not: it does not
|
||||
# re-create the app container, and Docker never restarts a container that was stopped by hand
|
||||
# (unless-stopped) — a real installation stayed down after `gpuk backup`.
|
||||
# (unless-stopped) — a real installation once stayed down after such a stop.
|
||||
restart_controller() {
|
||||
systemctl start "$SERVICE_NAME" || return 1
|
||||
GPUK_MANIFEST_PATH="$MANIFEST" "$BIN_DEST" apply >/dev/null
|
||||
}
|
||||
|
||||
# ── backup ─────────────────────────────────────────────────────────────────────
|
||||
# OPS-10: the embedded Postgres is only backed up COLD — hot-copying pgdata with
|
||||
# a file tool is forbidden (torn pages). Order matters: stop the DAEMON first
|
||||
# (its reconciler would immediately restart a stopped app container), then the
|
||||
# container, snapshot, then restart_controller brings both back.
|
||||
# An install on an external DATABASE_URL is refused here: gpuk only owns the
|
||||
# embedded pgdata — back the real database up with pg_dump/backup-compose.sh.
|
||||
# The finished directory still has to be copied to encrypted off-host storage,
|
||||
# next to the recovery set (OPS-04/OPS-05: ENCRYPTION_KEY above all).
|
||||
# [OPS-10] The database must be at rest: only a container Docker CONFIRMS stopped, or
|
||||
# confirms absent, lets a copy or a second server open pgdata. A Docker that cannot say
|
||||
# [OPS-102] The database must be at rest: only a container Docker CONFIRMS stopped, or
|
||||
# confirms absent, lets a second server open pgdata. A Docker that cannot say
|
||||
# (daemon down, timeout) is a refusal, never "absent".
|
||||
stop_app_container() {
|
||||
docker stop "$1" >/dev/null 2>&1 || true
|
||||
@@ -1441,36 +1718,69 @@ stop_app_container() {
|
||||
esac
|
||||
}
|
||||
|
||||
# ── backup ─────────────────────────────────────────────────────────────────────
|
||||
# [OPS-10] A hot backup: pg_dump of the embedded database, run inside the running app
|
||||
# container by the image's own client — one consistent snapshot while the controller keeps
|
||||
# serving — then read back by pg_restore --list before it is published. Neither the daemon nor
|
||||
# the container stops. An install on an external DATABASE_URL is refused: back THAT database up
|
||||
# with its own tools. Archives that releases before this one made (kind cold-pgdata-snapshot, a
|
||||
# tar of the stopped pgdata) stay readable: `gpuk carry-over` tells the kinds apart by the
|
||||
# `kind` of backup-manifest.json.
|
||||
# [OPS-136] --scheduled is the timer's run: once its archive is published (and copied off this
|
||||
# host under --offsite), it removes the dumps older than BACKUP_LOCAL_DAYS that runs of this
|
||||
# command left under backups/ with their own UTC-stamp name; a cold archive and a folder named
|
||||
# by hand are never touched.
|
||||
BACKUP_DATABASE=gpuk_controlplane
|
||||
BACKUP_LOCAL_DAYS=7
|
||||
|
||||
# [OPS-90] The command named in $ETC_DIR/offsite.env (offsite-restic.sh, which reads its
|
||||
# settings there too), printed; checked before anything is written.
|
||||
offsite_command() {
|
||||
[ -f "$ETC_DIR/offsite.env" ] \
|
||||
|| die "--offsite needs $ETC_DIR/offsite.env (GPUK_BACKUP_OFFSITE_CMD and the GPUK_OFFSITE_* settings)"
|
||||
_cmd=$(sed -n "s/^GPUK_BACKUP_OFFSITE_CMD=//p" "$ETC_DIR/offsite.env" | tail -n 1 | tr -d "'")
|
||||
[ -x "$_cmd" ] || die "GPUK_BACKUP_OFFSITE_CMD in $ETC_DIR/offsite.env is not an executable: '$_cmd'"
|
||||
printf '%s\n' "$_cmd"
|
||||
}
|
||||
|
||||
# The controller whose embedded database gpuk may back up; prints its data root.
|
||||
backup_target() {
|
||||
[ -n "$(manifest_image)" ] || die "this is a worker node — no controller data to back up here"
|
||||
if grep -q '"DATABASE_URL"' "$MANIFEST" 2>/dev/null; then
|
||||
die "this install uses an external DATABASE_URL — back THAT database up (pg_dump); gpuk backup only dumps the embedded database"
|
||||
fi
|
||||
_target=$(manifest_data_root)
|
||||
[ -n "$_target" ] || die "no dataRoot in $MANIFEST"
|
||||
printf '%s\n' "$_target"
|
||||
}
|
||||
|
||||
cmd_backup() {
|
||||
need_root
|
||||
lifecycle_lock
|
||||
# [OPS-90] --offsite: once published, the archive goes off this host through the command
|
||||
# named in $ETC_DIR/offsite.env (offsite-restic.sh, which reads its settings there too).
|
||||
_offsite=0
|
||||
_scheduled=0
|
||||
_out=""
|
||||
for _a in "$@"; do
|
||||
case "$_a" in
|
||||
--offsite) _offsite=1 ;;
|
||||
--scheduled) _scheduled=1 ;;
|
||||
-*) die "unknown backup option: $_a" ;;
|
||||
*) _out="$_a" ;;
|
||||
esac
|
||||
done
|
||||
[ "$_scheduled" -eq 0 ] || [ -z "$_out" ] || die "--scheduled writes under the data root's backups/ only"
|
||||
_offsite_env="$ETC_DIR/offsite.env"
|
||||
_offsite_cmd=""
|
||||
if [ "$_offsite" -eq 1 ]; then
|
||||
[ -f "$_offsite_env" ] || die "--offsite needs $_offsite_env (GPUK_BACKUP_OFFSITE_CMD and the GPUK_OFFSITE_* settings)"
|
||||
_offsite_cmd=$(sed -n "s/^GPUK_BACKUP_OFFSITE_CMD=//p" "$_offsite_env" | tail -n 1 | tr -d "'")
|
||||
[ -x "$_offsite_cmd" ] || die "GPUK_BACKUP_OFFSITE_CMD in $_offsite_env is not an executable: '$_offsite_cmd'"
|
||||
fi
|
||||
_img=$(manifest_image)
|
||||
[ -n "$_img" ] || die "this is a worker node — no controller data to back up here"
|
||||
if grep -q '"DATABASE_URL"' "$MANIFEST" 2>/dev/null; then
|
||||
die "this install uses an external DATABASE_URL — back THAT database up (pg_dump); gpuk backup only snapshots the embedded pgdata"
|
||||
fi
|
||||
_root=$(manifest_data_root)
|
||||
[ -n "$_root" ] || die "no dataRoot in $MANIFEST"
|
||||
[ -d "$_root/pgdata" ] || die "no embedded pgdata under $_root — nothing to snapshot"
|
||||
[ "$_offsite" -eq 0 ] || _offsite_cmd=$(offsite_command) || exit 1
|
||||
_root=$(backup_target) || exit 1
|
||||
command -v sha256sum >/dev/null 2>&1 || die "sha256sum is required"
|
||||
_img=$(manifest_image)
|
||||
_cn=$(container_name)
|
||||
[ -n "$_cn" ] || die "no app container named in $MANIFEST"
|
||||
_state=$(docker inspect -f '{{.State.Status}}' "$_cn" 2>&1) \
|
||||
|| die "cannot read the state of $_cn — refusing the backup"
|
||||
[ "$_state" = running ] \
|
||||
|| die "container $_cn is $_state: the backup reads the running database — start GPU Kitchen first: sudo gpuk apply"
|
||||
|
||||
_out="${_out:-$_root/backups/$(date -u +%Y%m%dT%H%M%SZ)}"
|
||||
# A dangling link is something too: never write through a path someone else prepared.
|
||||
@@ -1478,63 +1788,138 @@ cmd_backup() {
|
||||
mkdir -p "$(dirname "$_out")"
|
||||
_tmp="$_out.partial"
|
||||
# [OPS-109] Private BEFORE the first byte: a local user who opens the archive while it is
|
||||
# written keeps reading it after a later chmod. The restart gets the caller's umask back.
|
||||
# written keeps reading it after a later chmod. The caller's umask comes back afterwards.
|
||||
_umask=$(umask)
|
||||
umask 077
|
||||
# rm removes a planted link itself, and mkdir without -p refuses whatever reappears.
|
||||
rm -rf "$_tmp"; mkdir -m 0700 "$_tmp" || die "cannot create $_tmp"
|
||||
# A failed dump leaves nothing behind: half a database is still the database.
|
||||
trap 'rm -rf "$_tmp"' EXIT
|
||||
|
||||
_cn=$(container_name)
|
||||
echo "==> Stopping $SERVICE_NAME (its reconciler would restart the container mid-snapshot)..."
|
||||
systemctl stop "$SERVICE_NAME" || die "could not stop $SERVICE_NAME"
|
||||
_restart_daemon() { umask "$_umask"; restart_controller 2>/dev/null || true; }
|
||||
trap _restart_daemon EXIT
|
||||
if [ -n "$_cn" ]; then
|
||||
echo "==> Stopping $_cn (cold snapshot — OPS-10)..."
|
||||
stop_app_container "$_cn" "a hot snapshot"
|
||||
fi
|
||||
|
||||
echo "==> Snapshotting $_root/pgdata..."
|
||||
tar -C "$_root" -czf "$_tmp/pgdata.tar.gz" pgdata || die "snapshot failed"
|
||||
echo "==> Dumping $BACKUP_DATABASE from $_cn (the controller keeps running)..."
|
||||
docker exec -u postgres "$_cn" sh -c \
|
||||
"exec \"/usr/lib/postgresql/\$GPUK_PG_MAJOR/bin/pg_dump\" -h /var/run/postgresql -Fc $BACKUP_DATABASE" \
|
||||
> "$_tmp/controller.dump" || die "pg_dump failed in $_cn: nothing was published"
|
||||
[ -s "$_tmp/controller.dump" ] || die "pg_dump wrote nothing in $_cn: nothing was published"
|
||||
docker exec -i -u postgres "$_cn" sh -c \
|
||||
"exec \"/usr/lib/postgresql/\$GPUK_PG_MAJOR/bin/pg_restore\" --list" \
|
||||
< "$_tmp/controller.dump" > /dev/null \
|
||||
|| die "the dump of $_cn does not read back (pg_restore --list): nothing was published"
|
||||
cp "$MANIFEST" "$_tmp/host-manifest.json" 2>/dev/null || true
|
||||
{
|
||||
echo "{"
|
||||
echo " \"created_utc\": \"$(date -u +%Y-%m-%dT%H:%M:%SZ)\","
|
||||
echo " \"image\": \"$(json_str "$_img")\","
|
||||
echo " \"data_root\": \"$(json_str "$_root")\","
|
||||
echo " \"kind\": \"cold-pgdata-snapshot\""
|
||||
echo " \"database\": \"$BACKUP_DATABASE\","
|
||||
echo " \"kind\": \"pg-dump\""
|
||||
echo "}"
|
||||
} > "$_tmp/backup-manifest.json"
|
||||
(cd "$_tmp" && sha256sum ./* > SHA256SUMS) || die "checksums failed"
|
||||
chmod 0700 "$_tmp"
|
||||
mv -T "$_tmp" "$_out" || die "cannot publish $_out"
|
||||
|
||||
echo "==> Restarting $SERVICE_NAME and the app container..."
|
||||
trap - EXIT
|
||||
umask "$_umask"
|
||||
restart_controller || die "could not restart GPU Kitchen — run: sudo gpuk apply"
|
||||
echo "backup: $_out"
|
||||
|
||||
if [ "$_offsite" -eq 1 ]; then
|
||||
echo "==> Copying $_out off this host..."
|
||||
GPUK_OFFSITE_ENV="$_offsite_env" "$_offsite_cmd" "$_out" \
|
||||
|| die "the off-site copy of $_out failed: the archive is on this host only"
|
||||
echo "Off-site copy done. Keep the recovery set off this host too"
|
||||
echo "(ENCRYPTION_KEY above all — without it the data is unrecoverable, OPS-04)."
|
||||
return 0
|
||||
else
|
||||
echo "Copy it to encrypted OFF-HOST storage together with the recovery set"
|
||||
echo "(ENCRYPTION_KEY above all — without it the data is unrecoverable, OPS-04)."
|
||||
fi
|
||||
echo "Copy it to encrypted OFF-HOST storage together with the recovery set"
|
||||
echo "(ENCRYPTION_KEY above all — without it the data is unrecoverable, OPS-04)."
|
||||
echo "A physical pgdata restore requires the same Postgres major and a throwaway"
|
||||
echo "host rehearsal first (OPS-10)."
|
||||
if [ "$_scheduled" -eq 1 ]; then
|
||||
find "$_root/backups" -mindepth 1 -maxdepth 1 -type d \
|
||||
-name '[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]Z' \
|
||||
-mtime "+$BACKUP_LOCAL_DAYS" | while IFS= read -r _old; do
|
||||
grep -q '"kind": *"pg-dump"' "$_old/backup-manifest.json" 2>/dev/null || continue
|
||||
rm -rf "$_old" && echo "==> removed $_old (a scheduled dump older than $BACKUP_LOCAL_DAYS days)"
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# [OPS-136] The daily backup is the operator's choice, off until asked: `on` writes a oneshot
|
||||
# service running `gpuk backup --scheduled` (with --offsite when asked, checked now) and a daily
|
||||
# Persistent timer — a firing missed while the host was down runs at its next boot; `off`
|
||||
# removes both. A failed run is a failed unit: systemctl --failed, journalctl -u.
|
||||
cmd_backup_timer() {
|
||||
need_root
|
||||
lifecycle_lock
|
||||
_action="${1:-}"
|
||||
[ $# -eq 0 ] || shift
|
||||
_flags=""
|
||||
for _a in "$@"; do
|
||||
case "$_a" in
|
||||
--offsite) [ "$_action" = on ] || die "--offsite goes with: gpuk backup-timer on"; _flags=" --offsite" ;;
|
||||
*) die "unknown backup-timer option: $_a (expected: on [--offsite] | off)" ;;
|
||||
esac
|
||||
done
|
||||
for _unit in "$BACKUP_UNIT" "$BACKUP_TIMER"; do
|
||||
[ ! -L "$_unit" ] || die "refusing a symlink for the backup timer at $_unit"
|
||||
done
|
||||
case "$_action" in
|
||||
on)
|
||||
backup_target >/dev/null || exit 1
|
||||
[ -z "$_flags" ] || offsite_command >/dev/null || exit 1
|
||||
[ -x "$CLI_DEST" ] || die "gpuk is not installed at $CLI_DEST: run gpuk install first"
|
||||
(
|
||||
umask 022
|
||||
cat > "$BACKUP_UNIT" <<UNIT
|
||||
[Unit]
|
||||
Description=GPU Kitchen controller backup (pg_dump, the controller keeps running)
|
||||
After=docker.service $SERVICE_NAME.service
|
||||
Wants=docker.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=$CLI_DEST backup --scheduled$_flags
|
||||
User=root
|
||||
UNIT
|
||||
cat > "$BACKUP_TIMER" <<UNIT
|
||||
[Unit]
|
||||
Description=Daily GPU Kitchen controller backup
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 03:30:00
|
||||
Persistent=true
|
||||
RandomizedDelaySec=30m
|
||||
Unit=$BACKUP_SERVICE.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
UNIT
|
||||
) || die "cannot write the backup timer next to $UNIT_DEST"
|
||||
chmod 0644 "$BACKUP_UNIT" "$BACKUP_TIMER"
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now "$BACKUP_SERVICE.timer" || die "cannot enable $BACKUP_SERVICE.timer"
|
||||
echo "==> daily backup on: $CLI_DEST backup --scheduled$_flags (systemctl list-timers $BACKUP_SERVICE.timer)"
|
||||
;;
|
||||
off)
|
||||
if [ -e "$BACKUP_UNIT" ] || [ -e "$BACKUP_TIMER" ]; then
|
||||
systemctl disable --now "$BACKUP_SERVICE.timer" || die "cannot disable $BACKUP_SERVICE.timer"
|
||||
rm -f "$BACKUP_UNIT" "$BACKUP_TIMER"
|
||||
systemctl daemon-reload
|
||||
echo "==> daily backup off; the archives already taken stay where they are"
|
||||
else
|
||||
echo "The daily backup is not on."
|
||||
fi
|
||||
;;
|
||||
*) die "expected: gpuk backup-timer on [--offsite] | off" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ── carry-over ─────────────────────────────────────────────────────────────────
|
||||
# [OPS-100] [OPS-101] [OPS-102] Copies the recipes, templates, benchmarks, evaluations and baskets of a
|
||||
# backup into THIS installation's database — what a reinstall on a new database baseline would
|
||||
# backup into THIS cluster's database — what a reinstall on a new database baseline would
|
||||
# otherwise lose. Not a restore (OPS-09): the live database is never dropped or replaced; it
|
||||
# receives those rows, with the engines, models and GPU configs they use, in one transaction.
|
||||
# receives those rows, with the engines and models they use, in one transaction. A backup of
|
||||
# another epoch is refused before anything stops ([OPS-115]: an epoch starts from zero).
|
||||
# The work is the image's own (deployments/controller/carry-over.sh: reset-db's table list and
|
||||
# rules), in a one-off container of the installed image, the controller stopped as for a backup.
|
||||
# rules), in a one-off container of the installed image, the controller stopped first: that
|
||||
# container's server opens the live pgdata itself.
|
||||
CARRY_OVER_SCRIPT=/usr/local/lib/gpuk-controller/carry-over/carry-over.sh
|
||||
CARRY_OVER_CONTAINER=gpu-kitchen-carry-over
|
||||
|
||||
@@ -1577,20 +1962,27 @@ cmd_carry_over() {
|
||||
command -v sha256sum >/dev/null 2>&1 || die "sha256sum is required"
|
||||
|
||||
# The archive: a `gpuk backup` folder, a Compose backup folder, or one pg_dump -Fc file.
|
||||
# [OPS-10] [OPS-112] A `gpuk backup` folder says what it holds in the `kind` of its
|
||||
# backup-manifest.json: `pg-dump` (controller.dump, the hot backup) or, from the releases
|
||||
# before it, `cold-pgdata-snapshot` (pgdata.tar.gz, a tar of the stopped pgdata) — users'
|
||||
# data, read as the throwaway server's own pgdata.
|
||||
if [ -d "$_archive" ]; then
|
||||
_dir=$(cd "$_archive" && pwd)
|
||||
if [ -f "$_dir/backup-manifest.json" ] && [ -f "$_dir/pgdata.tar.gz" ]; then
|
||||
grep -q '"kind": *"cold-pgdata-snapshot"' "$_dir/backup-manifest.json" \
|
||||
|| die "$_dir/backup-manifest.json does not describe a gpuk backup"
|
||||
_kind=pgdata
|
||||
_file=pgdata.tar.gz
|
||||
if [ -f "$_dir/backup-manifest.json" ]; then
|
||||
_backup_kind=$(sed -n 's/.*"kind"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$_dir/backup-manifest.json" | head -1)
|
||||
case "$_backup_kind" in
|
||||
pg-dump) _kind=dump; _file=controller.dump ;;
|
||||
cold-pgdata-snapshot) _kind=pgdata; _file=pgdata.tar.gz ;;
|
||||
*) die "$_dir/backup-manifest.json does not describe a gpuk backup (kind '$_backup_kind')" ;;
|
||||
esac
|
||||
[ -f "$_dir/$_file" ] || die "$_dir holds no $_file, which its backup-manifest.json announces"
|
||||
elif [ -f "$_dir/manifest.env" ] && [ -f "$_dir/backend.dump" ]; then
|
||||
grep -qx 'format=gpuk-compose-backup-v1' "$_dir/manifest.env" \
|
||||
|| die "$_dir/manifest.env does not describe a Compose backup"
|
||||
_kind=dump
|
||||
_file=backend.dump
|
||||
else
|
||||
die "$_dir is neither a gpuk backup (pgdata.tar.gz) nor a Compose backup (backend.dump)"
|
||||
die "$_dir is neither a gpuk backup (backup-manifest.json) nor a Compose backup (backend.dump)"
|
||||
fi
|
||||
[ -f "$_dir/SHA256SUMS" ] || die "$_dir has no SHA256SUMS: refusing a backup that cannot be checked"
|
||||
elif [ -f "$_archive" ]; then
|
||||
@@ -1612,6 +2004,20 @@ cmd_carry_over() {
|
||||
echo "==> No checksum next to $_file: PostgreSQL checks the archive as it reads it."
|
||||
fi
|
||||
|
||||
# [OPS-115] [VER-06] A `gpuk backup` names the release that made it: one of another epoch
|
||||
# (the first two numbers of its version) is refused here, before anything stops; a bare dump
|
||||
# or a Compose backup, which name none, are judged when the archive is opened (exit 3 too).
|
||||
if [ -f "$_dir/backup-manifest.json" ]; then
|
||||
_backup_img=$(sed -n 's/.*"image"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$_dir/backup-manifest.json" | head -1)
|
||||
_backup_epoch=$(release_epoch "$(image_tag "$_backup_img")")
|
||||
_own_epoch=$(release_epoch "$(image_tag "$_img")")
|
||||
if [ -n "$_backup_epoch" ] && [ -n "$_own_epoch" ] && [ "$_backup_epoch" != "$_own_epoch" ]; then
|
||||
echo "gpuk: this backup was made by release $(image_tag "$_backup_img") (epoch $_backup_epoch); this cluster runs $(image_tag "$_img") (epoch $_own_epoch)." >&2
|
||||
echo "gpuk: an epoch starts from zero and takes nothing over from another — nothing was stopped, nothing copied." >&2
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
|
||||
docker image inspect "$_img" >/dev/null 2>&1 \
|
||||
|| die "the image $_img is not on this host: run 'gpuk apply' first"
|
||||
docker run --rm --network none --entrypoint /bin/sh "$_img" -c "test -x $CARRY_OVER_SCRIPT" \
|
||||
@@ -1652,7 +2058,7 @@ cmd_carry_over() {
|
||||
-v "$_root:$_root" ${_mount:+-v "$_mount"} "$_img" \
|
||||
--live-pgdata "$_pgdata" "--$_kind" "$_source" $_replace || _rc=$?
|
||||
if [ "$_rc" -ne 0 ]; then
|
||||
echo "gpuk: nothing was carried over; the installation's database is as it was." >&2
|
||||
echo "gpuk: nothing was carried over; the cluster's database is as it was." >&2
|
||||
exit "$_rc"
|
||||
fi
|
||||
trap - EXIT
|
||||
@@ -1661,7 +2067,7 @@ cmd_carry_over() {
|
||||
echo "==> Restarting $SERVICE_NAME and the app container..."
|
||||
restart_controller || die "could not restart GPU Kitchen — run: sudo gpuk apply"
|
||||
echo "Carried over: recipes, templates, benchmarks, evaluations, baskets and saved charts,"
|
||||
echo "with the engines, models and GPU configs they use."
|
||||
echo "with the engines and models they use."
|
||||
echo "Not carried over: nodes, GPUs, containers, accounts, keys and settings."
|
||||
}
|
||||
|
||||
@@ -1855,7 +2261,7 @@ cmd_enroll() {
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--controller) _url="$2"; shift 2 ;;
|
||||
--enroll-token|--token) _tok="$2"; shift 2 ;;
|
||||
--enroll-token|--token) _tok="$2"; token_on_command_line "$2"; shift 2 ;;
|
||||
*) die "unknown enroll option: $1" ;;
|
||||
esac
|
||||
done
|
||||
@@ -2137,6 +2543,7 @@ cmd_update() {
|
||||
# Validate the candidate before changing the installed manifest.
|
||||
[ "$_want" != "$_latest" ] || prepare_daemon
|
||||
update_cli "$_want"
|
||||
install_offsite_tool
|
||||
install_prepared_daemon
|
||||
|
||||
_new="$_repo:$_want"
|
||||
@@ -2444,6 +2851,14 @@ cmd_uninstall() {
|
||||
[ ! -e "$MACHINE_ID_FILE" ] || rm -f "$MACHINE_ID_FILE"
|
||||
[ ! -e "$BIN_DEST" ] || { rm -f "$BIN_DEST"; echo "==> removed $BIN_DEST"; }
|
||||
[ ! -e "$CLI_DEST" ] || { rm -f "$CLI_DEST"; echo "==> removed $CLI_DEST"; }
|
||||
for _unit in "$BACKUP_UNIT" "$BACKUP_TIMER"; do
|
||||
[ -e "$_unit" ] || continue
|
||||
systemctl disable --now "$BACKUP_SERVICE.timer" 2>/dev/null || true
|
||||
rm -f "$BACKUP_UNIT" "$BACKUP_TIMER"; systemctl daemon-reload 2>/dev/null || true
|
||||
echo "==> removed the daily backup timer"
|
||||
break
|
||||
done
|
||||
[ ! -e "$OFFSITE_DEST" ] || { rm -f "$OFFSITE_DEST"; echo "==> removed $OFFSITE_DEST"; }
|
||||
echo
|
||||
echo "Kept: the data root${_root:+ $_root} — database, models and secrets (ENCRYPTION_KEY)."
|
||||
echo "A new install over it reuses them. To delete it too, knowingly: rm -rf ${_root:-<data-root>}"
|
||||
@@ -2478,8 +2893,11 @@ gpuk — GPU Kitchen host daemon (gpu-kitchen-worker)
|
||||
gpuk update --check (controller) Compare the installed version with the release
|
||||
gpuk update --version <tag> (controller) Move to a specific release
|
||||
gpuk channel Fetch + VERIFY the release channel and print what it offers
|
||||
gpuk backup [DIR] [--offsite] (controller) Cold snapshot of the embedded pgdata (stop → tar → restart);
|
||||
gpuk backup [DIR] [--offsite] (controller) pg_dump of the running database, nothing stopped;
|
||||
--offsite then copies it with the command in /etc/gpu-kitchen/offsite.env
|
||||
(the installed gpuk-offsite-restic, configured there)
|
||||
gpuk backup-timer on [--offsite] | off (controller) A daily backup by a systemd timer (off
|
||||
until turned on); it keeps 7 days of its own dumps on this host
|
||||
gpuk carry-over <backup> [--replace] (controller) Copy the recipes, benchmarks, evaluations and
|
||||
baskets of a backup (gpuk backup folder or pg_dump file) into this database;
|
||||
--replace first deletes the ones it already has
|
||||
@@ -2505,6 +2923,7 @@ case "$cmd" in
|
||||
update) cmd_update "$@" ;;
|
||||
channel) cmd_channel ;;
|
||||
backup) cmd_backup "$@" ;;
|
||||
backup-timer) cmd_backup_timer "$@" ;;
|
||||
carry-over) cmd_carry_over "$@" ;;
|
||||
manifest) cat "$MANIFEST" ;;
|
||||
logs)
|
||||
|
||||
Reference in New Issue
Block a user