Enhance logging and timing in CLI and session operations

- Updated the `_print_checks` function to replace console prints with logging functions for better traceability.
- Introduced timing functionality in the `doctor`, `dry_run`, and `up` functions to log the duration of preflight checks.
- Modified the `wait_ssh` function to accept a logging callback, improving SSH wait feedback.
- Enhanced the `mark` method in `PhaseTimes` to log phase durations, aiding in performance analysis.
- Updated various remote scripts to ensure error messages are printed to stderr for better error handling.
This commit is contained in:
Leonid Pershin
2026-08-21 08:03:04 +03:00
parent 7756d0d4df
commit ccba40a228
16 changed files with 205 additions and 46 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ MARKER_DATA="${DATA_ROOT}/.gpu-rent-ready"
MARKER_BOOT="${SWARM_ROOT}/.gpu-rent-bootstrapped"
SWARM_REPO="https://github.com/mcmonkeyprojects/SwarmUI.git"
log() { echo "[gpu-rent] $*"; }
log() { echo "[gpu-rent] $*" >&2; }
if [[ "$(id -u)" -ne 0 ]]; then
echo "нужен root (sudo -n bash $0)" >&2
+2 -2
View File
@@ -192,7 +192,7 @@ def main() -> int:
print(f"{prefix} {reason}: {dest.name}")
if auth_host == "civitai" and not token:
failed += 1
print(f"{prefix} FAIL {dest.name}: нет CIVITAI токена", file=sys.stderr)
print(f"{prefix} FAIL {dest.name}: нет CIVITAI токена")
continue
try:
print(f"{prefix} качаю: {dest.name}", flush=True)
@@ -218,7 +218,7 @@ def main() -> int:
msg = str(exc)
if "401" in msg and auth_host == "hf":
msg += " — нужен HF_TOKEN в .env (huggingface.co/settings/tokens)"
print(f"{prefix} FAIL {dest.name}: {msg}", file=sys.stderr)
print(f"{prefix} FAIL {dest.name}: {msg}")
TOKEN_PATH.unlink(missing_ok=True)
HF_TOKEN_PATH.unlink(missing_ok=True)
print(f"seed итог: скачано {downloaded}, пропущено {skipped}, ошибок {failed} (из {total})")
+2 -2
View File
@@ -171,7 +171,7 @@ def update_installed_extras(known: set[str], update: bool, token: str = "") -> N
try:
update_tracking_branch(child, token=token)
except Exception as exc:
print(f"FAIL installed {child}: {exc}", file=sys.stderr)
print(f"FAIL installed {child}: {exc}")
raise
@@ -192,7 +192,7 @@ def main() -> int:
clone_one(job, token, update)
except Exception as exc:
failed += 1
print(f"FAIL {job.get('dest')}: {exc}", file=sys.stderr)
print(f"FAIL {job.get('dest')}: {exc}")
try:
update_installed_extras(known, update, token=token)
except Exception:
+8 -4
View File
@@ -14,7 +14,7 @@ UNIT="gpu-rent-llamacpp"
REPO="https://github.com/ggml-org/llama.cpp.git"
API_BASE="https://api.github.com/repos/ggml-org/llama.cpp"
log() { echo "[gpu-rent-llamacpp] $*"; }
log() { echo "[gpu-rent-llamacpp] $*" >&2; }
if [[ "$(id -u)" -ne 0 ]]; then
echo "нужен root" >&2
@@ -66,11 +66,11 @@ print(cands[0][1] if cands else "")
}
resolve_release_tag() {
# stdout = tag only (no log lines — callers capture via $())
if [[ -n "$LLAMACPP_TAG" ]]; then
echo "$LLAMACPP_TAG"
return
fi
log "WARN: LLAMACPP_TAG/ASSET_URL не заданы — берём latest (нет pin). См. docs/llm.md"
curl -fsSL "${API_BASE}/releases/latest" | python3 -c \
'import json,sys; print(json.load(sys.stdin).get("tag_name") or "")'
}
@@ -228,9 +228,13 @@ else
echo "asset-url" >"$STAMP"
chown "${SWARM_USER}:${SWARM_USER}" "$STAMP"
else
if [[ -z "$LLAMACPP_TAG" ]]; then
log "WARN: LLAMACPP_TAG/ASSET_URL не заданы — берём latest (нет pin). См. docs/llm.md"
fi
tag="$(resolve_release_tag)"
if [[ -z "$tag" ]]; then
log "не удалось определить release tag"
tag="$(printf '%s' "$tag" | tr -d '\r' | head -n1 | awk 'NF{print; exit}')"
if [[ -z "$tag" || "$tag" == *" "* || "$tag" == *"["* ]]; then
log "не удалось определить release tag (got: ${tag:-empty})"
exit 1
fi
if ! build_cuda_from_source "$tag"; then
+1 -1
View File
@@ -10,7 +10,7 @@ UNIT="gpu-rent-ollama"
GPU_JSON="${DATA_ROOT}/.gpu-rent-gpu.json"
OLLAMA_ENV_FILE="${DATA_ROOT}/.gpu-rent-ollama.env"
log() { echo "[gpu-rent-ollama] $*"; }
log() { echo "[gpu-rent-ollama] $*" >&2; }
if [[ "$(id -u)" -ne 0 ]]; then
echo "нужен root" >&2
+2 -2
View File
@@ -123,7 +123,7 @@ def main() -> int:
except OSError:
pass
if not JOBS.is_file():
print("no jobs file", file=sys.stderr)
print("no jobs file")
return 1
jobs = json.loads(JOBS.read_text(encoding="utf-8"))
if not isinstance(jobs, list) or not jobs:
@@ -167,7 +167,7 @@ def main() -> int:
" — токен есть, но отказано: проверь scopes / "
"Accept license на странице модели"
)
print(f"FAIL {name}: {msg}", file=sys.stderr)
print(f"FAIL {name}: {msg}")
try:
dest.with_suffix(dest.suffix + ".partial").unlink(missing_ok=True)
except OSError:
+2 -2
View File
@@ -110,7 +110,7 @@ def pull_stream(name: str, label: str) -> None:
def main() -> int:
if not JOBS.is_file():
print("no jobs file", file=sys.stderr)
print("no jobs file")
return 1
models = json.loads(JOBS.read_text(encoding="utf-8"))
if not isinstance(models, list) or not models:
@@ -135,7 +135,7 @@ def main() -> int:
have.add(name)
except (urllib.error.URLError, urllib.error.HTTPError, OSError, TimeoutError, RuntimeError) as exc:
failed += 1
print(f"FAIL pull {name}: {exc}", file=sys.stderr)
print(f"FAIL pull {name}: {exc}")
finally:
MARKER.unlink(missing_ok=True)
if failed:
+4 -4
View File
@@ -53,7 +53,7 @@ def main() -> int:
try:
raw = json.loads(KEYS_PATH.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError) as exc:
print(f"bad keys file: {exc}", file=sys.stderr)
print(f"bad keys file: {exc}")
return 1
finally:
try:
@@ -74,13 +74,13 @@ def main() -> int:
{"session_id": sid, "keyType": key_type, "key": value},
)
except (urllib.error.URLError, urllib.error.HTTPError, TimeoutError, OSError, json.JSONDecodeError) as exc:
print(f"SetAPIKey {key_type} failed: {exc}", file=sys.stderr)
print(f"SetAPIKey {key_type} failed: {exc}")
return 1
if resp.get("error"):
print(f"SetAPIKey {key_type}: {resp['error']}", file=sys.stderr)
print(f"SetAPIKey {key_type}: {resp['error']}")
return 1
if not resp.get("success"):
print(f"SetAPIKey {key_type}: unexpected {resp}", file=sys.stderr)
print(f"SetAPIKey {key_type}: unexpected {resp}")
return 1
print(f"SetAPIKey {key_type}=ok")
return 0