Add self-healing Cloudflare tunnel with 60s watchdog for USB deck.

Replaces fragile batch-based tunnel install with a single PowerShell
script (cloudflare/start-tunnel.ps1) that installs cloudflared as a
Windows service (admin) or runs as a background process (non-admin),
clears stale EventLog registry keys that caused service rollback, and
runs a 60-second watchdog that auto-restarts the connector on failure.
Hostname changed to aether.thetempleofdoom.com. LAUNCH.bat and
pack-usb.bat updated accordingly.
This commit is contained in:
AetherForge
2026-06-01 15:03:17 -07:00
parent feba06e008
commit 3605d540da
18 changed files with 1455 additions and 215 deletions

View File

@@ -32,11 +32,40 @@ if errorlevel 1 (
if not exist "%USB%" mkdir "%USB%"
:: ----------------------------------------------------------------
:: 0b. Ensure portable Go toolchain (forge on PCs without system Go)
:: ----------------------------------------------------------------
echo [0/8] Ensuring Go toolchain...
if not exist "%USB%\toolchain" mkdir "%USB%\toolchain"
if not exist "%USB%\toolchain\pack" mkdir "%USB%\toolchain\pack"
set "GO_PACK=%USB%\toolchain\pack\go1.26.3.windows-amd64.zip"
if not exist "%USB%\toolchain\go\bin\go.exe" (
if exist "C:\Program Files\Go\bin\go.exe" (
echo [0/8] Copying Go from C:\Program Files\Go...
if exist "%USB%\toolchain\go" rd /s /q "%USB%\toolchain\go"
robocopy "C:\Program Files\Go" "%USB%\toolchain\go" /E /NFL /NDL /NJH /NJS /NC /NS >nul
)
)
if not exist "%GO_PACK%" (
if exist "%ROOT%\usb\toolchain\pack\go1.26.3.windows-amd64.zip" (
copy /y "%ROOT%\usb\toolchain\pack\go1.26.3.windows-amd64.zip" "%GO_PACK%" >nul
echo [0/8] Offline Go zip copied from existing usb pack.
) else (
echo [0/8] Downloading offline Go zip for amd64...
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://go.dev/dl/go1.26.3.windows-amd64.zip' -OutFile '%GO_PACK%' }"
)
)
if exist "%USB%\toolchain\go\bin\go.exe" (
echo [0/8] Go toolchain ready in usb\toolchain\go\
) else (
echo [0/8] WARNING: Go not bundled — LAUNCH.bat will extract from pack zip on first run.
)
:: ----------------------------------------------------------------
:: 1. Build the frontend when npm is available
:: ----------------------------------------------------------------
if not defined SKIP_FRONTEND (
echo [1/7] Building frontend...
echo [1/8] Building frontend...
cd "%ROOT%\server\web"
call npm install --silent
call npm run build
@@ -47,15 +76,15 @@ if not defined SKIP_FRONTEND (
exit /b 1
)
cd "%ROOT%"
echo [1/7] Frontend built.
echo [1/8] Frontend built.
) else (
echo [1/7] Skipped - npm not found.
echo [1/8] Skipped - npm not found.
)
:: ----------------------------------------------------------------
:: 2. Build AetherForge.exe for Windows amd64
:: ----------------------------------------------------------------
echo [2/7] Compiling AetherForge.exe...
echo [2/8] Compiling AetherForge.exe...
cd "%ROOT%\server"
set "CGO_ENABLED=0"
set "GOOS=windows"
@@ -68,38 +97,48 @@ if errorlevel 1 (
exit /b 1
)
cd "%ROOT%"
echo [2/7] AetherForge.exe ready.
echo [2/8] AetherForge.exe ready.
:: ----------------------------------------------------------------
:: 3. Copy webroot - dashboard UI
:: ----------------------------------------------------------------
echo [3/7] Copying webroot...
echo [3/8] Copying webroot...
if exist "%USB%\webroot" rd /s /q "%USB%\webroot"
if exist "%ROOT%\server\webroot" (
xcopy /e /i /q "%ROOT%\server\webroot" "%USB%\webroot" >nul
) else if exist "%ROOT%\server\web\dist" (
if exist "%ROOT%\server\web\dist" (
xcopy /e /i /q "%ROOT%\server\web\dist" "%USB%\webroot" >nul
) else if exist "%ROOT%\server\webroot" (
xcopy /e /i /q "%ROOT%\server\webroot" "%USB%\webroot" >nul
) else (
echo ERROR: No webroot found. Run npm run build in server\web first.
pause
exit /b 1
)
echo [3/7] webroot copied.
echo [3/8] webroot copied.
:: ----------------------------------------------------------------
:: 4. Copy agent and fusion source - Forge needs these at runtime
:: ----------------------------------------------------------------
echo [4/7] Copying agent + fusion source...
echo [4/8] Copying agent + fusion source...
if exist "%USB%\agent" rd /s /q "%USB%\agent"
if exist "%USB%\fusion" rd /s /q "%USB%\fusion"
xcopy /e /i /q /EXCLUDE:"%ROOT%\usb_pack_exclude.txt" "%ROOT%\agent" "%USB%\agent" >nul
xcopy /e /i /q /EXCLUDE:"%ROOT%\usb_pack_exclude.txt" "%ROOT%\fusion" "%USB%\fusion" >nul
echo [4/7] Source trees copied.
robocopy "%ROOT%\agent" "%USB%\agent" /E /XD node_modules dist .git /XF crypto-miner-agent crypto-miner-fusion /NFL /NDL /NJH /NJS /NC /NS >nul
if errorlevel 8 (
echo ERROR: Failed to copy agent source.
pause
exit /b 1
)
robocopy "%ROOT%\fusion" "%USB%\fusion" /E /XD node_modules dist .git /XF crypto-miner-fusion /NFL /NDL /NJH /NJS /NC /NS >nul
if errorlevel 8 (
echo ERROR: Failed to copy fusion source.
pause
exit /b 1
)
echo [4/8] Source trees copied.
:: ----------------------------------------------------------------
:: 5. Launcher + docs (always sync from project root)
:: ----------------------------------------------------------------
echo [5/7] Syncing LAUNCH.bat, README, cloudflare...
echo [5/8] Syncing LAUNCH.bat, README, cloudflare...
copy /y "%ROOT%\LAUNCH.bat" "%USB%\LAUNCH.bat" >nul
if not exist "%USB%\README.txt" (
if exist "%ROOT%\usb\README.txt" copy /y "%ROOT%\usb\README.txt" "%USB%\README.txt" >nul
@@ -109,36 +148,47 @@ echo @echo off > "%USB%\run.bat"
echo rem AetherForge portable root marker >> "%USB%\run.bat"
if not exist "%USB%\cloudflare" mkdir "%USB%\cloudflare"
if exist "%ROOT%\usb\cloudflare\SETUP.txt" (
copy /y "%ROOT%\usb\cloudflare\SETUP.txt" "%USB%\cloudflare\SETUP.txt" >nul
)
if exist "%ROOT%\cloudflared-windows-amd64.msi" (
copy /y "%ROOT%\cloudflared-windows-amd64.msi" "%USB%\cloudflare\cloudflared-windows-amd64.msi" >nul
echo [5/7] cloudflared MSI bundled.
) else if exist "%ROOT%\usb\cloudflare\cloudflared-windows-amd64.msi" (
echo [5/7] cloudflared MSI already in usb\cloudflare\
) else (
echo [5/7] WARNING: No cloudflared MSI found. Tunnel auto-install skipped.
)
:: Preserve existing credentials.json if present (never overwrite operator tunnel)
if not exist "%USB%\cloudflare\credentials.json" (
if exist "%ROOT%\usb\cloudflare\credentials.json" (
copy /y "%ROOT%\usb\cloudflare\credentials.json" "%USB%\cloudflare\credentials.json" >nul
:: Core tunnel files — always sync from usb\cloudflare\
for %%F in (start-tunnel.ps1 tunnel-config.json SETUP.txt) do (
if exist "%ROOT%\usb\cloudflare\%%F" (
copy /y "%ROOT%\usb\cloudflare\%%F" "%USB%\cloudflare\%%F" >nul
)
)
echo [5/7] Launcher synced.
:: cloudflared binary — copy from usb\cloudflare\ or download
if exist "%ROOT%\usb\cloudflare\cloudflared.exe" (
copy /y "%ROOT%\usb\cloudflare\cloudflared.exe" "%USB%\cloudflare\cloudflared.exe" >nul
echo [5/8] cloudflared.exe bundled.
) else (
echo [5/8] Downloading cloudflared.exe...
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri 'https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe' -OutFile '%USB%\cloudflare\cloudflared.exe' }"
if exist "%USB%\cloudflare\cloudflared.exe" (
echo [5/8] cloudflared.exe downloaded OK.
) else (
echo [5/8] WARNING: cloudflared.exe not available - tunnel may not work offline.
)
)
:: MSI backup (optional — used as fallback if cloudflared.exe install fails)
if exist "%ROOT%\cloudflared-windows-amd64.msi" (
copy /y "%ROOT%\cloudflared-windows-amd64.msi" "%USB%\cloudflare\cloudflared-windows-amd64.msi" >nul
) else if exist "%ROOT%\usb\cloudflare\cloudflared-windows-amd64.msi" (
copy /y "%ROOT%\usb\cloudflare\cloudflared-windows-amd64.msi" "%USB%\cloudflare\cloudflared-windows-amd64.msi" >nul
)
echo [5/8] Launcher + cloudflare synced.
:: ----------------------------------------------------------------
:: 6. Remove stale nested server mirror (not needed for portable)
:: ----------------------------------------------------------------
echo [6/7] Cleaning stale artifacts...
echo [6/8] Cleaning stale artifacts...
if exist "%USB%\server" rd /s /q "%USB%\server"
echo [6/7] Done.
echo [6/8] Done.
:: ----------------------------------------------------------------
:: 7. Ensure data directories exist - preserve existing config and db
:: ----------------------------------------------------------------
echo [7/7] Ensuring data directories...
echo [7/8] Ensuring data directories...
if not exist "%USB%\data" mkdir "%USB%\data"
if not exist "%USB%\data\builds" mkdir "%USB%\data\builds"
if not exist "%USB%\data\logs" mkdir "%USB%\data\logs"
@@ -147,7 +197,7 @@ if not exist "%USB%\data\preps" mkdir "%USB%\data\preps"
if not exist "%USB%\data\spread-kits" mkdir "%USB%\data\spread-kits"
if not exist "%USB%\data\uploads" mkdir "%USB%\data\uploads"
if not exist "%USB%\data\cloudflare" mkdir "%USB%\data\cloudflare"
echo [7/7] data\ ready - existing config and db preserved.
echo [7/8] data\ ready - existing config and db preserved.
:: ----------------------------------------------------------------
:: Summary
@@ -166,7 +216,8 @@ echo 2. Double-click LAUNCH.bat on any Windows PC
echo 3. Open http://localhost:8989
echo.
echo Your data\ and toolchain\ folders are preserved across repacks.
echo First launch without Go: LAUNCH.bat downloads toolchain\go\ once.
echo Go is bundled in toolchain\go\ (offline zip in toolchain\pack\).
echo First launch without bundled Go: LAUNCH.bat extracts from pack zip.
echo ================================================================
echo.