From 9e63c0722e076c77752caaecf6c40fed35a602f0 Mon Sep 17 00:00:00 2001 From: Leonid Pershin Date: Fri, 21 Aug 2026 10:23:35 +0300 Subject: [PATCH] Enhance bootstrap script for .NET installation and error handling - Added `wget` to the package installation list for improved script functionality. - Implemented a fallback mechanism using `curl` for .NET installation if the primary script fails, enhancing robustness. - Updated ownership change for the installation directory to ensure proper permissions for the user. - Enhanced logging for error scenarios during .NET installation, providing clearer feedback for troubleshooting. - Added tests to verify the new fallback functionality and ownership changes in the bootstrap script. --- src/gpu_rent/remote/bootstrap.sh | 28 +++++++++++++++++++++++++--- tests/test_bootstrap.py | 4 ++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/gpu_rent/remote/bootstrap.sh b/src/gpu_rent/remote/bootstrap.sh index 5321185..72a183d 100644 --- a/src/gpu_rent/remote/bootstrap.sh +++ b/src/gpu_rent/remote/bootstrap.sh @@ -93,7 +93,7 @@ else log "light запрошен, но маркера нет — полный apt" fi apt-get update -qq - apt-get install -y -qq git python3 python3-venv python3-pip python3-full curl ca-certificates + apt-get install -y -qq git python3 python3-venv python3-pip python3-full curl wget ca-certificates fi ensure_data_mount @@ -148,17 +148,39 @@ else log "SwarmUI уже в ${SWARM_ROOT} (update off)" fi +# Clone runs as root; Swarm's linux-dotnet-install.sh wget -O into launchtools/ +# must be writable by SWARM_USER (otherwise: "dotnet-install.sh: Permission denied"). +chown -R "${SWARM_USER}:${SWARM_USER}" "$SWARM_ROOT" + +install_dotnet_via_curl() { + # Fallback when Swarm script fails (no wget, perms, CDN blip). + local install_dir="/home/${SWARM_USER}/.dotnet" + local script="/tmp/gpu-rent-dotnet-install.sh" + log "fallback: curl → ${script}, install → ${install_dir}" + curl -fsSL "https://dot.net/v1/dotnet-install.sh" -o "$script" + chmod +x "$script" + sudo -u "$SWARM_USER" bash "$script" --channel 10.0 --runtime aspnetcore --install-dir "$install_dir" + sudo -u "$SWARM_USER" bash "$script" --channel 10.0 --install-dir "$install_dir" + sudo -u "$SWARM_USER" bash "$script" --channel 8.0 --runtime aspnetcore --install-dir "$install_dir" + sudo -u "$SWARM_USER" bash "$script" --channel 8.0 --install-dir "$install_dir" + rm -f "$script" +} + if [[ ! -x /usr/share/dotnet/dotnet && ! -x "/home/${SWARM_USER}/.dotnet/dotnet" ]]; then if [[ -f "${SWARM_ROOT}/launchtools/linux-dotnet-install.sh" ]]; then log "ставим .NET SDK (скрипт SwarmUI)" # SwarmUI's linux-dotnet-install.sh does `cd launchtools` and # `./launchtools/dotnet-install.sh` — must run from repo root. if ! sudo -u "$SWARM_USER" bash -c "cd \"$SWARM_ROOT\" && bash launchtools/linux-dotnet-install.sh"; then - log "WARN: linux-dotnet-install.sh завершился с ошибкой" + log "WARN: linux-dotnet-install.sh завершился с ошибкой — пробуем curl fallback" + install_dotnet_via_curl || log "WARN: curl fallback тоже упал" fi + else + log "нет linux-dotnet-install.sh — curl fallback" + install_dotnet_via_curl || true fi if [[ ! -x /usr/share/dotnet/dotnet && ! -x "/home/${SWARM_USER}/.dotnet/dotnet" ]]; then - log "ERROR: .NET не установлен ($HOME/.dotnet или /usr/share/dotnet) — SwarmUI не стартует" + log "ERROR: .NET не установлен (/home/${SWARM_USER}/.dotnet или /usr/share/dotnet) — SwarmUI не стартует" exit 1 fi log ".NET ok: $(sudo -u "$SWARM_USER" bash -lc 'command -v dotnet || echo /home/'"$SWARM_USER"'/.dotnet/dotnet')" diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index d7c687b..1a722c5 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -19,3 +19,7 @@ def test_bootstrap_script_is_native_swarmui(): assert "light bootstrap — пропускаем apt-get" in script # llm-only re-up can skip apt when data marker exists (not only Swarm boot marker) assert 'MARKER_DATA' in script or ".gpu-rent-ready" in script + # .NET: chown before Swarm install script; curl fallback if wget/perms fail + assert "install_dotnet_via_curl" in script + assert "chown -R" in script + assert "wget" in script