-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStop.bat
More file actions
70 lines (62 loc) · 2.52 KB
/
Copy pathStop.bat
File metadata and controls
70 lines (62 loc) · 2.52 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@echo off
chcp 936 >nul
setlocal EnableExtensions EnableDelayedExpansion
rem "检查当前批处理是否已经以管理员身份运行;未提升时触发一次 UAC 重启。"
fltmc >nul 2>&1
if errorlevel 1 (
powershell -NoProfile -ExecutionPolicy Bypass -Command "Start-Process -FilePath '%~f0' -WorkingDirectory '%~dp0' -Verb RunAs"
if errorlevel 1 (
echo [错误] 管理员权限获取失败,可能是取消了 UAC 或当前账户没有管理员权限。
pause
exit /b 1
)
exit /b 0
)
title 鱼丸工作室_SHUTDOWN_TOOL
set "APP_DIR=%~dp0"
set "PID_FILE=%APP_DIR%master.pid"
pushd "%APP_DIR%" >nul 2>&1
if errorlevel 1 (
echo [错误] 无法进入控制面板目录:%APP_DIR%
pause
exit /b 1
)
echo ====================================================
echo 鱼丸工作室- 控制面板与服务停止工具
echo ====================================================
echo.
set "STOPPED=0"
if exist "%PID_FILE%" (
set /p APP_PID=<"%PID_FILE%"
if defined APP_PID (
powershell -NoProfile -ExecutionPolicy Bypass -Command "$p = Get-CimInstance Win32_Process -Filter 'ProcessId=!APP_PID!' -ErrorAction SilentlyContinue; if ($p -and $p.CommandLine -match 'uvicorn.*main:app') { exit 0 } else { exit 1 }" >nul 2>&1
if not errorlevel 1 (
echo 正在停止控制面板进程 PID !APP_PID! ...
taskkill /F /T /PID !APP_PID! >nul 2>&1
if not errorlevel 1 set "STOPPED=1"
) else (
echo [提示] master.pid 文件已失效,跳过该PID
)
)
)
rem 处理异常退出后残留的控制面板监听进程,仅严格限定Uvicorn程序
call :kill_uvicorn_port 8099
rem 8001 是services.yaml业务服务端口,仅清理确认为Uvicorn的监听进程
call :kill_uvicorn_port 8001
if exist "%PID_FILE%" del /f /q "%PID_FILE%" >nul 2>&1
if "%STOPPED%"=="1" (
echo [成功] 控制面板进程已停止
) else (
echo [提示] 未找到本项目记录的控制面板进程,已完成残留端口检查
)
echo ====================================================
popd
powershell -NoProfile -Command "Start-Sleep -Seconds 2"
exit /b 0
:kill_uvicorn_port
set "TARGET_PORT=%~1"
for /f "usebackq delims=" %%P in (`powershell -NoProfile -ExecutionPolicy Bypass -Command "$connections = Get-NetTCPConnection -LocalPort %TARGET_PORT% -State Listen -ErrorAction SilentlyContinue; foreach ($connection in $connections) { $p = Get-CimInstance Win32_Process -Filter ('ProcessId=' + $connection.OwningProcess) -ErrorAction SilentlyContinue; if ($p -and $p.CommandLine -match 'uvicorn') { $connection.OwningProcess } }"`) do (
echo 正在清理Uvicorn监听进程 PID %%P(端口%TARGET_PORT%)...
taskkill /F /T /PID %%P >nul 2>&1
)
goto :eof