Make service execution runbooks self-auditing
This commit is contained in:
parent
fc993b7be4
commit
22c66917bd
5 changed files with 80 additions and 17 deletions
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
|
|
@ -600,7 +600,7 @@ current_status:
|
|||
cargo and rejects modeling/planning/graph/checkpoint authority. MVP status
|
||||
and coordinator smokes pass with six lanes, and the smoke harness now
|
||||
rebuilds stale coordinator/app-server binaries before using them.
|
||||
- `tools/epiphany_local_run.ps1 -Mode service-execution-runbook` is the repeatable elevated Windows service proof artifact generator. It writes a non-mutating `#Requires -RunAsAdministrator` PowerShell runbook containing the exact `service-execution-readiness`, `service-install-execute`, `service-start-execute`, `service-status`, `service-reconcile`, `service-stop-execute`, final `service-status`, and `service-execution-audit` wrapper calls, so the remaining elevated service proof can run through typed operator and lifecycle receipts instead of improvised `sc.exe` rites.
|
||||
- `tools/epiphany_local_run.ps1 -Mode service-execution-runbook` is the repeatable elevated Windows service proof artifact generator. It writes a non-mutating `#Requires -RunAsAdministrator` PowerShell runbook containing the exact `service-execution-readiness`, `service-install-execute`, `service-start-execute`, `service-status`, `service-reconcile`, `service-stop-execute`, final `service-status`, and `service-execution-audit` wrapper calls, so the remaining elevated service proof can run through typed operator and lifecycle receipts instead of improvised `sc.exe` rites. The artifact now uses `Invoke-EpiphanyRunbookStep` to reset `$LASTEXITCODE`, catch thrown/nonzero failures, continue gathering receipts after a failed step, run final `service-execution-audit` in `finally`, and exit nonzero only after audit if any step failed. Latest proof `local-20260618-160641-685-331af57c` generated and parsed the single-service artifact.
|
||||
- `epiphany-daemon-supervisor windows-service-execution-audit` and `tools/epiphany_local_run.ps1 -Mode service-execution-audit` are the post-run service proof verifier. The audit scans typed `epiphany.cultmesh.daemon_service_lifecycle_receipt.v0` documents for a service, first requires the sealed `windows-service-execution-runbook` receipt as the non-mutating preflight witness, then checks readiness/install/start/status/reconcile/stop receipt statuses, requires private-state sealing, writes its own `windows-service-execution-audit` lifecycle receipt, and returns `complete` only when the runbook plus elevated effect receipts prove the chain. `service-execution-audit-smoke` now writes synthetic sealed lifecycle receipts to prove the audit accepts a complete chain and then rejects a drifted reconcile receipt. Live wrapper proof `local-20260618-133559-466-6644f26f` reported the runbook witness as `written` and OK while six elevated effect receipts remained missing, preserving the elevated authority boundary.
|
||||
- `epiphany-verse-query poke-down-daemons` and `tools/epiphany_local_run.ps1 -Mode swarm-poke-down` are the typed swarm responsibility reflex: inspect local Verse daemon status rows, write daemon poke intent/receipt documents for every non-ready daemon, respect the `daemon.lifecycle_poke` swarm brake, include target display name/body domain/private Verse id/Eve surface metadata from cluster topology in the operator-safe poke summary, and expose no private state. Live local Verse currently reports seven ready daemons, so the wrapper proof correctly produced a no-op operator receipt with `pokedDaemonCount=0`; temp degraded Hands proof produced one topology-aware poke receipt; and `epiphany-verse-query smoke` now source-proves both the ready no-op and degraded single-poke path.
|
||||
- `epiphany-verse-query swarm-status` and `tools/epiphany_local_run.ps1 -Mode swarm-status` provide the compact read-only liveness sight organ over local Verse daemon rows. It uses a narrow CultMesh daemon-liveness loader instead of serializing the full local Verse context, returns seven agent-friendly TUI rows with `READY`/`POKE`, body domain, daemon id, and Eve surface, and exposes no private state. A degraded Hands proof returns status `attention`, `nonReadyCount=1`, and `POKE | Hands | epiphany-daemon-hands | repo:E:/Projects/EpiphanyAgent | eve://epiphany/hands`.
|
||||
|
|
@ -611,7 +611,7 @@ current_status:
|
|||
- `epiphany-verse-query bifrost-ledger` and `tools/epiphany_local_run.ps1 -Mode bifrost-ledger` provide the compact Bifrost ledger sight organ. It reads only the latest Bifrost body-change intent, Bifrost publication receipt, GitHub publication receipt, collaboration feedback, and Imagination consensus receipt through narrow CultMesh loaders, returns five agent-friendly TUI rows when both chains exist, publishes follow-on command hints for swarm overview, tool directory, collaboration feedback, Bifrost publication, and Bifrost ledger readback, and exposes no private state.
|
||||
- `epiphany-verse-query receipt-directory` and `tools/epiphany_local_run.ps1 -Mode receipt-directory` provide the compact latest-witness directory over local Verse. It indexes operator run, daemon poke, daemon tool invocation, Eve connection, Bifrost publication, Imagination consensus, coordinator run, Hands gate, role review, work-loop, cluster service lifecycle, single-service lifecycle, cluster service execution runbook, single-service execution runbook, scheduler, Persona speech, and agent-state SoA witness families from typed local Verse projections; returns agent-friendly `OK`/`ABSENT`/`ATTN` TUI rows with owner, family, status, route, latest id, follow-up command, `presentRowCount`, and `absentRowCount`; preserves `missingRowCount` as compatibility for absent witnesses; flags sealed service lifecycle failure states such as `not-elevated`, `execution-refused-not-elevated`, and `incomplete` as attention without exposing receipt payloads; routes cluster service lifecycle receipts to `cluster-service-execution-audit`, single-service receipts to `service-execution-audit`, the cluster execution-runbook witness to `cluster-service-execution-runbook`, and the single-service execution-runbook witness to `service-execution-runbook`; and exposes no private state or receipt payload previews. The lifecycle projection now reads the typed receipt family, splits `cluster-service-lifecycle` from `service-lifecycle`, selects the latest attention receipt before falling back to latest overall, and exposes `service-id::action` route values such as `epiphany-cluster-daemon-services::cluster-windows-service-execution-audit`, so agents can see the owning lifecycle action without opening raw audit JSON. It also exposes `cluster-service-execution-runbook` plus `service-execution-runbook` as display-only rows, so newer harmless planned/runbook lifecycle receipts cannot hide the active seven-service cluster wound.
|
||||
- `tools/epiphany_local_run.ps1 -Mode service-tick` is the wrapper-owned daemon scheduler pulse rite. It runs `epiphany-daemon-supervisor tick` through the same local Verse store, operator run intent/receipt, agent-state SoA refresh, and swarm-brake preflight as other service lifecycle modes, but leaves restart authority inside durable daemon restart policies. The receipt directory scheduler row now follows up with `tools/epiphany_local_run.ps1 -Mode service-tick` instead of passive service status. Proof seeded one disabled Persona restart policy as inert policy metadata, then the wrapper wrote `daemon-scheduler-receipt-epiphany-daemon-supervisor-0` with `status=tickComplete`, `outcomeCount=1`, `skippedCount=1`, `restartedCount=0`, `refusedCount=0`, and `privateStateExposed=false`; the follow-up receipt-directory proof reported the scheduler row as present with route `*`, follow-up command `service-tick`, and no private-state exposure.
|
||||
- `epiphany-cluster-daemon` is the first real per-cluster daemon heartbeat body. It runs as a narrow Rust binary parameterized by daemon id, publishes typed `epiphany.cultmesh.daemon_status.v0` heartbeats into the shared local Verse, can run once or loop, and exposes no private state. Durable restart policies for Self, Hands, Persona, Imagination, Eyes, Modeling, and Soul now invoke `epiphany-cluster-daemon heartbeat`, not the generic query/debug writer. A degraded proof showed `service-tick` invoking all seven daemon bodies through the supervisor and restoring ready liveness with sealed scheduler/poke receipts; a fresh tick no-ops when all heartbeats are current. `epiphany-daemon-supervisor cluster-service-runbook` and wrapper `-Mode cluster-service-runbook` write a non-mutating service runbook plus `daemon_service_lifecycle` receipt for all seven organ daemon `epiphany-cluster-daemon serve` commands. `epiphany-daemon-supervisor cluster-service-install-plan` and wrapper `-Mode cluster-service-install-plan` write a non-mutating Windows install script plus lifecycle receipt for seven distinct per-organ Windows services. Wrapper `-Mode cluster-service-install-execute` requests execution through the same typed path and, in non-elevated shells, writes `execution-refused-not-elevated` with `executed=false` instead of mutating services. `epiphany-daemon-supervisor cluster-service-audit` and wrapper `-Mode cluster-service-audit` read Windows service-manager state for those seven expected service names, writing an incomplete audit receipt when they are missing. `epiphany-daemon-supervisor cluster-service-start`/`cluster-service-stop` and wrapper `-Mode cluster-service-start-plan`, `cluster-service-stop-plan`, `cluster-service-start-execute`, and `cluster-service-stop-execute` record cluster lifecycle receipts for all seven services: plan modes emit seven `*-planned` rows without mutation, and explicit execute modes refuse as `execution-refused-not-elevated` with seven refused rows when the shell lacks service authority. `cluster-service-execution-runbook` writes an admin-gated wrapper sequence for cluster-native readiness, cluster install, cluster start, cluster audit, cluster stop, and final cluster audit inside a `try` block, then runs `cluster-service-execution-audit` from `finally` so partial elevated failures still seal a post-run audit attempt; the wrapper now calls `epiphany-daemon-supervisor cluster-service-execution-runbook` after artifact generation, so the runbook itself has a typed `daemon_service_lifecycle` receipt with action `cluster-windows-service-execution-runbook`, status `written`, artifact path, final-audit metadata, and `privateStateExposed=false`. Its wrapper JSON now exposes `runbookTryModes`, `finalAuditMode=cluster-service-execution-audit`, and `finalAuditRunsInFinally=true`, and the compact wrapper line prints `finalAuditInFinally=True`. `cluster-service-execution-audit` first requires the sealed `cluster-windows-service-execution-runbook` receipt, then checks the latest cluster-native readiness plus cluster install/start/audit/stop lifecycle receipts by receipt timestamp and reports `complete` only when the runbook and elevated effect receipts are sealed and successful. Wrapper summaries now print compact failed-check anatomy for service and cluster execution audits, so the operator sees which sealed actions are missing or failed without opening raw JSON. Live proof `local-20260618-133611-696-fb1b1f3a` reported the cluster runbook witness as `written` and OK while the non-elevated store remained `incomplete` with zero missing categories and five failed sealed checks for not-elevated readiness, refused install/start/stop, and incomplete service audit; both single-service and cluster smoke paths prove synthetic sealed complete receipts pass and a later bad receipt fails.
|
||||
- `epiphany-cluster-daemon` is the first real per-cluster daemon heartbeat body. It runs as a narrow Rust binary parameterized by daemon id, publishes typed `epiphany.cultmesh.daemon_status.v0` heartbeats into the shared local Verse, can run once or loop, and exposes no private state. Durable restart policies for Self, Hands, Persona, Imagination, Eyes, Modeling, and Soul now invoke `epiphany-cluster-daemon heartbeat`, not the generic query/debug writer. A degraded proof showed `service-tick` invoking all seven daemon bodies through the supervisor and restoring ready liveness with sealed scheduler/poke receipts; a fresh tick no-ops when all heartbeats are current. `epiphany-daemon-supervisor cluster-service-runbook` and wrapper `-Mode cluster-service-runbook` write a non-mutating service runbook plus `daemon_service_lifecycle` receipt for all seven organ daemon `epiphany-cluster-daemon serve` commands. `epiphany-daemon-supervisor cluster-service-install-plan` and wrapper `-Mode cluster-service-install-plan` write a non-mutating Windows install script plus lifecycle receipt for seven distinct per-organ Windows services. Wrapper `-Mode cluster-service-install-execute` requests execution through the same typed path and, in non-elevated shells, writes `execution-refused-not-elevated` with `executed=false` instead of mutating services. `epiphany-daemon-supervisor cluster-service-audit` and wrapper `-Mode cluster-service-audit` read Windows service-manager state for those seven expected service names, writing an incomplete audit receipt when they are missing. `epiphany-daemon-supervisor cluster-service-start`/`cluster-service-stop` and wrapper `-Mode cluster-service-start-plan`, `cluster-service-stop-plan`, `cluster-service-start-execute`, and `cluster-service-stop-execute` record cluster lifecycle receipts for all seven services: plan modes emit seven `*-planned` rows without mutation, and explicit execute modes refuse as `execution-refused-not-elevated` with seven refused rows when the shell lacks service authority. `cluster-service-execution-runbook` writes an admin-gated wrapper sequence for cluster-native readiness, cluster install, cluster start, cluster audit, cluster stop, and final cluster audit; the artifact now uses `Invoke-EpiphanyRunbookStep` to reset `$LASTEXITCODE`, catch thrown/nonzero failures, continue gathering receipts after a failed step, and always runs `cluster-service-execution-audit` from `finally`; the wrapper calls `epiphany-daemon-supervisor cluster-service-execution-runbook` after artifact generation, so the runbook itself has a typed `daemon_service_lifecycle` receipt with action `cluster-windows-service-execution-runbook`, status `written`, artifact path, final-audit metadata, and `privateStateExposed=false`. Its wrapper JSON exposes `runbookTryModes`, `finalAuditMode=cluster-service-execution-audit`, and `finalAuditRunsInFinally=true`, and the compact wrapper line prints `finalAuditInFinally=True`. Latest proof `local-20260618-160627-557-66b23361` generated and parsed the robust cluster artifact; live overview `local-20260618-160719-316-79d0422d` points the elevated operator row at that artifact. `cluster-service-execution-audit` first requires the sealed `cluster-windows-service-execution-runbook` receipt, then checks the latest cluster-native readiness plus cluster install/start/audit/stop lifecycle receipts by receipt timestamp and reports `complete` only when the runbook and elevated effect receipts are sealed and successful. Wrapper summaries print compact failed-check anatomy for service and cluster execution audits, so the operator sees which sealed actions are missing or failed without opening raw JSON.
|
||||
- `epiphany-verse-query restart-policy-directory` and `tools/epiphany_local_run.ps1 -Mode service-policy-directory` provide the compact scheduler coverage sight organ. It reads daemon topology/status plus durable `epiphany.cultmesh.daemon_restart_policy.v0` rows through a narrow CultMesh restart-policy directory loader, reports each daemon as `ENABLED`, `DISABLED`, or `MISSING`, treats disabled and missing policies as recovery attention, returns covered/enabled/disabled/missing/attention counts, and publishes explicit policy-write plus scheduler-tick follow-up commands without creating or mutating policies. Direct and wrapper proof now report seven daemons, seven covered policies, seven enabled policies, zero disabled, zero missing, zero attention, `status=ok`, and `privateStateExposed=false`. This is a real daemon heartbeat body with non-mutating per-organ launch and install artifacts, but not yet executed installed per-organ OS services.
|
||||
- `https://gamecult.org/Blog/purge-the-heretek-from-our-daemonic-swarm` is a public doctrine receipt for the Perfect Machine audit pressure: organs must not borrow each other's crowns, witnesses need owning mouths, surfaces reflect rather than rule, and cross-repo purification needs Bifrost-shaped ledger evidence instead of relying on recoverable transcripts or commit trails alone.
|
||||
- `tools/epiphany_local_run.ps1` now uses collision-resistant local run ids (`local-YYYYMMDD-HHMMSS-fff-<guid8>`) for artifact roots and operator run receipts. Same-second parallel compact wrapper proofs for `collaboration-feedback` and `bifrost-publication` produce separate artifact drawers and both complete, so operator rites no longer collide on second-resolution run ids.
|
||||
|
|
@ -624,4 +624,4 @@ current_status:
|
|||
- Wrapper `swarm-overview` and `swarm-triage` summaries now surface lifecycle receipt `artifactStatus` plus compact service execution failed-check anatomy instead of hiding either inside JSON. Live artifact `local-20260618-155606-611-19701102` shows both service lifecycle attention rows, the operator-elevated runbook row, and `serviceExecutionFailedChecks` naming readiness/install/start/audit/stop status, while private state stays sealed.
|
||||
- Service lifecycle receipt history is now event-only: `load_epiphany_cultmesh_daemon_service_lifecycle_receipts` filters out the `epiphany-local/daemon-service-lifecycle-receipt/latest` mirror, while `load_latest_epiphany_cultmesh_daemon_service_lifecycle_receipt` remains the latest-state reader. Focused unit test `service_lifecycle_receipt_history_excludes_latest_mirror` proves two per-receipt writes return exactly two history records and latest points at the second. Fresh smoke `verse-query-lifecycle-history-filter-smoke` and live overview/triage `local-20260618-145632-497-efac6f0d` / `local-20260618-145632-321-867947af` prove compact swarm sights still expose service lifecycle attention plus the present elevated runbook artifact without daemon pokes or service mutation. Do not use a broad unscoped cargo test filter for this check on Windows; it fans out across bin harnesses and hit a broken pipe during this pass.
|
||||
- `epiphany-verse-query seed-compact` is the compact seed receipt for wrappers and read-only rites. The older `seed` command still prints the full local Verse context for explicit debugging, but compact wrapper modes now avoid full `seed`/final `query` readback after the combined overview proof exposed Windows debug stack overflow from full-context serialization pressure.
|
||||
next_action: Continue the swarm-readiness cuts toward elevated operator install/start execution and completed audit/readiness for the seven installed services. Run generated service execution/install/control runbooks only when the operator grants that authority. The current local Verse proves liveness readiness, scheduler-policy coverage, daemon-body invocation, per-organ launch artifact generation, per-organ install-plan generation, non-elevated install/start/stop execution refusal, read-only installed-service audit, cluster-wide service control planning, service-lifecycle attention surfacing, and cluster execution audit acceptance criteria: `swarm-overview` now reports `status=attention`, `livenessStatus=ready`, `recoveryStatus=attention`, and `recommendedWrapperMode=cluster-service-execution-audit` when the latest sealed cluster service lifecycle receipt is `not-elevated`; `service-tick` can refresh all seven daemon heartbeats through sealed scheduler receipts; `cluster-service-runbook` writes seven explicit `epiphany-cluster-daemon serve` commands with `privateStateExposed=false`; `cluster-service-install-plan` writes seven distinct Windows service install commands with `privateStateExposed=false`; `cluster-service-install-execute`, `cluster-service-start-execute`, and `cluster-service-stop-execute` refuse as `execution-refused-not-elevated` with `executed=false` when the shell lacks service authority; `cluster-service-start-plan` and `cluster-service-stop-plan` emit seven non-mutating planned rows; `cluster-service-audit` currently reports `incomplete` with seven missing services in this non-installed environment; `service-execution-runbook` and `cluster-service-execution-runbook` write the exact elevated wrapper sequences and seal typed runbook receipts; and `service-execution-audit` plus `cluster-service-execution-audit` now require those runbook witnesses before considering elevated-ready/install/start/audit/status/reconcile/stop effect receipts. Preserve the existing typed local Verse surfaces: `service-plan`, `service-launch`, `service-runbook`, `cluster-service-runbook`, `cluster-service-install-plan`, `cluster-service-install-execute`, `cluster-service-audit`, `cluster-service-start-plan`, `cluster-service-stop-plan`, `cluster-service-start-execute`, `cluster-service-stop-execute`, `cluster-service-execution-readiness`, `cluster-service-execution-runbook`, `cluster-service-execution-audit`, `service-execution-runbook`, `service-execution-audit`, `service-tick`, `service-policy-directory`, `agent-state-soa`, `swarm-status`, `swarm-poke-down`, `swarm-triage`, `cluster-topology`, `eve-surfaces`, `eve-connect`, `collaboration-feedback`, `bifrost-publication`, `bifrost-ledger`, `receipt-directory`, `tool-directory`, `tool-invoke`, `swarm-overview`, `seed-compact`, service manager status/reconcile/readiness/control wrappers, compact daemon scheduler/policy receipt rows, daemon liveness-gated tool routing, Bifrost/Imagination chains, coordinator-run receipts, Hands gates, role review mirrors, and sealed agent-state SoA summary. Keep the seven-standing-faculty SoA, stale-turn repair, memory lifecycle, shared local Verse witnesses, and typed CultMesh Persona speech gate intact.
|
||||
next_action: Continue the swarm-readiness cuts toward elevated operator install/start execution and completed audit/readiness for the seven installed services. Run generated service execution/install/control runbooks only when the operator grants that authority. The current local Verse proves liveness readiness, scheduler-policy coverage, daemon-body invocation, per-organ launch artifact generation, per-organ install-plan generation, non-elevated install/start/stop execution refusal, read-only installed-service audit, cluster-wide service control planning, service-lifecycle attention surfacing, and cluster execution audit acceptance criteria: `swarm-overview` now reports `status=attention`, `livenessStatus=ready`, `recoveryStatus=attention`, and `recommendedWrapperMode=cluster-service-execution-audit`; `service-tick` can refresh all seven daemon heartbeats through sealed scheduler receipts; `cluster-service-runbook` writes seven explicit `epiphany-cluster-daemon serve` commands with `privateStateExposed=false`; `cluster-service-install-plan` writes seven distinct Windows service install commands with `privateStateExposed=false`; `cluster-service-install-execute`, `cluster-service-start-execute`, and `cluster-service-stop-execute` refuse as `execution-refused-not-elevated` with `executed=false` when the shell lacks service authority; `cluster-service-start-plan` and `cluster-service-stop-plan` emit seven non-mutating planned rows; `cluster-service-audit` currently reports `incomplete` with seven missing services in this non-installed environment; `service-execution-runbook` and `cluster-service-execution-runbook` write elevated wrapper sequences that continue after per-step failure, run final audits in `finally`, exit nonzero after audit when any step failed, and seal typed runbook receipts; and `service-execution-audit` plus `cluster-service-execution-audit` now require those runbook witnesses before considering elevated-ready/install/start/audit/status/reconcile/stop effect receipts. Preserve the existing typed local Verse surfaces: `service-plan`, `service-launch`, `service-runbook`, `cluster-service-runbook`, `cluster-service-install-plan`, `cluster-service-install-execute`, `cluster-service-audit`, `cluster-service-start-plan`, `cluster-service-stop-plan`, `cluster-service-start-execute`, `cluster-service-stop-execute`, `cluster-service-execution-readiness`, `cluster-service-execution-runbook`, `cluster-service-execution-audit`, `service-execution-runbook`, `service-execution-audit`, `service-tick`, `service-policy-directory`, `agent-state-soa`, `swarm-status`, `swarm-poke-down`, `swarm-triage`, `cluster-topology`, `eve-surfaces`, `eve-connect`, `collaboration-feedback`, `bifrost-publication`, `bifrost-ledger`, `receipt-directory`, `tool-directory`, `tool-invoke`, `swarm-overview`, `seed-compact`, service manager status/reconcile/readiness/control wrappers, compact daemon scheduler/policy receipt rows, daemon liveness-gated tool routing, Bifrost/Imagination chains, coordinator-run receipts, Hands gates, role review mirrors, and sealed agent-state SoA summary. Keep the seven-standing-faculty SoA, stale-turn repair, memory lifecycle, shared local Verse witnesses, and typed CultMesh Persona speech gate intact.
|
||||
|
|
|
|||
|
|
@ -955,22 +955,52 @@ if ($Mode -eq "cluster-service-execution-runbook") {
|
|||
return "& " + (ConvertTo-NativeArgument $wrapperScriptPath) + " " + (($args | ForEach-Object { ConvertTo-NativeArgument $_ }) -join " ")
|
||||
}
|
||||
|
||||
function New-RunbookStepLine {
|
||||
param([string]$RunbookMode)
|
||||
|
||||
return "Invoke-EpiphanyRunbookStep -Name " + (ConvertTo-NativeArgument $RunbookMode) + " -Command " + (ConvertTo-NativeArgument (New-ClusterRunbookCommand $RunbookMode))
|
||||
}
|
||||
|
||||
$runbookLines = @(
|
||||
"#Requires -RunAsAdministrator",
|
||||
"Set-StrictMode -Version Latest",
|
||||
'$ErrorActionPreference = "Stop"',
|
||||
'$epiphanyRunbookFailures = New-Object System.Collections.Generic.List[string]',
|
||||
"",
|
||||
"# Elevated Epiphany cluster daemon service execution rite.",
|
||||
"# Run only under explicit operator authority. Each command writes typed operator and lifecycle receipts into the local Verse store.",
|
||||
"# Individual steps continue after failure so the local Verse gets the fullest possible receipt trail.",
|
||||
"# ServiceId: $clusterServiceId",
|
||||
"# ServiceName prefix: $ServiceName",
|
||||
"",
|
||||
"function Invoke-EpiphanyRunbookStep {",
|
||||
" param(",
|
||||
" [Parameter(Mandatory = `$true)][string]`$Name,",
|
||||
" [Parameter(Mandatory = `$true)][string]`$Command",
|
||||
" )",
|
||||
" Write-Host `"==> `$Name`"",
|
||||
" try {",
|
||||
" `$global:LASTEXITCODE = 0",
|
||||
" Invoke-Expression `$Command",
|
||||
" if (`$null -ne `$global:LASTEXITCODE -and `$global:LASTEXITCODE -ne 0) {",
|
||||
" throw `"Command exited with code `$global:LASTEXITCODE`"",
|
||||
" }",
|
||||
" } catch {",
|
||||
" `$epiphanyRunbookFailures.Add(`"`${Name}: `$(`$_.Exception.Message)`")",
|
||||
" Write-Warning `"Epiphany runbook step failed: `${Name}: `$(`$_.Exception.Message)`"",
|
||||
" }",
|
||||
"}",
|
||||
"",
|
||||
"try {"
|
||||
) + ($clusterExecutionRunbookTryModes | ForEach-Object {
|
||||
" " + (New-ClusterRunbookCommand $_)
|
||||
" " + (New-RunbookStepLine $_)
|
||||
}) + @(
|
||||
"} finally {",
|
||||
" " + (New-ClusterRunbookCommand $clusterExecutionRunbookFinalAuditMode),
|
||||
" " + (New-RunbookStepLine $clusterExecutionRunbookFinalAuditMode),
|
||||
"}",
|
||||
'if ($epiphanyRunbookFailures.Count -gt 0) {',
|
||||
' Write-Error ("Epiphany runbook completed with {0} failed step(s): {1}" -f $epiphanyRunbookFailures.Count, ($epiphanyRunbookFailures -join "; "))',
|
||||
" exit 1",
|
||||
"}"
|
||||
)
|
||||
Set-Content -LiteralPath $executionRunbookPath -Value ($runbookLines -join [Environment]::NewLine) -Encoding UTF8
|
||||
|
|
@ -1084,24 +1114,57 @@ if ($Mode -eq "service-execution-runbook") {
|
|||
return "& " + (ConvertTo-NativeArgument $wrapperScriptPath) + " " + (($args | ForEach-Object { ConvertTo-NativeArgument $_ }) -join " ")
|
||||
}
|
||||
|
||||
function New-ServiceRunbookStepLine {
|
||||
param([string]$RunbookMode)
|
||||
|
||||
return "Invoke-EpiphanyRunbookStep -Name " + (ConvertTo-NativeArgument $RunbookMode) + " -Command " + (ConvertTo-NativeArgument (New-RunbookCommand $RunbookMode))
|
||||
}
|
||||
|
||||
$runbookLines = @(
|
||||
"#Requires -RunAsAdministrator",
|
||||
"Set-StrictMode -Version Latest",
|
||||
'$ErrorActionPreference = "Stop"',
|
||||
'$epiphanyRunbookFailures = New-Object System.Collections.Generic.List[string]',
|
||||
"",
|
||||
"# Elevated Epiphany daemon service execution rite.",
|
||||
"# Run only under explicit operator authority. Each command writes typed operator and lifecycle receipts into the local Verse store.",
|
||||
"# Individual steps continue after failure so the local Verse gets the fullest possible receipt trail.",
|
||||
"# ServiceId: $ServiceId",
|
||||
"# ServiceName: $ServiceName",
|
||||
"",
|
||||
(New-RunbookCommand "service-execution-readiness"),
|
||||
(New-RunbookCommand "service-install-execute"),
|
||||
(New-RunbookCommand "service-start-execute"),
|
||||
(New-RunbookCommand "service-status"),
|
||||
(New-RunbookCommand "service-reconcile"),
|
||||
(New-RunbookCommand "service-stop-execute"),
|
||||
(New-RunbookCommand "service-status"),
|
||||
(New-RunbookCommand "service-execution-audit")
|
||||
"function Invoke-EpiphanyRunbookStep {",
|
||||
" param(",
|
||||
" [Parameter(Mandatory = `$true)][string]`$Name,",
|
||||
" [Parameter(Mandatory = `$true)][string]`$Command",
|
||||
" )",
|
||||
" Write-Host `"==> `$Name`"",
|
||||
" try {",
|
||||
" `$global:LASTEXITCODE = 0",
|
||||
" Invoke-Expression `$Command",
|
||||
" if (`$null -ne `$global:LASTEXITCODE -and `$global:LASTEXITCODE -ne 0) {",
|
||||
" throw `"Command exited with code `$global:LASTEXITCODE`"",
|
||||
" }",
|
||||
" } catch {",
|
||||
" `$epiphanyRunbookFailures.Add(`"`${Name}: `$(`$_.Exception.Message)`")",
|
||||
" Write-Warning `"Epiphany runbook step failed: `${Name}: `$(`$_.Exception.Message)`"",
|
||||
" }",
|
||||
"}",
|
||||
"",
|
||||
"try {",
|
||||
" " + (New-ServiceRunbookStepLine "service-execution-readiness"),
|
||||
" " + (New-ServiceRunbookStepLine "service-install-execute"),
|
||||
" " + (New-ServiceRunbookStepLine "service-start-execute"),
|
||||
" " + (New-ServiceRunbookStepLine "service-status"),
|
||||
" " + (New-ServiceRunbookStepLine "service-reconcile"),
|
||||
" " + (New-ServiceRunbookStepLine "service-stop-execute"),
|
||||
" " + (New-ServiceRunbookStepLine "service-status"),
|
||||
"} finally {",
|
||||
" " + (New-ServiceRunbookStepLine "service-execution-audit"),
|
||||
"}",
|
||||
'if ($epiphanyRunbookFailures.Count -gt 0) {',
|
||||
' Write-Error ("Epiphany runbook completed with {0} failed step(s): {1}" -f $epiphanyRunbookFailures.Count, ($epiphanyRunbookFailures -join "; "))',
|
||||
" exit 1",
|
||||
"}"
|
||||
)
|
||||
Set-Content -LiteralPath $executionRunbookPath -Value ($runbookLines -join [Environment]::NewLine) -Encoding UTF8
|
||||
|
||||
|
|
|
|||
Reference in a new issue