Install local Idunn keepalive startup

This commit is contained in:
Meta Vens 2026-06-06 13:30:46 +01:00
commit 311de22fc3
7 changed files with 182 additions and 0 deletions

View file

@ -0,0 +1,26 @@
param(
[string] $TaskName = "Idunn Local Keepalive",
[int] $IntervalSeconds = 30
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$scriptPath = Join-Path $repoRoot "scripts\start-idunn-local.ps1"
$powershell = Join-Path $env:SystemRoot "System32\WindowsPowerShell\v1.0\powershell.exe"
$taskCommand = "`"$powershell`" -NoProfile -NonInteractive -ExecutionPolicy Bypass -File `"$scriptPath`" -IntervalSeconds $IntervalSeconds"
& schtasks.exe /Create /TN $TaskName /SC ONLOGON /TR $taskCommand /F | Out-Null
if ($LASTEXITCODE -ne 0) {
$startupDir = [Environment]::GetFolderPath("Startup")
$startupScript = Join-Path $startupDir "$TaskName.cmd"
$cmd = "@echo off`r`ncd /d `"$repoRoot`"`r`n$taskCommand`r`n"
[System.IO.File]::WriteAllText($startupScript, $cmd, [System.Text.UTF8Encoding]::new($false))
Write-Host "Scheduled task install was denied; installed Startup folder launcher instead:"
Write-Host " $startupScript"
} else {
Write-Host "Installed scheduled task: $TaskName"
}
Write-Host "Starting Idunn watchdogs now..."
& $scriptPath -IntervalSeconds $IntervalSeconds

View file

@ -0,0 +1,2 @@
@echo off
ssh.exe -o BatchMode=yes -o ConnectTimeout=5 nwroot systemctl restart nightwing-eve-browser-reference.service

View file

@ -0,0 +1,2 @@
@echo off
ssh.exe -o BatchMode=yes -o ConnectTimeout=5 nwroot systemctl restart nightwing-eve-dashboard.service

View file

@ -0,0 +1,2 @@
@echo off
ssh.exe -o BatchMode=yes -o ConnectTimeout=5 nwroot systemctl restart gjallar.service

2
scripts/restart-odin.cmd Normal file
View file

@ -0,0 +1,2 @@
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\start-odin.ps1

View file

@ -0,0 +1,138 @@
param(
[int] $IntervalSeconds = 30,
[string] $StateDir = "E:\Projects\Odin\scratch\idunn"
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$idunnExe = Join-Path $repoRoot "target\debug\idunn.exe"
$logDir = Join-Path $StateDir "logs"
$pidDir = Join-Path $StateDir "pids"
New-Item -ItemType Directory -Force -Path $StateDir, $logDir, $pidDir | Out-Null
if (-not (Test-Path -LiteralPath $idunnExe)) {
Push-Location -LiteralPath $repoRoot
try {
& cargo build -p idunn-daemon
if ($LASTEXITCODE -ne 0) {
throw "cargo build -p idunn-daemon failed with exit code $LASTEXITCODE"
}
} finally {
Pop-Location
}
}
$watchdogs = @(
[pscustomobject]@{
Id = "odin"
Name = "Odin all-seer"
Verse = "starfire.local"
Health = "curl.exe -fsS http://127.0.0.1:8797/health >NUL"
Restart = "$repoRoot\scripts\restart-odin.cmd"
},
[pscustomobject]@{
Id = "mimir-eve-dashboard"
Name = "Mimir Eve dashboard"
Verse = "starfire.local"
Health = "curl.exe -fsS http://127.0.0.1:8795/health >NUL"
Restart = $null
},
[pscustomobject]@{
Id = "nightwing-gjallar"
Name = "Nightwing Gjallar framebuffer compositor"
Verse = "nightwing.local"
Health = "ssh -o BatchMode=yes -o ConnectTimeout=5 nightwing `"systemctl is-active --quiet gjallar.service`""
Restart = "$repoRoot\scripts\restart-nightwing-gjallar.cmd"
},
[pscustomobject]@{
Id = "nightwing-eve-dashboard"
Name = "Nightwing Eve dashboard broker"
Verse = "nightwing.local"
Health = "ssh -o BatchMode=yes -o ConnectTimeout=5 nightwing `"systemctl is-active --quiet nightwing-eve-dashboard.service`""
Restart = "$repoRoot\scripts\restart-nightwing-eve-dashboard.cmd"
},
[pscustomobject]@{
Id = "nightwing-eve-browser-reference"
Name = "Nightwing Eve browser reference"
Verse = "nightwing.local"
Health = "ssh -o BatchMode=yes -o ConnectTimeout=5 nightwing `"systemctl is-active --quiet nightwing-eve-browser-reference.service`""
Restart = "$repoRoot\scripts\restart-nightwing-eve-browser-reference.cmd"
}
)
function Test-LivePid {
param([string] $Path)
if (-not (Test-Path -LiteralPath $Path)) {
return $false
}
$pidText = (Get-Content -LiteralPath $Path -Raw).Trim()
if ($pidText -notmatch "^\d+$") {
Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue
return $false
}
$process = Get-Process -Id ([int] $pidText) -ErrorAction SilentlyContinue
if ($null -eq $process) {
Remove-Item -LiteralPath $Path -Force -ErrorAction SilentlyContinue
return $false
}
return $true
}
function Start-Watchdog {
param($Watchdog)
$pidPath = Join-Path $pidDir "$($Watchdog.Id).pid"
if (Test-LivePid -Path $pidPath) {
Write-Host "Idunn watchdog already running for $($Watchdog.Id)."
return
}
$storePath = Join-Path $StateDir "$($Watchdog.Id).keepalive.cc"
$startInfo = [System.Diagnostics.ProcessStartInfo]::new()
$startInfo.FileName = $idunnExe
$startInfo.WorkingDirectory = $repoRoot
$startInfo.UseShellExecute = $false
$startInfo.CreateNoWindow = $true
$startInfo.RedirectStandardOutput = $false
$startInfo.RedirectStandardError = $false
$arguments = @(
"--daemon", $Watchdog.Id,
"--name", $Watchdog.Name,
"--verse", $Watchdog.Verse,
"--store", $storePath,
"--health-command", $Watchdog.Health,
"--interval-seconds", "$IntervalSeconds"
)
if (-not [string]::IsNullOrWhiteSpace($Watchdog.Restart)) {
$arguments += @("--restart-command", $Watchdog.Restart, "--execute")
}
$startInfo.Arguments = Join-WindowsArguments -Arguments $arguments
$process = [System.Diagnostics.Process]::new()
$process.StartInfo = $startInfo
[void] $process.Start()
$process.Id | Set-Content -Encoding ASCII -LiteralPath $pidPath
Write-Host "Started Idunn watchdog $($Watchdog.Id) as PID $($process.Id)."
Write-Host " store: $storePath"
}
function ConvertTo-WindowsArgument {
param([string] $Value)
if ($Value -notmatch '[\s"]') {
return $Value
}
return '"' + ($Value -replace '(\\*)"', '$1$1\"' -replace '(\\+)$', '$1$1') + '"'
}
function Join-WindowsArguments {
param([object[]] $Arguments)
return (($Arguments | ForEach-Object { ConvertTo-WindowsArgument -Value ([string] $_) }) -join " ")
}
foreach ($watchdog in $watchdogs) {
Start-Watchdog -Watchdog $watchdog
}

View file

@ -67,6 +67,16 @@ npm run idunn:build
npm run idunn:start -- --daemon demo --health-command "exit 0"
```
Install the local Starfire boot watchdogs:
```powershell
.\scripts\install-idunn-startup.ps1
```
That task starts Idunn loops for Odin and the Nightwing display services at
user logon. The current Mimir dashboard is observed but not restarted until its
restart authority is named.
To record a failed health check and request a restart without actuating:
```powershell