Keep Windows training agent alive
This commit is contained in:
@@ -3,7 +3,8 @@ param(
|
|||||||
[string]$TaskName = "TradeBot Windows Training Agent",
|
[string]$TaskName = "TradeBot Windows Training Agent",
|
||||||
[string]$ApiBaseUrl = "https://tb.kusoft.xyz",
|
[string]$ApiBaseUrl = "https://tb.kusoft.xyz",
|
||||||
[string]$ApiAuth = "",
|
[string]$ApiAuth = "",
|
||||||
[int]$PollSeconds = 60,
|
[int]$PollSeconds = 10,
|
||||||
|
[int]$WatchdogMinutes = 5,
|
||||||
[string]$RepoRoot = "",
|
[string]$RepoRoot = "",
|
||||||
[switch]$StartNow,
|
[switch]$StartNow,
|
||||||
[switch]$KeepLegacyRetrainer
|
[switch]$KeepLegacyRetrainer
|
||||||
@@ -59,6 +60,7 @@ if (-not $KeepLegacyRetrainer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$python = Resolve-Python
|
$python = Resolve-Python
|
||||||
|
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
||||||
$arguments = @(
|
$arguments = @(
|
||||||
"-u",
|
"-u",
|
||||||
"`"$Agent`"",
|
"`"$Agent`"",
|
||||||
@@ -68,9 +70,17 @@ $arguments = @(
|
|||||||
) -join " "
|
) -join " "
|
||||||
|
|
||||||
$action = New-ScheduledTaskAction -Execute $python -Argument $arguments -WorkingDirectory $RepoRoot
|
$action = New-ScheduledTaskAction -Execute $python -Argument $arguments -WorkingDirectory $RepoRoot
|
||||||
$trigger = New-ScheduledTaskTrigger -AtLogOn -User ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
|
$trigger = @(
|
||||||
|
New-ScheduledTaskTrigger -AtLogOn -User $currentUser
|
||||||
|
New-ScheduledTaskTrigger -AtStartup
|
||||||
|
New-ScheduledTaskTrigger `
|
||||||
|
-Once `
|
||||||
|
-At (Get-Date).AddMinutes(1) `
|
||||||
|
-RepetitionInterval (New-TimeSpan -Minutes $WatchdogMinutes) `
|
||||||
|
-RepetitionDuration (New-TimeSpan -Days 3650)
|
||||||
|
)
|
||||||
$principal = New-ScheduledTaskPrincipal `
|
$principal = New-ScheduledTaskPrincipal `
|
||||||
-UserId ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name) `
|
-UserId $currentUser `
|
||||||
-LogonType Interactive `
|
-LogonType Interactive `
|
||||||
-RunLevel Limited
|
-RunLevel Limited
|
||||||
$settings = New-ScheduledTaskSettingsSet `
|
$settings = New-ScheduledTaskSettingsSet `
|
||||||
@@ -78,6 +88,8 @@ $settings = New-ScheduledTaskSettingsSet `
|
|||||||
-MultipleInstances IgnoreNew `
|
-MultipleInstances IgnoreNew `
|
||||||
-AllowStartIfOnBatteries `
|
-AllowStartIfOnBatteries `
|
||||||
-DontStopIfGoingOnBatteries `
|
-DontStopIfGoingOnBatteries `
|
||||||
|
-RestartCount 999 `
|
||||||
|
-RestartInterval (New-TimeSpan -Minutes 1) `
|
||||||
-ExecutionTimeLimit (New-TimeSpan -Days 30)
|
-ExecutionTimeLimit (New-TimeSpan -Days 30)
|
||||||
|
|
||||||
Register-ScheduledTask `
|
Register-ScheduledTask `
|
||||||
@@ -93,6 +105,6 @@ if ($StartNow) {
|
|||||||
Start-ScheduledTask -TaskName $TaskName
|
Start-ScheduledTask -TaskName $TaskName
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Registered scheduled task '$TaskName' for Windows logon."
|
Write-Host "Registered scheduled task '$TaskName' for Windows startup, logon, and watchdog restarts."
|
||||||
Write-Host "Agent API: $ApiBaseUrl"
|
Write-Host "Agent API: $ApiBaseUrl"
|
||||||
Write-Host "Agent script: $Agent"
|
Write-Host "Agent script: $Agent"
|
||||||
|
|||||||
Reference in New Issue
Block a user