-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_service.ps1
More file actions
45 lines (36 loc) · 1.94 KB
/
Copy pathstart_service.ps1
File metadata and controls
45 lines (36 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# 修改历史 (Revision History)
# ==================================
# 版本: v1.0
# 日期: 2026-06-25
# 修改说明: 一键启动 Copilot API 服务的 PowerShell 脚本。智能检测凭证有效性,自动清理占用 8000 端口的旧进程并重启 app.py。
$ErrorActionPreference = "Stop"
# 1. 检查凭证是否有效
Write-Host "==================================================" -ForegroundColor Cyan
Write-Host "🤖 正在诊断 Copilot 登录凭证有效性..." -ForegroundColor Cyan
Write-Host "==================================================" -ForegroundColor Cyan
$verifyResult = & venv\Scripts\python verify_auth.py
$exitCode = $LASTEXITCODE
if ($exitCode -ne 0) {
Write-Host "[!] 登录凭证已失效或不存在,需要重新登录。" -ForegroundColor Yellow
Write-Host "[*] 正在拉起 Chrome 浏览器抓取新凭证,请按浏览器提示完成登录和对话测试..." -ForegroundColor Yellow
# 执行登录命令
& venv\Scripts\python -m copilot login
# 再次验证
$verifyResult = & venv\Scripts\python verify_auth.py
if ($LASTEXITCODE -ne 0) {
Write-Host "[Error] 凭证获取失败,无法启动服务,请检查网络或重新运行登录流程。" -ForegroundColor Red
Exit 1
}
} else {
Write-Host "[Success] 凭证验证成功,无需重新登录!" -ForegroundColor Green
}
# 2. 完全重启服务
Write-Host "[*] 正在检查并清理本地 8000 端口旧进程..." -ForegroundColor Yellow
Get-NetTCPConnection -LocalPort 8000 -ErrorAction SilentlyContinue | ForEach-Object {
Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue
}
Write-Host "[Success] 旧进程清理完成!" -ForegroundColor Green
Write-Host "[*] 正在启动 API 服务器..." -ForegroundColor Green
Write-Host "--------------------------------------------------" -ForegroundColor Gray
# 启动 app.py 并把日志实时打印到屏幕上
& venv\Scripts\python app.py