Fix Odin health actuation and share discovery pass

This commit is contained in:
Meta Vens 2026-06-23 18:36:59 +01:00
commit e1eb4b45a7
7 changed files with 415 additions and 251 deletions

View file

@ -1,2 +1,2 @@
@echo off
curl.exe -fsS http://127.0.0.1:8797/health >NUL
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\health-odin.ps1

80
scripts/health-odin.ps1 Normal file
View file

@ -0,0 +1,80 @@
param(
[int] $Port = 8797,
[string] $StateDir = "E:\Projects\Odin\scratch\odin",
[int] $MaxSilenceSeconds = 120,
[string] $CultNetRudpBind = "0.0.0.0:17871"
)
$ErrorActionPreference = "Stop"
$pidPath = Join-Path $StateDir "odin.pid"
$outLog = Join-Path $StateDir "odin.out.log"
$errLog = Join-Path $StateDir "odin.err.log"
if (-not (Test-Path -LiteralPath $pidPath)) {
throw "Odin PID file is missing at $pidPath"
}
$pidText = (Get-Content -LiteralPath $pidPath -Raw).Trim()
if ($pidText -notmatch '^\d+$') {
throw "Odin PID file is invalid at ${pidPath}: '$pidText'"
}
$process = Get-CimInstance Win32_Process -Filter "ProcessId = $pidText" -ErrorAction SilentlyContinue
if ($null -eq $process) {
throw "Odin process $pidText is not running"
}
foreach ($pattern in @(
'node.exe',
'src\odin-coordinator.cjs',
"--port $Port",
"--stateDir $StateDir",
"--cultnet-rudp-bind $CultNetRudpBind",
'--idunn-daemon odin',
'--idunn-health-contract odin.cultnet-rudp-provider-health'
)) {
if ($process.CommandLine -notlike "*$pattern*") {
throw "Odin process command line is missing expected segment ${pattern}: $($process.CommandLine)"
}
}
foreach ($logPath in @($outLog, $errLog)) {
if (-not (Test-Path -LiteralPath $logPath)) {
throw "Odin log is missing at $logPath"
}
}
$newestLogWriteUtc = @($outLog, $errLog) |
ForEach-Object { (Get-Item -LiteralPath $_).LastWriteTimeUtc } |
Sort-Object -Descending |
Select-Object -First 1
$logAgeSeconds = ([DateTime]::UtcNow - $newestLogWriteUtc).TotalSeconds
$healthUri = "http://127.0.0.1:$Port/health"
try {
$health = Invoke-RestMethod -Uri $healthUri -TimeoutSec 10
} catch {
throw "Odin health endpoint is unavailable at ${healthUri}: $($_.Exception.Message)"
}
if (-not $health.ok) {
throw "Odin health endpoint reports ok=false"
}
$tcpListener = Get-NetTCPConnection -State Listen -LocalPort $Port -ErrorAction SilentlyContinue |
Where-Object { $_.OwningProcess -eq [int]$pidText } |
Select-Object -First 1
if ($null -eq $tcpListener) {
throw "Odin is not listening on TCP port $Port as process $pidText"
}
$rudpPort = [int](($CultNetRudpBind -split ':')[-1])
$udpListener = Get-NetUDPEndpoint -LocalPort $rudpPort -ErrorAction SilentlyContinue |
Where-Object { $_.OwningProcess -eq [int]$pidText } |
Select-Object -First 1
if ($null -eq $udpListener) {
throw "Odin is not listening on UDP port $rudpPort as process $pidText"
}
Write-Host "Odin healthy: pid=$pidText tcp=$Port udp=$rudpPort log_age=$([math]::Round($logAgeSeconds))s"

View file

@ -1,2 +1,2 @@
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\start-odin.ps1
"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\restart-odin.ps1

35
scripts/restart-odin.ps1 Normal file
View file

@ -0,0 +1,35 @@
param(
[int] $Port = 8797,
[string] $StateDir = "E:\Projects\Odin\scratch\odin",
[string] $CultNetRudpBind = "0.0.0.0:17871",
[string] $IdunnRudpHealth = "127.0.0.1:17870",
[string] $IdunnDaemon = "odin",
[string] $IdunnHealthContract = "odin.cultnet-rudp-provider-health"
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$stopScript = Join-Path $PSScriptRoot "stop-odin.ps1"
$startScript = Join-Path $PSScriptRoot "start-odin.ps1"
$healthScript = Join-Path $PSScriptRoot "health-odin.ps1"
$powerShellExe = Join-Path $env:WINDIR "System32\WindowsPowerShell\v1.0\powershell.exe"
if (-not (Test-Path -LiteralPath $powerShellExe)) {
throw "PowerShell executable is missing at $powerShellExe"
}
& $powerShellExe -NoProfile -ExecutionPolicy Bypass -File $stopScript -StateDir $StateDir
& $powerShellExe -NoProfile -ExecutionPolicy Bypass -File $startScript `
-Port $Port `
-StateDir $StateDir `
-CultNetRudpBind $CultNetRudpBind `
-IdunnRudpHealth $IdunnRudpHealth `
-IdunnDaemon $IdunnDaemon `
-IdunnHealthContract $IdunnHealthContract
& $powerShellExe -NoProfile -ExecutionPolicy Bypass -File $healthScript `
-Port $Port `
-StateDir $StateDir `
-CultNetRudpBind $CultNetRudpBind