-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.ps1
More file actions
58 lines (50 loc) · 2.63 KB
/
Copy pathstart.ps1
File metadata and controls
58 lines (50 loc) · 2.63 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
Write-Host "=========================================" -ForegroundColor Cyan
Write-Host " Quartermaster .NET - Startup" -ForegroundColor Cyan
Write-Host "=========================================" -ForegroundColor Cyan
# Warning for Service users
if (Get-Service -Name "QuartermasterBot" -ErrorAction SilentlyContinue) {
Write-Host "⚠️ WARNING: Windows Services (QuartermasterBot/Web) detected." -ForegroundColor Yellow
Write-Host "If the services are already running, this manual start will fail due to file locks or port conflicts." -ForegroundColor Yellow
$ans = Read-Host "Continue manual startup? (Y/N)"
if ($ans -ne "Y") { exit }
}
# Cleanup existing processes to avoid port/file locks
Write-Host "Cleaning up old processes..." -ForegroundColor Yellow
Get-Process Quartermaster.Bot -ErrorAction SilentlyContinue | Stop-Process -Force
Get-Process Quartermaster.Web -ErrorAction SilentlyContinue | Stop-Process -Force
# Ensure build is up to date
Write-Host "Checking build..."
dotnet build --configuration Release
if ($LASTEXITCODE -ne 0) {
Write-Host "Build failed! Please fix errors before starting." -ForegroundColor Red
exit 1
}
# Start the Bot and Web Host
try {
Write-Host "Starting Bot and Web Dashboard..." -ForegroundColor Green
# Use Start-Process with Hidden window for a clean background run
$bot = Start-Process dotnet -ArgumentList "run --project Quartermaster.Bot --configuration Release" -PassThru -WindowStyle Hidden
$web = Start-Process dotnet -ArgumentList "run --project Quartermaster.Web --configuration Release" -PassThru -WindowStyle Hidden
Write-Host "Processes started."
Write-Host "Bot PID: $($bot.Id)"
Write-Host "Web PID: $($web.Id)"
Write-Host "Press Ctrl+C to stop both services gracefully."
# Wait for processes
Wait-Process -Id $bot.Id, $web.Id
}
finally {
Write-Host "`nStopping Quartermaster processes..." -ForegroundColor Yellow
if ($bot) {
Write-Host "Stopping Bot (PID: $($bot.Id))..."
Stop-Process -Id $bot.Id -Force -ErrorAction SilentlyContinue
}
if ($web) {
Write-Host "Stopping Web (PID: $($web.Id))..."
Stop-Process -Id $web.Id -Force -ErrorAction SilentlyContinue
}
# Thorough cleanup of named processes to avoid any orphans
Get-Process Quartermaster.Bot -ErrorAction SilentlyContinue | Stop-Process -Force
Get-Process Quartermaster.Web -ErrorAction SilentlyContinue | Stop-Process -Force
Get-Process dotnet -ErrorAction SilentlyContinue | Where-Object { $_.CommandLine -like "*Quartermaster.*" } | Stop-Process -Force
Write-Host "Quartermaster stopped successfully." -ForegroundColor Green
}