189 lines
7.5 KiB
PowerShell
189 lines
7.5 KiB
PowerShell
param(
|
|
[string]$AgentRoot = "C:\Wooo\Agent99"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$launcher = Join-Path $AgentRoot "agent99-run.ps1"
|
|
if (-not (Test-Path $launcher)) {
|
|
throw "Agent99 launcher not found: $launcher"
|
|
}
|
|
|
|
$ps = Join-Path $env:SystemRoot "System32\WindowsPowerShell\v1.0\powershell.exe"
|
|
$principalUser = if ($env:COMPUTERNAME) { "$env:COMPUTERNAME\$env:USERNAME" } else { $env:USERNAME }
|
|
$principal = New-ScheduledTaskPrincipal -UserId $principalUser -LogonType S4U -RunLevel Highest
|
|
$settings = New-ScheduledTaskSettingsSet `
|
|
-AllowStartIfOnBatteries `
|
|
-DontStopIfGoingOnBatteries `
|
|
-StartWhenAvailable `
|
|
-MultipleInstances IgnoreNew `
|
|
-ExecutionTimeLimit (New-TimeSpan -Minutes 10)
|
|
$recoverySettings = New-ScheduledTaskSettingsSet `
|
|
-AllowStartIfOnBatteries `
|
|
-DontStopIfGoingOnBatteries `
|
|
-StartWhenAvailable `
|
|
-MultipleInstances IgnoreNew `
|
|
-ExecutionTimeLimit (New-TimeSpan -Minutes 20)
|
|
$serviceSettings = New-ScheduledTaskSettingsSet `
|
|
-AllowStartIfOnBatteries `
|
|
-DontStopIfGoingOnBatteries `
|
|
-StartWhenAvailable `
|
|
-MultipleInstances IgnoreNew `
|
|
-ExecutionTimeLimit ([TimeSpan]::Zero)
|
|
|
|
$recoverArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$launcher`" -Mode Recover -ControlledApply"
|
|
$recoverAction = New-ScheduledTaskAction -Execute $ps -Argument $recoverArgs
|
|
$startupTrigger = New-ScheduledTaskTrigger -AtStartup
|
|
$logonTrigger = New-ScheduledTaskTrigger -AtLogOn -User $principalUser
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-Startup-Recovery" `
|
|
-Action $recoverAction `
|
|
-Trigger @($startupTrigger, $logonTrigger) `
|
|
-Principal $principal `
|
|
-Settings $recoverySettings `
|
|
-Description "Agent99 startup recovery for VMs, Harbor, K3s, and public routes." `
|
|
-Force | Out-Null
|
|
|
|
$heartbeatArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$launcher`" -Mode Status"
|
|
$heartbeatAction = New-ScheduledTaskAction -Execute $ps -Argument $heartbeatArgs
|
|
$heartbeatTrigger = New-ScheduledTaskTrigger `
|
|
-Once `
|
|
-At (Get-Date).AddMinutes(1) `
|
|
-RepetitionInterval (New-TimeSpan -Minutes 5) `
|
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-Heartbeat" `
|
|
-Action $heartbeatAction `
|
|
-Trigger $heartbeatTrigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Agent99 observe-mode heartbeat for host, Harbor, K3s, and public route evidence." `
|
|
-Force | Out-Null
|
|
|
|
$perfArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$launcher`" -Mode Perf -ControlledApply"
|
|
$perfAction = New-ScheduledTaskAction -Execute $ps -Argument $perfArgs
|
|
$perfTrigger = New-ScheduledTaskTrigger `
|
|
-Once `
|
|
-At (Get-Date).AddMinutes(1) `
|
|
-RepetitionInterval (New-TimeSpan -Minutes 1) `
|
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-Performance-Guard" `
|
|
-Action $perfAction `
|
|
-Trigger $perfTrigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Agent99 minute-level performance guard with Telegram audit and allowlisted controlled load shedding." `
|
|
-Force | Out-Null
|
|
|
|
$controlArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$launcher`" -Mode ControlTick"
|
|
$controlAction = New-ScheduledTaskAction -Execute $ps -Argument $controlArgs
|
|
$controlTrigger = New-ScheduledTaskTrigger `
|
|
-Once `
|
|
-At (Get-Date).AddMinutes(1) `
|
|
-RepetitionInterval (New-TimeSpan -Minutes 1) `
|
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-Control-Loop" `
|
|
-Action $controlAction `
|
|
-Trigger $controlTrigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Agent99 visible control center, desktop shortcuts, and allowlisted operator command queue processor." `
|
|
-Force | Out-Null
|
|
|
|
$telegramInboxScript = Join-Path $AgentRoot "bin\agent99-telegram-inbox.ps1"
|
|
$telegramInboxArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$telegramInboxScript`" -RunNow"
|
|
$telegramInboxAction = New-ScheduledTaskAction -Execute $ps -Argument $telegramInboxArgs
|
|
$telegramInboxTrigger = New-ScheduledTaskTrigger `
|
|
-Once `
|
|
-At (Get-Date).AddMinutes(1) `
|
|
-RepetitionInterval (New-TimeSpan -Minutes 1) `
|
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-Telegram-Inbox" `
|
|
-Action $telegramInboxAction `
|
|
-Trigger $telegramInboxTrigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Agent99 Telegram command inbox for allowlisted /agent99 operator instructions." `
|
|
-Force | Out-Null
|
|
|
|
$sreAlertInboxScript = Join-Path $AgentRoot "bin\agent99-sre-alert-inbox.ps1"
|
|
$sreAlertInboxArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$sreAlertInboxScript`" -RunNow"
|
|
$sreAlertInboxAction = New-ScheduledTaskAction -Execute $ps -Argument $sreAlertInboxArgs
|
|
$sreAlertInboxTrigger = New-ScheduledTaskTrigger `
|
|
-Once `
|
|
-At (Get-Date).AddMinutes(1) `
|
|
-RepetitionInterval (New-TimeSpan -Minutes 1) `
|
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-SRE-Alert-Inbox" `
|
|
-Action $sreAlertInboxAction `
|
|
-Trigger $sreAlertInboxTrigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Agent99 SRE war-room alert inbox that converts actionable alerts into allowlisted remediation queue entries." `
|
|
-Force | Out-Null
|
|
|
|
$sreAlertRelayScript = Join-Path $AgentRoot "bin\agent99-sre-alert-relay.ps1"
|
|
if (Test-Path $sreAlertRelayScript) {
|
|
$sreAlertRelayArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$sreAlertRelayScript`""
|
|
$sreAlertRelayAction = New-ScheduledTaskAction -Execute $ps -Argument $sreAlertRelayArgs
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-SRE-Alert-Relay" `
|
|
-Action $sreAlertRelayAction `
|
|
-Trigger @($startupTrigger, $logonTrigger) `
|
|
-Principal $principal `
|
|
-Settings $serviceSettings `
|
|
-Description "Agent99 HTTP relay for AWOOI Alertmanager alerts into the SRE alert inbox." `
|
|
-Force | Out-Null
|
|
}
|
|
|
|
$selfCheckArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$launcher`" -Mode SelfCheck"
|
|
$selfCheckAction = New-ScheduledTaskAction -Execute $ps -Argument $selfCheckArgs
|
|
$selfCheckTrigger = New-ScheduledTaskTrigger `
|
|
-Once `
|
|
-At (Get-Date).AddMinutes(2) `
|
|
-RepetitionInterval (New-TimeSpan -Minutes 5) `
|
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-Self-Health" `
|
|
-Action $selfCheckAction `
|
|
-Trigger $selfCheckTrigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Agent99 self-health guard for scheduled tasks, evidence freshness, host perf readback, and Telegram delivery." `
|
|
-Force | Out-Null
|
|
|
|
$backupArgs = "-NoProfile -ExecutionPolicy Bypass -File `"$launcher`" -Mode BackupCheck"
|
|
$backupAction = New-ScheduledTaskAction -Execute $ps -Argument $backupArgs
|
|
$backupTrigger = New-ScheduledTaskTrigger `
|
|
-Once `
|
|
-At (Get-Date).AddMinutes(3) `
|
|
-RepetitionInterval (New-TimeSpan -Minutes 15) `
|
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
|
Register-ScheduledTask `
|
|
-TaskName "Wooo-Agent99-Backup-Health" `
|
|
-Action $backupAction `
|
|
-Trigger $backupTrigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Agent99 backup freshness, integrity-status, cron-contract, and Telegram alert guard." `
|
|
-Force | Out-Null
|
|
|
|
$taskNames = @(
|
|
"Wooo-Agent99-Startup-Recovery",
|
|
"Wooo-Agent99-Heartbeat",
|
|
"Wooo-Agent99-Performance-Guard",
|
|
"Wooo-Agent99-Control-Loop",
|
|
"Wooo-Agent99-Telegram-Inbox",
|
|
"Wooo-Agent99-SRE-Alert-Inbox",
|
|
"Wooo-Agent99-SRE-Alert-Relay",
|
|
"Wooo-Agent99-Self-Health",
|
|
"Wooo-Agent99-Backup-Health"
|
|
)
|
|
|
|
Get-ScheduledTask -TaskName $taskNames -ErrorAction SilentlyContinue |
|
|
Select-Object TaskName, State, TaskPath
|