From 544668b6ef91dca2606c5d832c7bab532ebc5bdd Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Tue, 23 Jun 2026 17:04:07 +0100 Subject: [PATCH] Make Idunn witness checks use daemon-owned state --- scripts/health-nightwing-muninn.ps1 | 32 ++++++++++++++++++++++------ scripts/restart-nightwing-muninn.cmd | 2 +- scripts/restart-nightwing-muninn.ps1 | 23 ++++++++++++++++---- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/scripts/health-nightwing-muninn.ps1 b/scripts/health-nightwing-muninn.ps1 index 3dd436a..7e05de9 100644 --- a/scripts/health-nightwing-muninn.ps1 +++ b/scripts/health-nightwing-muninn.ps1 @@ -67,6 +67,21 @@ else echo 'Muninn serve process is not running on Nightwing' >&2 exit 1 fi +process_line="`$(pgrep -af '[m]uninn serve .*--host nightwing' | head -n1 || true)" +if [ -z "`$process_line" ]; then + echo 'Nightwing Muninn serve command line is unavailable' >&2 + exit 1 +fi +for pattern in \ + '--idunn-rudp-health $IdunnRudpHealth' \ + '--idunn-daemon nightwing-muninn' \ + '--idunn-health-contract muninn.cultnet-rudp-remote-telemetry-and-move-hid' +do + if ! printf '%s\n' "`$process_line" | grep -F -- "`$pattern" >/dev/null 2>&1; then + echo "Nightwing Muninn serve command line is missing `$pattern" >&2 + exit 1 + fi +done if [ ! -f '$StorePath' ]; then echo 'Muninn telemetry store is missing on Nightwing' >&2 exit 1 @@ -78,13 +93,18 @@ if [ "`$store_age" -gt '$MaxStoreAgeSeconds' ]; then echo "Muninn telemetry store is stale on Nightwing (`$store_age s old)" >&2 exit 1 fi -identity_output="`$('$MuninnExe' move-identity-status --store '$StorePath' --host nightwing)" -if printf '%s\n' "`$identity_output" | grep -Fq 'No Muninn Move identity records found'; then - echo 'Muninn Move identity roster is empty on Nightwing' >&2 - exit 1 +if printf '%s\n' "`$process_line" | grep -F -- '--move-state' >/dev/null 2>&1 || \ + printf '%s\n' "`$process_line" | grep -F -- '--move-evidence-stream' >/dev/null 2>&1; then + identity_output="`$('$MuninnExe' move-identity-status --store '$StorePath' --host nightwing)" + if printf '%s\n' "`$identity_output" | grep -Fq 'No Muninn Move identity records found'; then + echo 'Muninn Move identity roster is empty on Nightwing' >&2 + exit 1 + fi + identity_count="`$(printf '%s\n' "`$identity_output" | grep -c 'move-identity move=')" + echo "Muninn healthy: nightwing store_age=`${store_age}s move_runtime=explicit move_identities=`${identity_count}" +else + echo "Muninn healthy: nightwing store_age=`${store_age}s move_runtime=disabled" fi -identity_count="`$(printf '%s\n' "`$identity_output" | grep -c 'move-identity move=')" -echo "Muninn healthy: nightwing store_age=`${store_age}s move_identities=`${identity_count}" "@ Invoke-NightwingUploadedShell -SshTarget $SshTarget -RemoteScriptContent $remoteScript -TempPrefix "odin-nightwing-muninn-health" diff --git a/scripts/restart-nightwing-muninn.cmd b/scripts/restart-nightwing-muninn.cmd index 1b6a169..761647f 100644 --- a/scripts/restart-nightwing-muninn.cmd +++ b/scripts/restart-nightwing-muninn.cmd @@ -1,2 +1,2 @@ @echo off -powershell.exe -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\restart-nightwing-muninn.ps1 +powershell.exe -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\restart-nightwing-muninn.ps1 -DiscoverMoveState -ClaimUsbMoves diff --git a/scripts/restart-nightwing-muninn.ps1 b/scripts/restart-nightwing-muninn.ps1 index c95d1dc..9437928 100644 --- a/scripts/restart-nightwing-muninn.ps1 +++ b/scripts/restart-nightwing-muninn.ps1 @@ -4,6 +4,8 @@ param( [string] $StorePath = "/home/metacrat/.local/state/gamecult/muninn/muninn.telemetry.cc", [string] $LogRoot = "/home/metacrat/.local/state/gamecult/muninn", [string[]] $MoveState = @(), + [switch] $DiscoverMoveState, + [switch] $ClaimUsbMoves, [string] $MoveEvidenceStream = "muninn:nightwing:move-evidence", [int] $IntervalSeconds = 15, [string] $IdunnRudpHealth = "10.77.0.2:17870", @@ -18,16 +20,30 @@ function Quote-ShSingle([string] $Value) { } $moveStateSpecs = @($MoveState | Where-Object { -not [string]::IsNullOrWhiteSpace($_) }) -if ($moveStateSpecs.Count -eq 0) { +if ($ClaimUsbMoves.IsPresent -and -not $DiscoverMoveState.IsPresent -and $moveStateSpecs.Count -eq 0) { + throw "-ClaimUsbMoves requires -DiscoverMoveState or at least one explicit -MoveState value." +} +if ($DiscoverMoveState.IsPresent) { $claimScript = Join-Path $PSScriptRoot "claim-nightwing-usb-moves.ps1" - & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $claimScript -SshTarget $SshTarget + if ($ClaimUsbMoves.IsPresent) { + & powershell.exe -NoProfile -ExecutionPolicy Bypass -File $claimScript -SshTarget $SshTarget + } $sourceScript = Join-Path $PSScriptRoot "get-nightwing-move-state-sources.ps1" $moveStateSpecs = @(& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $sourceScript -SshTarget $SshTarget) + if ($moveStateSpecs.Count -eq 0) { + throw "Nightwing Move runtime was explicitly requested, but no live Move state sources were discovered." + } } $moveStateSetLines = ($moveStateSpecs | ForEach-Object { "set -- ""`$@"" --move-state $(Quote-ShSingle $_)" }) -join "`n" +$moveRuntimeSetLines = @() +if ($moveStateSpecs.Count -gt 0) { + $moveRuntimeSetLines += $moveStateSetLines + $moveRuntimeSetLines += "set -- ""`$@"" --move-evidence-stream $(Quote-ShSingle $MoveEvidenceStream)" +} +$moveRuntimeSetBlock = ($moveRuntimeSetLines -join "`n") $remoteScript = @" set -eu @@ -47,9 +63,8 @@ set -- serve \ --store '$StorePath' \ --log-root '$LogRoot' \ --host nightwing -$moveStateSetLines +$moveRuntimeSetBlock set -- "`$@" \ - --move-evidence-stream '$MoveEvidenceStream' \ --interval-seconds '$IntervalSeconds' \ --idunn-rudp-health '$IdunnRudpHealth' \ --idunn-daemon '$IdunnDaemon' \