The downloader's test -f guard never picks up an upstream re-upload of an existing filename. The new script moves the old file aside, re-runs the compose downloader, restores on failure, and restarts llama-server. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
41 lines
1.6 KiB
Bash
Executable File
41 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Forces a fresh download of a model file listed in models.yml, replacing the one on disk.
|
|
# Why and how: docs/operations.md#forcing-a-model-re-download
|
|
set -euo pipefail
|
|
cd "$(dirname "$0")/.."
|
|
|
|
if [ $# -gt 1 ] || [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
|
|
echo "Usage: $0 [model-file] (default: LLAMA_MODEL_FILE from .env)" >&2
|
|
exit 1
|
|
fi
|
|
|
|
file="${1:-}"
|
|
if [ -z "$file" ]; then
|
|
[ -f .env ] || { echo ".env missing, run scripts/update.sh first" >&2; exit 1; }
|
|
file="$(grep -m1 '^LLAMA_MODEL_FILE=' .env | cut -d= -f2- | tr -d '\r"'"'" || true)"
|
|
[ -n "$file" ] || { echo "LLAMA_MODEL_FILE is not set in .env" >&2; exit 1; }
|
|
fi
|
|
grep -qxF " - file: $file" models.yml || { echo "$file is not listed in models.yml" >&2; exit 1; }
|
|
|
|
# Runs a snippet against the models volume; $1 in it is the model file.
|
|
in_volume() { docker compose --profile tools run --rm --entrypoint sh downloader -c "cd /models; $1" _ "$file"; }
|
|
|
|
# Put the previous file back if the download didn't finish, so a failed run never loses the working model.
|
|
ok=false
|
|
restore() {
|
|
$ok || in_volume '[ ! -f "$1.old" ] || { rm -f "$1" "$1.part"; mv "$1.old" "$1"; }' || true
|
|
}
|
|
trap restore EXIT
|
|
|
|
echo "==> moving aside the current $file (kept until the new download succeeds)"
|
|
in_volume '[ -f "$1" ] || { [ ! -f "$1.old" ] || mv "$1.old" "$1"; }; [ ! -f "$1" ] || mv -f "$1" "$1.old"; rm -f "$1.part"'
|
|
|
|
echo "==> downloading $file"
|
|
docker compose --profile tools run --rm downloader
|
|
|
|
ok=true
|
|
in_volume 'rm -f "$1.old"'
|
|
|
|
echo "==> restarting llama-server to load the new file"
|
|
docker compose restart llama-server
|