Odin/scripts/start-odin.ps1
Meta Vens 515a864ef0 Rebase Idunn actuator scripts off the projects root
The previous commit fixed the target catalog and the operator alarm, but the
actuators the catalog invokes carried the same E: paths. Idunn would have
resolved every target and then failed on the first restart or deploy it ran,
for exactly the reason the alarm failed.

Rebased 41 references across 27 scripts:

- .cmd bodies invoke their sibling .ps1 through %~dp0 instead of an absolute
  drive path, and restart-weksa.cmd reaches its sibling repo the same way.
- .ps1 parameter defaults and assignments derive from $PSScriptRoot: one level
  up for paths inside Odin, two for sibling repos under the projects root.

Left deliberately alone: $RemoteViliRoot and $StateRoot in restart-vili.ps1.
Both are consumed inside the EncodedCommand block that restart-vili ssh's to
raven, so they describe raven's filesystem, not starfire's. Whether raven also
moved off E: is an operator question, not something to infer from here.

Verified: all 46 scripts under scripts/ parse clean, and the derivation
resolves to F:\Projects\Odin and F:\Projects on this host.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 01:05:40 +02:00

68 lines
2.5 KiB
PowerShell

param(
[string] $StateDir = (Join-Path (Split-Path -Parent $PSScriptRoot) "scratch\odin"),
[string] $CultNetRudpBind = "0.0.0.0:17871",
[string] $IdunnRudpHealth = $(if ($env:ODIN_IDUNN_RUDP_HEALTH) { $env:ODIN_IDUNN_RUDP_HEALTH } else { $env:IDUNN_RUDP_HEALTH }),
[string] $IdunnDaemon = "odin",
[string] $IdunnHealthContract = "odin.cultnet-rudp-provider-health",
[switch] $Foreground
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $PSScriptRoot
$scriptPath = Join-Path $repoRoot "src\odin-coordinator.cjs"
$pidPath = Join-Path $StateDir "odin.pid"
$outLog = Join-Path $StateDir "odin.out.log"
$errLog = Join-Path $StateDir "odin.err.log"
$nodeExe = (Get-Command node.exe -ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty Source)
if (-not $nodeExe) {
$nodeExe = "C:\Program Files\nodejs\node.exe"
}
if (-not (Test-Path -LiteralPath $nodeExe)) {
throw "Node.js executable is missing; checked PATH and $nodeExe"
}
if ([string]::IsNullOrWhiteSpace($IdunnRudpHealth)) {
throw "Odin Idunn health publication requires -IdunnRudpHealth, ODIN_IDUNN_RUDP_HEALTH, or IDUNN_RUDP_HEALTH; no localhost default is assumed."
}
New-Item -ItemType Directory -Force -Path $StateDir | Out-Null
if (Test-Path $pidPath) {
$oldPid = (Get-Content -Raw $pidPath).Trim()
if ($oldPid -match "^\d+$") {
$old = Get-Process -Id ([int] $oldPid) -ErrorAction SilentlyContinue
if ($old) {
throw "Odin already appears to be running as PID $oldPid."
}
}
Remove-Item -LiteralPath $pidPath -Force
}
$env:NODE_PATH = (Join-Path (Split-Path -Parent (Split-Path -Parent $PSScriptRoot)) "CultLib\packages")
$args = @(
$scriptPath,
"--stateDir", $StateDir,
"--cultnet-rudp-bind", $CultNetRudpBind,
"--idunn-rudp-health", $IdunnRudpHealth,
"--idunn-daemon", $IdunnDaemon,
"--idunn-health-contract", $IdunnHealthContract
)
if ($Foreground) {
& $nodeExe @args
exit $LASTEXITCODE
}
$proc = Start-Process -FilePath $nodeExe -ArgumentList $args -WorkingDirectory $repoRoot -WindowStyle Hidden -PassThru -RedirectStandardOutput $outLog -RedirectStandardError $errLog
$proc.Id | Set-Content -Encoding ASCII -LiteralPath $pidPath
Start-Sleep -Seconds 1
if ($proc.HasExited) {
$detail = ""
if (Test-Path $outLog) { $detail += Get-Content -Raw $outLog }
if (Test-Path $errLog) { $detail += Get-Content -Raw $errLog }
throw "Odin exited immediately with code $($proc.ExitCode).`n$detail"
}
Write-Host "Odin started as PID $($proc.Id)."
Write-Host "CultMesh/RUDP document catalog: $CultNetRudpBind"