Repository navigation
Expand file tree
/
Copy pathstart_scriptotic_web.ps1
More file actions
114 lines (91 loc) · 4.34 KB
/
Copy pathstart_scriptotic_web.ps1
File metadata and controls
114 lines (91 loc) · 4.34 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# Scriptotic Backend Startup Script
# Starts vLLM server and Flask web server in WSL2
# Called by the Sentinel service for on-demand activation
param(
[switch]$Verbose
)
# Explicit interpreter paths - clean consolidation to 2 environments
$VENV = "D:\Coding\Scriptotic\venv"
$PY = Join-Path $VENV "Scripts\python.exe"
# Logging function
function Write-Log {
param([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logMessage = "[$timestamp] START-SCRIPT: $Message"
Write-Output $logMessage
if ($Verbose) { Write-Host $logMessage -ForegroundColor Green }
}
Write-Log "Starting Scriptotic backend services..."
try {
# Verify the intended interpreter exists
if (-not (Test-Path $PY)) {
Write-Error "Interpreter missing: $PY"
exit 1
}
# Set UTF-8 encoding for WSL communication
$env:WSL_UTF8 = "1"
$env:PYTHONUTF8 = "1"
# Start Flask on Windows using explicit venv interpreter
Write-Log "Starting Flask web server with interpreter: $PY"
# Check if Flask is already running
$flaskProcess = Get-Process -Name "python" -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -like "*web_server.py*" }
if (-not $flaskProcess) {
# Sanity guard - ensure we're using the right interpreter
$sanityCheck = & $PY -c "import os, sys; expected = r'$PY'; print('Interpreter verified:', sys.executable)"
Write-Log $sanityCheck
# Start Flask server using explicit venv interpreter
$flaskStartInfo = New-Object System.Diagnostics.ProcessStartInfo
$flaskStartInfo.FileName = $PY
$flaskStartInfo.Arguments = "src/core/web_server.py"
$flaskStartInfo.WorkingDirectory = "D:\Coding\Scriptotic"
$flaskStartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
$flaskStartInfo.UseShellExecute = $false
$flaskProcess = [System.Diagnostics.Process]::Start($flaskStartInfo)
Write-Log "Flask process started with PID: $($flaskProcess.Id)"
# Give Flask time to start
Start-Sleep -Seconds 3
} else {
Write-Log "Flask web server already running"
}
# Check if Flask is responding
$maxAttempts = 10
$attempt = 0
$flaskHealthy = $false
while ($attempt -lt $maxAttempts -and -not $flaskHealthy) {
try {
$response = Invoke-RestMethod -Uri "http://localhost:5000/api/server-status" -TimeoutSec 2 -ErrorAction Stop
$flaskHealthy = $true
Write-Log "Flask server is healthy and responding"
} catch {
Start-Sleep -Seconds 1
$attempt++
}
}
if ($flaskHealthy) {
Write-Log "SUCCESS: Flask server is running and healthy"
} else {
Write-Log "ERROR: Flask server failed to respond to health check"
exit 1
}
# Start vLLM server in WSL2 (the missing piece!)
Write-Log "Starting vLLM server in WSL2..."
$vllmCommand = "source ~/venv-vllm-stable/bin/activate && python -m vllm.entrypoints.openai.api_server --model mistralai/Voxtral-Mini-3B-2507 --task transcription --dtype bfloat16 --kv-cache-dtype fp8_e5m2 --calculate-kv-scales --gpu-memory-utilization 0.95 --max-model-len 4096 --max-num-seqs 1 --port 8000 --host 0.0.0.0 --tokenizer-mode mistral --config-format mistral --load-format mistral"
Start-Process -FilePath "wsl" -ArgumentList @("-d", "Ubuntu", "bash", "-c", $vllmCommand) -WindowStyle Hidden
Write-Log "vLLM server startup command sent to WSL2"
# Start smart shutdown monitor in background
Write-Log "Starting smart shutdown monitor..."
$monitorScript = Join-Path $PSScriptRoot "smart_shutdown_monitor.ps1"
if (Test-Path $monitorScript) {
$monitorArgs = @("-IdleTimeoutSeconds", "60", "-CheckIntervalSeconds", "10")
if ($Verbose) { $monitorArgs += "-Verbose" }
Start-Process -FilePath "powershell" -ArgumentList @("-File", $monitorScript) + $monitorArgs -WindowStyle Hidden
Write-Log "Smart shutdown monitor started in background"
} else {
Write-Log "Warning: Smart shutdown monitor script not found: $monitorScript"
}
} catch {
Write-Log "EXCEPTION during startup: $($_.Exception.Message)"
Write-Log "Stack trace: $($_.ScriptStackTrace)"
exit 1
}
Write-Log "Startup script completed"