feat: pi-agent-public.ps1 增加 -NoTunnel 开关(明确跳过隧道注册/启动,新电脑不穿透用)

This commit is contained in:
luckyyzh
2026-08-03 18:52:18 +08:00
parent f531e8e2ef
commit bd4eb05a2a
+9 -4
View File
@@ -1,7 +1,8 @@
[CmdletBinding()] [CmdletBinding()]
param( param(
[ValidateSet('status', 'start', 'restart', 'stop')] [ValidateSet('status', 'start', 'restart', 'stop')]
[string]$Action = 'status' [string]$Action = 'status',
[switch]$NoTunnel
) )
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
@@ -50,7 +51,11 @@ function Ensure-Tasks {
-Settings $settings -Description 'Pi Agent Integrated Web supervisor' -Force | Out-Null -Settings $settings -Description 'Pi Agent Integrated Web supervisor' -Force | Out-Null
} }
# Tunnel 任务:可选,仅在配置了 PI_AGENT_TUNNEL_COMMAND 时注册 # Tunnel 任务:可选,仅在配置了 PI_AGENT_TUNNEL_COMMAND 时注册;-NoTunnel 明确跳过
if ($NoTunnel) {
Write-Host " - 已跳过隧道任务(-NoTunnel)"
return
}
if (Get-ScheduledTask -TaskName $tunnelTaskName -ErrorAction SilentlyContinue) { return } if (Get-ScheduledTask -TaskName $tunnelTaskName -ErrorAction SilentlyContinue) { return }
if ([string]::IsNullOrWhiteSpace($tunnelCommand)) { if ([string]::IsNullOrWhiteSpace($tunnelCommand)) {
Write-Host " - 未配置 PI_AGENT_TUNNEL_COMMAND,跳过隧道任务" Write-Host " - 未配置 PI_AGENT_TUNNEL_COMMAND,跳过隧道任务"
@@ -98,7 +103,7 @@ switch ($Action) {
} }
'start' { 'start' {
Ensure-Tasks Ensure-Tasks
Start-ScheduledTask -TaskName $tunnelTaskName -ErrorAction SilentlyContinue if (-not $NoTunnel) { Start-ScheduledTask -TaskName $tunnelTaskName -ErrorAction SilentlyContinue }
Start-ScheduledTask -TaskName $webTaskName Start-ScheduledTask -TaskName $webTaskName
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
Get-PublicAccessStatus Get-PublicAccessStatus
@@ -107,7 +112,7 @@ switch ($Action) {
Stop-ScheduledTask -TaskName $webTaskName -ErrorAction SilentlyContinue Stop-ScheduledTask -TaskName $webTaskName -ErrorAction SilentlyContinue
Stop-ScheduledTask -TaskName $tunnelTaskName -ErrorAction SilentlyContinue Stop-ScheduledTask -TaskName $tunnelTaskName -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2 Start-Sleep -Seconds 2
Start-ScheduledTask -TaskName $tunnelTaskName if (-not $NoTunnel) { Start-ScheduledTask -TaskName $tunnelTaskName -ErrorAction SilentlyContinue }
Start-ScheduledTask -TaskName $webTaskName Start-ScheduledTask -TaskName $webTaskName
Start-Sleep -Seconds 3 Start-Sleep -Seconds 3
Get-PublicAccessStatus Get-PublicAccessStatus