70 lines
2.4 KiB
PowerShell
70 lines
2.4 KiB
PowerShell
$ErrorActionPreference = "Stop"
|
|
|
|
$taskName = "SDR Rover HTTP Control Server"
|
|
$repository = Split-Path -Parent $PSScriptRoot
|
|
$pythonCommand = Get-Command python.exe -ErrorAction Stop
|
|
$python = $pythonCommand.Source
|
|
$serverScript = Join-Path $repository "tools\rf001_http_control.py"
|
|
$tokenFile = Join-Path $repository ".local\rf001_http_token.txt"
|
|
$stateFile = Join-Path $repository ".local\rf001_http_server_state.json"
|
|
$logFile = Join-Path $repository ".local\logs\rf001_http_service.log"
|
|
|
|
foreach ($required in @($python, $serverScript, $tokenFile)) {
|
|
if (-not (Test-Path -LiteralPath $required -PathType Leaf)) {
|
|
throw "Required file is absent: $required"
|
|
}
|
|
}
|
|
|
|
$arguments = @(
|
|
"-u",
|
|
"-B",
|
|
('"{0}"' -f $serverScript),
|
|
"serve",
|
|
"--bind", "192.168.255.185",
|
|
"--port", "8765",
|
|
"--allowed-agent-ip", "192.168.255.56",
|
|
"--state-file", ('"{0}"' -f $stateFile),
|
|
"--token-file", ('"{0}"' -f $tokenFile),
|
|
"--log-file", ('"{0}"' -f $logFile),
|
|
"--bind-retry-seconds", "300"
|
|
) -join " "
|
|
|
|
$account = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
|
|
$action = New-ScheduledTaskAction -Execute $python -Argument $arguments -WorkingDirectory $repository
|
|
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $account
|
|
$principal = New-ScheduledTaskPrincipal -UserId $account -LogonType Interactive -RunLevel Limited
|
|
$settings = New-ScheduledTaskSettingsSet `
|
|
-AllowStartIfOnBatteries `
|
|
-DontStopIfGoingOnBatteries `
|
|
-StartWhenAvailable `
|
|
-RestartCount 10 `
|
|
-RestartInterval (New-TimeSpan -Minutes 1) `
|
|
-ExecutionTimeLimit ([TimeSpan]::Zero) `
|
|
-MultipleInstances IgnoreNew
|
|
|
|
$existing = Get-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
|
if ($null -ne $existing) {
|
|
Stop-ScheduledTask -TaskName $taskName -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Register-ScheduledTask `
|
|
-TaskName $taskName `
|
|
-Action $action `
|
|
-Trigger $trigger `
|
|
-Principal $principal `
|
|
-Settings $settings `
|
|
-Description "Authenticated RF-001 control server. No network RF TX operation." `
|
|
-Force | Out-Null
|
|
|
|
Start-ScheduledTask -TaskName $taskName
|
|
Start-Sleep -Seconds 2
|
|
$task = Get-ScheduledTask -TaskName $taskName
|
|
$taskInfo = Get-ScheduledTaskInfo -TaskName $taskName
|
|
|
|
"AUTOSTART_TASK=$taskName"
|
|
"AUTOSTART_ACCOUNT=$account"
|
|
"AUTOSTART_MODE=USER_LOGON"
|
|
"TASK_STATE=$($task.State)"
|
|
"LAST_TASK_RESULT=$($taskInfo.LastTaskResult)"
|
|
"RF_TX=0"
|