Deploy Windows gateway as persistent scheduled task and verify public ADB
This commit is contained in:
1 parent
c38f067bea
commit
3fb894c1a1
9 files changed
+193
-13
No files matched your search
@@ -0,0 +1,23 @@
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$root = [System.IO.Path]::GetFullPath($PSScriptRoot)
|
||||
$config = Get-Content -LiteralPath (Join-Path $root 'agent.json') -Raw | ConvertFrom-Json
|
||||
$tokenFile = Join-Path $root 'agent.env'
|
||||
foreach ($line in Get-Content -LiteralPath $tokenFile) {
|
||||
if ($line.StartsWith('ADS_AGENT_TOKEN=')) { $env:ADS_AGENT_TOKEN = $line.Substring(16) }
|
||||
}
|
||||
if (-not $env:ADS_AGENT_TOKEN -or $env:ADS_AGENT_TOKEN.Length -lt 32) { throw 'Missing agent token' }
|
||||
if (-not $config.server.StartsWith('wss://')) { throw 'Public relay requires WSS' }
|
||||
$env:RUST_LOG = 'info'
|
||||
$logDirectory = Join-Path $root 'logs'
|
||||
New-Item -ItemType Directory -Path $logDirectory -Force | Out-Null
|
||||
$logFile = Join-Path $logDirectory 'agent.log'
|
||||
if ((Test-Path -LiteralPath $logFile) -and (Get-Item -LiteralPath $logFile).Length -gt 10MB) {
|
||||
Move-Item -LiteralPath $logFile -Destination ($logFile + '.1') -Force
|
||||
}
|
||||
$arguments = @('--server', [string]$config.server, '--device', [string]$config.device, '--target', [string]$config.target)
|
||||
if ($config.connect_address) { $arguments += @('--connect-address', [string]$config.connect_address) }
|
||||
# Keep the child in this task's process tree. Task Scheduler owns its lifecycle.
|
||||
# Tracing writes to stdout; stderr is also retained for startup diagnostics.
|
||||
$ErrorActionPreference = 'Continue'
|
||||
& (Join-Path $root 'ads-agent.exe') @arguments >> $logFile 2>&1
|
||||
exit $LASTEXITCODE
|
||||
Reference in new issue
Block a user