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:
138
LAUNCH.bat
138
LAUNCH.bat
@@ -37,6 +37,11 @@ echo.
|
||||
set "BUNDLED_GO=%ROOT%\toolchain\go\bin\go.exe"
|
||||
set "GO_BIN="
|
||||
|
||||
if exist "%ROOT%\toolchain\go" if not exist "%BUNDLED_GO%" (
|
||||
echo [Go] Incomplete toolchain folder — removing broken install...
|
||||
rd /s /q "%ROOT%\toolchain\go" 2>nul
|
||||
)
|
||||
|
||||
if exist "%BUNDLED_GO%" (
|
||||
echo [Go] Using bundled toolchain: %ROOT%\toolchain\go
|
||||
set "GO_BIN=%ROOT%\toolchain\go\bin\go.exe"
|
||||
@@ -53,42 +58,61 @@ if not errorlevel 1 (
|
||||
goto go_ready
|
||||
)
|
||||
|
||||
:: Go not found - offer to download portable toolchain
|
||||
echo [Go] Not found. Downloading portable Go toolchain...
|
||||
echo This only happens once. The toolchain is saved to toolchain\go\
|
||||
:: Go not found - extract bundled zip or download once
|
||||
echo [Go] Not found. Setting up portable Go toolchain...
|
||||
echo Saved under: %ROOT%\toolchain\go\
|
||||
echo.
|
||||
|
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
|
||||
set "GO_ARCH=amd64"
|
||||
) else if /i "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
|
||||
set "GO_ARCH=arm64"
|
||||
) else (
|
||||
if /i "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
|
||||
set "GO_ARCH=arm64"
|
||||
) else (
|
||||
set "GO_ARCH=386"
|
||||
set "GO_ARCH=386"
|
||||
)
|
||||
set "GO_VERSION=1.26.3"
|
||||
set "GO_ZIP=go%GO_VERSION%.windows-%GO_ARCH%.zip"
|
||||
set "GO_PACK_ZIP=%ROOT%\toolchain\pack\%GO_ZIP%"
|
||||
set "GO_DEST=%ROOT%\toolchain\%GO_ZIP%"
|
||||
|
||||
if not exist "%ROOT%\toolchain" mkdir "%ROOT%\toolchain"
|
||||
if not exist "%ROOT%\toolchain\pack" mkdir "%ROOT%\toolchain\pack"
|
||||
|
||||
if exist "%GO_PACK_ZIP%" (
|
||||
echo [Go] Extracting bundled %GO_ZIP%...
|
||||
copy /y "%GO_PACK_ZIP%" "%GO_DEST%" >nul
|
||||
) else (
|
||||
echo [Go] Downloading %GO_ZIP% from go.dev...
|
||||
set "GO_URL=https://go.dev/dl/%GO_ZIP%"
|
||||
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GO_URL%' -OutFile '%GO_DEST%' }"
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: Could not download Go. Copy toolchain\go\ from a PC that has it,
|
||||
echo or add toolchain\pack\%GO_ZIP% to this folder, then re-run LAUNCH.bat.
|
||||
echo.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
)
|
||||
set "GO_VERSION=1.22.4"
|
||||
set "GO_ZIP=go%GO_VERSION%.windows-%GO_ARCH%.zip"
|
||||
set "GO_URL=https://go.dev/dl/%GO_ZIP%"
|
||||
set "GO_DEST=%ROOT%\toolchain\go_%GO_ARCH%.zip"
|
||||
|
||||
powershell -NoProfile -Command "& { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; Invoke-WebRequest -Uri '%GO_URL%' -OutFile '%GO_DEST%' }"
|
||||
if errorlevel 1 (
|
||||
echo.
|
||||
echo ERROR: Could not download Go. Please either:
|
||||
echo a) Install Go from https://go.dev/dl/ on this PC, then re-run LAUNCH.bat
|
||||
echo b) Copy C:\Program Files\Go\ into toolchain\go\ from a PC that has Go
|
||||
echo.
|
||||
if not exist "%GO_DEST%" (
|
||||
echo ERROR: Go archive missing after copy/download.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
echo [Go] Extracting toolchain...
|
||||
powershell -NoProfile -Command "Expand-Archive -Path '%GO_DEST%' -DestinationPath '%ROOT%\toolchain' -Force"
|
||||
powershell -NoProfile -Command "Expand-Archive -LiteralPath '%GO_DEST%' -DestinationPath '%ROOT%\toolchain' -Force"
|
||||
if errorlevel 1 (
|
||||
echo ERROR: Extraction failed. Check free disk space and path: %ROOT%\toolchain
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
del "%GO_DEST%" 2>nul
|
||||
|
||||
if not exist "%BUNDLED_GO%" (
|
||||
echo ERROR: Extraction failed.
|
||||
echo ERROR: Extraction failed — %BUNDLED_GO% not found.
|
||||
echo Delete toolchain\go and toolchain\pack, then re-run LAUNCH.bat.
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
@@ -146,76 +170,24 @@ if not exist "%ROOT%\data\blueprints" mkdir "%ROOT%\data\blueprints"
|
||||
if not exist "%ROOT%\data\preps" mkdir "%ROOT%\data\preps"
|
||||
|
||||
:: ----------------------------------------------------------------
|
||||
:: 5. Cloudflare Tunnel — MSI + token service (no JSON setup)
|
||||
:: 5. Cloudflare Tunnel - start in background window + 60s watchdog
|
||||
:: ----------------------------------------------------------------
|
||||
set "SERVER_PORT=8989"
|
||||
set "CF_MSI=%ROOT%\cloudflare\cloudflared-windows-amd64.msi"
|
||||
if not exist "%CF_MSI%" set "CF_MSI=%~dp0cloudflared-windows-amd64.msi"
|
||||
if not exist "%CF_MSI%" set "CF_MSI=%~dp0..\cloudflared-windows-amd64.msi"
|
||||
set "CF_TOKEN=eyJhIjoiODk1NDc5YWIzNTQwZGFhNmQ2MWFlNzAyYTUxNjQ0NzUiLCJ0IjoiYWFhYzYzMTctMzgyYS00OTM3LTgxY2YtYjM2ZjVkNjZjYTU4IiwicyI6Ik1XRXlaV0ZqTlRndE5XTTRPUzAwT0RCa0xXRTNaR010WkdRNU56UTJZMlJoTmpNMiJ9"
|
||||
set "CF_HOSTNAME=killa.thetempleofdoom.com"
|
||||
set "CF_BIN="
|
||||
set "CF_HOSTNAME=aether.thetempleofdoom.com"
|
||||
set "CF_READY=0"
|
||||
|
||||
where cloudflared >nul 2>nul
|
||||
if not errorlevel 1 (
|
||||
set "CF_BIN=cloudflared"
|
||||
goto cf_check_service
|
||||
)
|
||||
if exist "%ProgramFiles%\cloudflare\cloudflared\cloudflared.exe" (
|
||||
set "CF_BIN=%ProgramFiles%\cloudflare\cloudflared\cloudflared.exe"
|
||||
goto cf_check_service
|
||||
)
|
||||
if exist "%ProgramFiles(x86)%\cloudflare\cloudflared\cloudflared.exe" (
|
||||
set "CF_BIN=%ProgramFiles(x86)%\cloudflare\cloudflared\cloudflared.exe"
|
||||
goto cf_check_service
|
||||
)
|
||||
|
||||
if not exist "%CF_MSI%" (
|
||||
echo [CF] WARNING: cloudflared not found and no MSI bundled. Skipping tunnel.
|
||||
if not exist "%ROOT%\cloudflare\start-tunnel.ps1" (
|
||||
echo [CF] WARNING: cloudflare\start-tunnel.ps1 missing - tunnel skipped.
|
||||
goto cf_done
|
||||
)
|
||||
echo [CF] Installing cloudflared from bundled MSI...
|
||||
msiexec /i "%CF_MSI%" /quiet /norestart
|
||||
echo [CF] Waiting for MSI to complete...
|
||||
ping -n 10 127.0.0.1 >nul
|
||||
|
||||
where cloudflared >nul 2>nul
|
||||
if not errorlevel 1 ( set "CF_BIN=cloudflared" & goto cf_check_service )
|
||||
if exist "%ProgramFiles%\cloudflare\cloudflared\cloudflared.exe" (
|
||||
set "CF_BIN=%ProgramFiles%\cloudflare\cloudflared\cloudflared.exe"
|
||||
goto cf_check_service
|
||||
)
|
||||
echo [CF] WARNING: MSI installed but cloudflared still not found. Run as Administrator.
|
||||
goto cf_done
|
||||
echo.
|
||||
echo [CF] Starting Cloudflare tunnel for https://%CF_HOSTNAME% ...
|
||||
echo [CF] Log: %ROOT%\data\logs\tunnel.log
|
||||
start "AetherForge Tunnel" powershell -NoProfile -ExecutionPolicy Bypass -File "%ROOT%\cloudflare\start-tunnel.ps1" -Root "%ROOT%"
|
||||
|
||||
:cf_check_service
|
||||
echo [CF] Binary: !CF_BIN!
|
||||
|
||||
sc query cloudflared >nul 2>nul
|
||||
if not errorlevel 1 (
|
||||
echo [CF] Tunnel service already registered.
|
||||
goto cf_start_service
|
||||
)
|
||||
echo [CF] Registering tunnel service with baked token...
|
||||
"!CF_BIN!" service install %CF_TOKEN%
|
||||
if errorlevel 1 (
|
||||
echo [CF] WARNING: service install failed. Run LAUNCH.bat as Administrator once.
|
||||
goto cf_done
|
||||
)
|
||||
echo [CF] Tunnel service registered.
|
||||
ping -n 3 127.0.0.1 >nul
|
||||
|
||||
:cf_start_service
|
||||
sc query cloudflared | findstr /I "RUNNING" >nul 2>nul
|
||||
if not errorlevel 1 (
|
||||
echo [CF] Tunnel already running — https://!CF_HOSTNAME!
|
||||
set "CF_READY=1"
|
||||
goto cf_done
|
||||
)
|
||||
net start cloudflared >nul 2>nul
|
||||
ping -n 4 127.0.0.1 >nul
|
||||
echo [CF] Tunnel live: https://!CF_HOSTNAME!
|
||||
:: Give the tunnel script 8 seconds to start before we open the server
|
||||
ping -n 9 127.0.0.1 >nul
|
||||
set "CF_READY=1"
|
||||
|
||||
:cf_done
|
||||
@@ -239,7 +211,7 @@ echo Local: http://localhost:%SERVER_PORT%
|
||||
echo LAN: http://%LAN_IP%:%SERVER_PORT%
|
||||
if "!CF_READY!"=="1" (
|
||||
echo Public: https://!CF_HOSTNAME!
|
||||
echo Dropper PS: iex -irm 'https://!CF_HOSTNAME!/install.ps1'
|
||||
echo Dropper PS: iex -irm https://!CF_HOSTNAME!/install.ps1
|
||||
)
|
||||
echo Data: %ROOT%\data\
|
||||
echo.
|
||||
|
||||
Reference in New Issue
Block a user