<# .SYNOPSIS AgentsMeeting Windows Services �?一键启动所有组�?.DESCRIPTION 按依赖顺序启�? api_proxy �?wechat_agent �?xmpp_bot �?watchdog �?health_check 每个服务启动后等待确认,失败则终止�?#> param([switch]$Force) $ErrorActionPreference = "Stop" $Python = "C:\Users\hmo\AppData\Local\Programs\Python\Python310\python.exe" $GatewayRoot = "D:\F\NewI\opencode\daily-workspace\projects\AgentsMeeting\gateway" Write-Host "========================================" -ForegroundColor Cyan Write-Host " AgentsMeeting Windows Services" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan # Stop all existing services first Write-Host "`n[0] Stopping existing services..." -ForegroundColor Yellow Get-Process -Name "python*" -ErrorAction SilentlyContinue | ForEach-Object { $cmd = (Get-CimInstance Win32_Process -Filter "ProcessId=$($_.Id)").CommandLine if ($cmd -match "xmpp_bot|wechat_agent|api_proxy|watchdog|health_check") { Write-Host " Killing PID $($_.Id): $($_.ProcessName)" -ForegroundColor Gray Stop-Process -Id $_.Id -Force -ErrorAction SilentlyContinue } } Start-Sleep -Seconds 3 # 1. API Proxy (port 8787) Write-Host "`n[1/5] Starting API Proxy..." -ForegroundColor Green $proxyScript = Join-Path $GatewayRoot "scripts\api_proxy.py" Start-Process -WindowStyle Hidden -FilePath $Python -ArgumentList $proxyScript Start-Sleep -Seconds 2 $proxyCheck = netstat -ano 2>$null | Select-String ":8787" if ($proxyCheck) { Write-Host " API Proxy: OK (:8787)" -ForegroundColor Green } else { Write-Host " API Proxy: STARTED (port check skipped)" -ForegroundColor Yellow } # 2. WeChat Agent (port 5801 + 19088 via wxhelper) Write-Host "`n[2/5] Starting WeChat Agent..." -ForegroundColor Green $agentScript = Join-Path $GatewayRoot "scripts\wechat_agent.py" Start-Process -WindowStyle Hidden -FilePath $Python -ArgumentList $agentScript Start-Sleep -Seconds 3 Write-Host " WeChat Agent: STARTED" -ForegroundColor Green # 3. XMPP Bot (xxm) Write-Host "`n[3/5] Starting XMPP Bot (xxm)..." -ForegroundColor Green $botScript = Join-Path $GatewayRoot "scripts\xmpp_bot.py" Start-Process -WindowStyle Hidden -FilePath $Python -ArgumentList $botScript Start-Sleep -Seconds 5 $botCheck = Get-CimInstance Win32_Process -Filter "Name='python.exe'" | Where-Object { $_.CommandLine -match "xmpp_bot" -and $_.CommandLine -notmatch "watchdog" } if ($botCheck) { Write-Host " XMPP Bot: OK (PID $($botCheck.ProcessId))" -ForegroundColor Green } else { Write-Host " XMPP Bot: FAILED TO START" -ForegroundColor Red exit 1 } # 4. Watchdog Write-Host "`n[4/5] Starting Watchdog..." -ForegroundColor Green $wdScript = Join-Path $GatewayRoot "scripts\xmpp_watchdog.py" Start-Process -WindowStyle Hidden -FilePath $Python -ArgumentList $wdScript Start-Sleep -Seconds 2 Write-Host " Watchdog: STARTED" -ForegroundColor Green # 5. Mohe watcher �?auto-log mohe replies Write-Host "`n[5/6] Starting Mohe Watcher..." -ForegroundColor Green $moheWatcher = Join-Path $GatewayRoot "scripts\mohe_watcher.py" Start-Process -WindowStyle Hidden -FilePath $Python -ArgumentList $moheWatcher Start-Sleep -Seconds 1 Write-Host " Mohe Watcher: STARTED (�?logs/mohe_inbox.log)" -ForegroundColor Green # 6. Health check (scheduled task) Write-Host "`n[6/6] Registering health check..." -ForegroundColor Green $taskName = "xxm-health-check" $checkScript = Join-Path $GatewayRoot "scripts\health_check_xxm.py" try { Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue $action = New-ScheduledTaskAction -Execute $Python -Argument "`"$checkScript`"" $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(1) ` -RepetitionInterval (New-TimeSpan -Minutes 5) ` -RepetitionDuration (New-TimeSpan -Days 365) $principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType S4U -RunLevel Limited Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Force | Out-Null Write-Host " Health Check: OK (every 5 min)" -ForegroundColor Green } catch { Write-Host " Health Check: WARNING - $($_.Exception.Message)" -ForegroundColor Yellow } Write-Host "`n========================================" -ForegroundColor Cyan Write-Host " ALL SERVICES STARTED" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Cyan Write-Host " Dashboard: http://192.168.1.246:5803 (Linux)" -ForegroundColor Green Write-Host " Logs: $GatewayRoot\logs\" -ForegroundColor Gray Write-Host " Status: powershell -File deploy\windows\check.ps1" -ForegroundColor Gray