igneum/relay/playbooks/start-app.ps1

35 lines
2.2 KiB
PowerShell

# The body of a start-app task (tools/relay.mjs start-app <machine>; MF-11, 7 October 2026). An agent from v3 on never
# runs this text: its own Start-App does the same thing. An agent from before the kind runs it as a `run` task, which is
# why it is here. Starts the installed Igneum Miner as this user and reads back that an engine answers api/state.
# It never sends quit, pause or resume to the installed app (the standing rule of 5 October 2026).
$ErrorActionPreference = 'Continue'
$dir = ''
foreach ($d in @((Join-Path $env:LOCALAPPDATA 'Programs\Igneum Miner'), (Join-Path $env:ProgramFiles 'Igneum Miner'))) {
if (Test-Path (Join-Path $d 'igneum-app.exe')) { $dir = $d; break }
}
if (-not $dir) { Write-Host 'start-app: igneum-app.exe not found'; exit 2 }
$urlFile = Join-Path $env:LOCALAPPDATA 'igneum\app\app.url'
function App-Version {
if (-not (Test-Path $urlFile)) { return '' }
try { $u = (Get-Content $urlFile -Raw).Trim(); $st = Invoke-RestMethod -Uri ($u + 'api/state') -TimeoutSec 5 -UseBasicParsing; return [string]$st.version } catch { return '' }
}
$v = App-Version
if ($v) { Write-Host ('start-app: an engine already answers (app ' + $v + '); nothing started'); exit 0 }
$exe = Join-Path $dir 'igneum-app.exe'
$admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if ($admin) {
& schtasks.exe /Create /F /TN 'IgneumStartApp' /SC ONCE /ST 00:00 /RL LIMITED /TR ('"' + $exe + '" --launch') 2>&1 | Out-Null
& schtasks.exe /Run /TN 'IgneumStartApp' 2>&1 | Out-Null
Start-Sleep -Seconds 3
& schtasks.exe /Delete /F /TN 'IgneumStartApp' 2>&1 | Out-Null
} else {
# console: igneum-app.exe is a windows-subsystem program (no console); the window host it opens is its own
Start-Process -FilePath $exe -ArgumentList '--launch' -WorkingDirectory $dir | Out-Null
}
$t0 = Get-Date
$deadline = (Get-Date).AddSeconds(90)
while ((Get-Date) -lt $deadline) { $v = App-Version; if ($v) { break }; Start-Sleep -Seconds 3 }
$s = [int]((Get-Date) - $t0).TotalSeconds
if ($v) { Write-Host ('start-app: app ' + $v + ' answered api/state after ' + $s + ' s'); exit 0 }
Write-Host 'start-app: no engine answered api/state inside 90 s'
exit 3