@echo off setlocal enabledelayedexpansion echo ======================================== echo RESTART WSL + GPU NODE echo ======================================== echo. REM ----- Step 1: check if WSL is running ----- echo [1/4] Checking WSL state... wsl --list --running | findstr /R /C:"Ubuntu" /C:"ubuntu" /C:"Default" >nul 2>&1 if errorlevel 1 ( echo WSL is not running. Starting it... wsl --list --verbose >nul 2>&1 REM Touch WSL to make sure the distro is awake wsl bash -c "echo started" >nul 2>&1 ) else ( echo WSL is already running. ) REM ----- Step 2: shut down WSL ----- echo. echo [2/4] Shutting down WSL... wsl --shutdown if errorlevel 1 ( echo WARNING: wsl --shutdown returned an error. goto :error ) REM Wait for WSL to fully terminate timeout /t 3 /nobreak >nul REM ----- Step 3: start WSL again ----- echo. echo [3/4] Starting WSL... REM Get WSL path of this script's directory set "WIN_DIR=%~dp0" set "WIN_DIR_TRIMMED=%WIN_DIR:~0,-1%" for /f "delims=" %%i in ('wsl wslpath -u "%WIN_DIR_TRIMMED%"') do set "WSL_DIR=%%i" REM Trigger WSL to start (any command will wake it up) wsl bash -c "echo WSL awake" if errorlevel 1 ( echo ERROR: failed to start WSL. goto :error ) echo WSL path: %WSL_DIR% REM ----- Step 4: ensure Docker is up and start GPU node containers ----- echo. echo [4/4] Starting Docker services... wsl bash -c "cd '%WSL_DIR%' && docker compose up -d" if errorlevel 1 ( echo ERROR: docker compose up failed. goto :error ) echo. echo ======================================== echo WSL restarted + GPU node started echo ======================================== echo. wsl bash -c "docker ps --filter 'name=gpu-node-'" echo. pause exit /b 0 :error echo. echo ======================================== echo FAILED — see errors above echo ======================================== pause exit /b 1