Repository navigation
Expand file tree
/
Copy pathstop_scriptotic_web.ps1
More file actions
94 lines (78 loc) · 3.12 KB
/
Copy pathstop_scriptotic_web.ps1
File metadata and controls
94 lines (78 loc) · 3.12 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Scriptotic Backend Shutdown Script
# Stops vLLM server and Flask web server in WSL2
# Called by the Sentinel service during idle timeout
param(
[switch]$Verbose,
[switch]$Force
)
# Logging function
function Write-Log {
param([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logMessage = "[$timestamp] STOP-SCRIPT: $Message"
Write-Output $logMessage
if ($Verbose) { Write-Host $logMessage -ForegroundColor Yellow }
}
Write-Log "Stopping Scriptotic backend services..."
try {
# Stop vLLM server in WSL2 first (force kill all processes)
Write-Log "Force killing all vLLM processes in WSL2..."
$vllmKillCommands = @(
"pkill -9 -f 'vllm.entrypoints.openai.api_server'",
"pkill -9 -f 'multiprocessing.spawn'",
"pkill -9 -f 'multiprocessing.resource_tracker'",
"pkill -9 -f 'python.*vllm'"
)
foreach ($cmd in $vllmKillCommands) {
Start-Process -FilePath "wsl" -ArgumentList @("-d", "Ubuntu", "bash", "-c", "$cmd || true") -Wait -WindowStyle Hidden
}
Write-Log "vLLM processes force killed"
# Give processes time to die and GPU memory to release
Start-Sleep -Seconds 3
# Verify GPU memory is released
try {
$gpuCheck = wsl -d Ubuntu bash -c "nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits"
$gpuMemory = [int]$gpuCheck
if ($gpuMemory -lt 2000) {
Write-Log "GPU memory released successfully ($gpuMemory MB)"
} else {
Write-Log "Warning: GPU memory still high ($gpuMemory MB) - some processes may not have died"
}
} catch {
Write-Log "Could not check GPU memory status"
}
Write-Log "Stopping Flask web server on Windows..."
# Find and stop Flask processes
$flaskProcesses = Get-Process -Name "python" -ErrorAction SilentlyContinue | Where-Object {
$_.CommandLine -like "*web_server.py*"
}
if ($flaskProcesses) {
foreach ($process in $flaskProcesses) {
Write-Log "Stopping Flask process PID: $($process.Id)"
try {
$process.Kill()
$process.WaitForExit(5000) # Wait up to 5 seconds
Write-Log "Flask process stopped successfully"
} catch {
Write-Log "Warning: Could not stop Flask process PID $($process.Id): $($_.Exception.Message)"
}
}
} else {
Write-Log "No Flask web server processes found"
}
# Verify Flask is stopped
Start-Sleep -Seconds 1
$remainingFlask = Get-Process -Name "python" -ErrorAction SilentlyContinue | Where-Object {
$_.CommandLine -like "*web_server.py*"
}
if (-not $remainingFlask) {
Write-Log "SUCCESS: Flask web server stopped cleanly"
} else {
Write-Log "WARNING: Some Flask processes may still be running"
}
} catch {
Write-Log "EXCEPTION during shutdown: $($_.Exception.Message)"
Write-Log "Stack trace: $($_.ScriptStackTrace)"
# Don't exit with error code - shutdown failures shouldn't break the sentinel
}
Write-Log "Shutdown script completed"