fix: 修复 Windows start.ps1 闪退,保持终端不关闭便于 Debug
Some checks are pending
Test start.ps1 (Windows) / test-windows (push) Waiting to run

- 增加 trap 错误捕获与堆栈输出
- 增加 Wait-ForExit 结束时暂停,避免窗口闪退
- 使用 $PSScriptRoot 获取脚本目录
- README 补充 Windows 权限配置与启动说明

Made-with: Cursor
This commit is contained in:
wangbo 2026-03-10 22:13:12 +08:00
parent b7a11abe9f
commit fe370bd5bc
2 changed files with 64 additions and 5 deletions

View File

@ -247,6 +247,44 @@ chmod +x start.sh
``` ```
6. 脚本运行完成无错误,并且提示`EasyAI应用启动成功`表示应用启动成功打开浏览器输入服务器的公网ip3010或者局域网IP3010即可访问EasyAI应用 6. 脚本运行完成无错误,并且提示`EasyAI应用启动成功`表示应用启动成功打开浏览器输入服务器的公网ip3010或者局域网IP3010即可访问EasyAI应用
## Windows 一键启动
start.ps1 脚本用于 Windows 本机/局域网一键部署 EasyAI 应用。**不要直接双击运行**(会闪退),请按以下方式执行:
### 权限配置(首次执行必做)
PowerShell 默认可能禁止运行脚本,需先执行以下任一方式:
**方式一:临时允许本次运行(推荐)**
```powershell
powershell -ExecutionPolicy Bypass -File .\start.ps1
```
**方式二:为当前用户永久放开脚本执行权限**
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
```
执行后再运行 `.\start.ps1` 即可。
### 启动步骤
1. 克隆并进入目录
```powershell
git clone https://git.51easyai.com/wangbo/easyai.git
cd easyai
```
2. 在 PowerShell 或 CMD 中运行(二选一)
```powershell
# 若已设置 ExecutionPolicy可直接执行
.\start.ps1
# 未设置时使用 Bypass 方式
powershell -ExecutionPolicy Bypass -File .\start.ps1
```
3. 按提示选择 [1] 本地访问 或 [2] 局域网访问,脚本将自动配置并启动 Docker 服务。
### 启用HTTPS ### 启用HTTPS
1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名] 1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名]
2. [修改.env文件]修改如下两个环境变量为如下的对应的值 2. [修改.env文件]修改如下两个环境变量为如下的对应的值

View File

@ -4,6 +4,23 @@
# 一行命令: git clone https://git.51easyai.com/wangbo/easyai; cd easyai; .\start.ps1 # 一行命令: git clone https://git.51easyai.com/wangbo/easyai; cd easyai; .\start.ps1
$ErrorActionPreference = "Stop" $ErrorActionPreference = "Stop"
trap {
Write-Host ""
Write-Host "========================================" -ForegroundColor Red
Write-Host " 发生错误(便于 Debug" -ForegroundColor Red
Write-Host "========================================" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
if ($_.ScriptStackTrace) { Write-Host "`n$($_.ScriptStackTrace)" }
Wait-ForExit
exit 1
}
# 结束时保持窗口不关闭,便于查看输出和 DebugCI 环境自动跳过)
function Wait-ForExit {
if ($env:CI -eq "true") { return }
Write-Host ""
Read-Host "按 Enter 键退出"
}
# 仅配置模式DEPLOY_DRY_RUN=1 只生成配置文件,不执行 Docker 安装和启动 # 仅配置模式DEPLOY_DRY_RUN=1 只生成配置文件,不执行 Docker 安装和启动
$script:DeployDryRun = if ($env:DEPLOY_DRY_RUN -eq "1") { $true } else { $false } $script:DeployDryRun = if ($env:DEPLOY_DRY_RUN -eq "1") { $true } else { $false }
@ -15,12 +32,13 @@ $DockerDesktopUrl = "https://desktop.docker.com/win/main/amd64/Docker%20Desktop%
function Write-Step { param($Msg) Write-Host $Msg } function Write-Step { param($Msg) Write-Host $Msg }
function Write-Ok { param($Msg) Write-Host "$Msg" -ForegroundColor Green } function Write-Ok { param($Msg) Write-Host "$Msg" -ForegroundColor Green }
function Write-Err { param($Msg) Write-Host "$Msg" -ForegroundColor Red; exit 1 } function Write-Err { param($Msg) Write-Host "$Msg" -ForegroundColor Red; throw $Msg }
function Write-Warn { param($Msg) Write-Host "⚠️ $Msg" -ForegroundColor Yellow } function Write-Warn { param($Msg) Write-Host "⚠️ $Msg" -ForegroundColor Yellow }
# ==================== 项目初始化 ==================== # ==================== 项目初始化 ====================
function Init-ProjectDir { function Init-ProjectDir {
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path $scriptDir = $PSScriptRoot
if (-not $scriptDir) { throw "无法获取脚本所在目录。请在 easyai 目录下打开 PowerShell 执行: .\start.ps1" }
$composePath = Join-Path $scriptDir "docker-compose.yml" $composePath = Join-Path $scriptDir "docker-compose.yml"
if (Test-Path $composePath) { if (Test-Path $composePath) {
Set-Location $scriptDir Set-Location $scriptDir
@ -122,7 +140,7 @@ function Install-DockerDesktop {
if (-not $isWin) { if (-not $isWin) {
Write-Warn "自动安装仅支持 Windows。请手动安装 Docker Desktop。" Write-Warn "自动安装仅支持 Windows。请手动安装 Docker Desktop。"
Write-Host "下载地址: $DockerDesktopUrl" Write-Host "下载地址: $DockerDesktopUrl"
exit 1 Wait-ForExit; exit 1
} }
# 优先 winget其次 Chocolatey # 优先 winget其次 Chocolatey
@ -145,7 +163,7 @@ function Install-DockerDesktop {
Write-Warn "未找到 winget 或 Chocolatey请手动安装 Docker Desktop。" Write-Warn "未找到 winget 或 Chocolatey请手动安装 Docker Desktop。"
Write-Host "下载地址: $DockerDesktopUrl" Write-Host "下载地址: $DockerDesktopUrl"
exit 1 Wait-ForExit; exit 1
} }
function Test-Docker { function Test-Docker {
@ -179,7 +197,7 @@ function Test-Docker {
if ($env:OS -eq "Windows_NT") { if ($env:OS -eq "Windows_NT") {
Start-Process $DockerDesktopUrl Start-Process $DockerDesktopUrl
} }
exit 1 Wait-ForExit; exit 1
} }
"2" { "2" {
Install-DockerDesktop Install-DockerDesktop
@ -259,6 +277,9 @@ function Main {
$accessIp = if ($script:DeployIP) { $script:DeployIP } else { "127.0.0.1" } $accessIp = if ($script:DeployIP) { $script:DeployIP } else { "127.0.0.1" }
Write-Host "访问地址: http://${accessIp}:3010" Write-Host "访问地址: http://${accessIp}:3010"
Write-Host "" Write-Host ""
Wait-ForExit
} }
Write-Host "EasyAI Windows 部署脚本启动中..." -ForegroundColor Cyan
Write-Host ""
Main Main