forked from existence-master/Sentient
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_all_services.ps1
More file actions
159 lines (134 loc) Β· 7.64 KB
/
start_all_services.ps1
File metadata and controls
159 lines (134 loc) Β· 7.64 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Place this script in the root of your project (e.g., D:\Documents\cyber\projects\Sentient-New\Code)
<#
.SYNOPSIS
Starts all backend services, workers, and the frontend client for the Sentient project.
.DESCRIPTION
This script automates the startup of all necessary services for local development.
It launches each service in its own dedicated PowerShell terminal window with a clear title.
The script handles:
- Starting databases like MongoDB (as admin).
- Launching the Redis message broker within the Windows Subsystem for Linux (WSL).
- Dynamically discovering and starting all MCP (Modular Companion Protocol) servers.
- Activating the Python virtual environment for all backend scripts.
- Running the Celery worker and beat scheduler for background tasks.
- Starting the main FastAPI server and the Next.js frontend client.
.NOTES
- Run this script from your project's root directory.
- You may need to adjust your PowerShell execution policy to run this script.
Open PowerShell as an Administrator and run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
#>
# --- Configuration ---
# Please review and update these paths to match your local setup.
# The name of your WSL distribution where Redis is installed.
$wslDistroName = "Ubuntu"
# --- Script Body ---
try {
# Get the directory where the script is located (your project root)
$projectRoot = $PSScriptRoot
if (-not $projectRoot) { $projectRoot = Get-Location }
# Define key paths
$srcPath = Join-Path -Path $projectRoot -ChildPath "src"
$serverPath = Join-Path -Path $srcPath -ChildPath "server"
$clientPath = Join-Path -Path $srcPath -ChildPath "client"
$mcpHubPath = Join-Path -Path $serverPath -ChildPath "mcp_hub"
$venvActivatePath = Join-Path -Path $serverPath -ChildPath "venv\Scripts\activate.ps1"
# --- Path Validation ---
if (-not (Test-Path -Path $srcPath)) { throw "The 'src' directory was not found. Please run this script from the project root." }
if (-not (Test-Path -Path $serverPath)) { throw "The 'src/server' directory was not found." }
if (-not (Test-Path -Path $clientPath)) { throw "The 'src/client' directory was not found." }
if (-not (Test-Path -Path $mcpHubPath)) { throw "The 'src/server/mcp_hub' directory was not found." }
if (-not (Test-Path -Path $venvActivatePath)) { throw "The venv activation script was not found at '$venvActivatePath'." }
$envFilePath = Join-Path -Path $serverPath -ChildPath ".env"
$redisPassword = ""
if (Test-Path $envFilePath) {
$envContent = Get-Content $envFilePath
$passwordLine = $envContent | Select-String -Pattern "^\s*REDIS_PASSWORD\s*=\s*(.+)"
if ($passwordLine) {
$redisPassword = $passwordLine.Matches[0].Groups[1].Value.Trim()
}
}
if (-not $redisPassword) {
throw "Could not find REDIS_PASSWORD in the src/server/.env file."
}
# Helper function to start a process in a new terminal window
function Start-NewTerminal {
param(
[string]$WindowTitle,
[string]$Command,
[string]$WorkDir = $projectRoot,
[switch]$NoExit = $true
)
# Using -NoExit keeps the window open to see output/errors
$psCommand = "Set-Location -Path '$WorkDir'; `$Host.UI.RawUI.WindowTitle = '$WindowTitle'; $Command"
$startArgs = @{
FilePath = "powershell.exe"
WorkingDirectory = $WorkDir
ArgumentList = "-NoExit", "-Command", $psCommand
}
if (-not $NoExit) {
# For fire-and-forget commands
$startArgs.ArgumentList = "-Command", $psCommand
}
Start-Process @startArgs
}
# --- 1. Start Databases & Core Infrastructure ---
Write-Host "`n--- 1. Starting Databases & Core Infrastructure ---" -ForegroundColor Cyan
# Start MongoDB Service (requires admin)
Write-Host "π Launching MongoDB Service (requires admin)..." -ForegroundColor Yellow
Start-Process powershell.exe -Verb RunAs -ArgumentList "Start-Service -Name 'MongoDB' -ErrorAction SilentlyContinue; if (`$?) { Write-Host 'MongoDB service started successfully.' -ForegroundColor Green } else { Write-Host 'MongoDB service was already running or failed to start.' -ForegroundColor Yellow }; Read-Host 'Press Enter to close this admin window.'"
Start-Sleep -Seconds 3
# Start Redis Server (for Celery)
Write-Host "π Launching Redis Server (in WSL)..." -ForegroundColor Yellow
$redisStartCommand = "wsl -d $wslDistroName -e redis-server --bind 0.0.0.0 --requirepass `"$redisPassword`""
Start-NewTerminal -WindowTitle "SERVICE - Redis" -Command $redisStartCommand
Start-Sleep -Seconds 2
# --- 2. Start MCP Servers ---
Write-Host "`n--- 2. Starting All MCP Servers ---" -ForegroundColor Cyan
$mcpServers = Get-ChildItem -Path $mcpHubPath -Directory | Select-Object -ExpandProperty Name
if ($mcpServers.Count -eq 0) { throw "No MCP server directories found in '$mcpHubPath'." }
Write-Host "Found the following MCP servers to start:" -ForegroundColor Green
$mcpServers | ForEach-Object { Write-Host " - $_" }
Write-Host ""
foreach ($serverName in $mcpServers) {
$windowTitle = "MCP - $($serverName.ToUpper())"
$pythonModule = "mcp_hub.$serverName.main"
$commandToRun = "& '$venvActivatePath'; python -m '$pythonModule'"
Write-Host "π Launching $windowTitle..." -ForegroundColor Yellow
Start-NewTerminal -WindowTitle $windowTitle -Command $commandToRun -WorkDir $serverPath
Start-Sleep -Milliseconds 500
}
# --- 3. Resetting Queues & State (for clean development starts) ---
Write-Host "`n--- 3. Resetting Queues & State ---" -ForegroundColor Cyan
# Clear Redis (Celery queue) - This is fast, runs in the current window.
Write-Host "π Flushing Redis database (Celery Queue)..." -ForegroundColor Yellow
$redisFlushCommand = "wsl -d $wslDistroName -e redis-cli FLUSHALL"
Start-NewTerminal -WindowTitle "RESET - Redis Flush" -Command $redisFlushCommand -WorkDir $serverPath -NoExit:$false
# --- 4. Start Backend Workers ---
Write-Host "`n--- 4. Starting Backend Workers ---" -ForegroundColor Cyan
$workerServices = @(
@{ Name = "Celery Worker"; Command = "& '$venvActivatePath'; celery -A workers.celery_app worker --loglevel=info --pool=solo" },
@{ Name = "Celery Beat Scheduler"; Command = "& '$venvActivatePath'; celery -A workers.celery_app beat --loglevel=info" }
)
foreach ($service in $workerServices) {
$windowTitle = "WORKER - $($service.Name)"
Write-Host "π Launching $windowTitle..." -ForegroundColor Yellow
Start-NewTerminal -WindowTitle $windowTitle -Command $service.Command -WorkDir $serverPath
Start-Sleep -Milliseconds 500
}
# --- 5. Start Main API Server and Frontend Client ---
Write-Host "`n--- 5. Starting Main API and Client ---" -ForegroundColor Cyan
# Start Main FastAPI Server
Write-Host "π Launching Main API Server..." -ForegroundColor Yellow
$mainApiCommand = "& '$venvActivatePath'; python -m main.app"
Start-NewTerminal -WindowTitle "API - Main Server" -Command $mainApiCommand -WorkDir $serverPath
Start-Sleep -Seconds 3
# Start Next.js Client
Write-Host "π Launching Next.js Client..." -ForegroundColor Yellow
Start-NewTerminal -WindowTitle "CLIENT - Next.js" -Command "npm run dev" -WorkDir $clientPath
Write-Host "`nβ
All services have been launched successfully in new terminals." -ForegroundColor Green
}
catch {
Write-Error "An error occurred during startup: $_"
Read-Host "Press Enter to exit..."
}