diff --git a/README.md b/README.md index 895df32..f594965 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,8 @@ powershell -ExecutionPolicy Bypass -File .\start.ps1 3. 按提示选择 [1] 本地访问 或 [2] 局域网访问,脚本将自动配置并启动 Docker 服务。 +4. 若窗口闪退,可查看日志 `start.ps1.log`(与 start.ps1 同目录,或 `%TEMP%\start.ps1.log`)获取退出原因。 + ### 启用HTTPS 1. [更改为你的域名]修改`easyai-proxy.conf`中域名`51easyai.com`为你的域名[可以使用Ctrl+F批量替换51easyai.com为你的域名] 2. [修改.env文件]修改如下两个环境变量为如下的对应的值 diff --git a/start.ps1 b/start.ps1 index 105e8a2..c6df889 100644 --- a/start.ps1 +++ b/start.ps1 @@ -4,13 +4,30 @@ # 一行命令: git clone https://git.51easyai.com/wangbo/easyai; cd easyai; .\start.ps1 $ErrorActionPreference = "Stop" +$script:LogFile = Join-Path (if ($PSScriptRoot) { $PSScriptRoot } else { $env:TEMP }) "start.ps1.log" +# 尽早写入启动标记,便于闪退时排查 +try { "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] === 脚本加载 ===" | Out-File -FilePath $script:LogFile -Append -Encoding utf8 } catch { } + +function Write-Log { + param([string]$Msg) + try { + $line = "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')] $Msg" + Add-Content -Path $script:LogFile -Value $line -Encoding UTF8 -ErrorAction SilentlyContinue + } catch { } +} + 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)" } + $errMsg = $_.Exception.Message + $errStack = if ($_.ScriptStackTrace) { " | 堆栈: $($_.ScriptStackTrace)" } else { "" } + Write-Log "错误退出: $errMsg$errStack" + try { + Write-Host "" + Write-Host "========================================" -ForegroundColor Red + Write-Host " 发生错误,详见日志: $script:LogFile" -ForegroundColor Red + Write-Host "========================================" -ForegroundColor Red + Write-Host $errMsg -ForegroundColor Red + if ($errStack) { Write-Host $errStack } + } catch { } Wait-ForExit exit 1 } @@ -280,6 +297,9 @@ function Main { Wait-ForExit } +Write-Log "=== 脚本启动 ===" Write-Host "EasyAI Windows 部署脚本启动中..." -ForegroundColor Cyan +Write-Host "日志文件: $script:LogFile" Write-Host "" Main +Write-Log "=== 脚本正常结束 ==="