Files
termi-blog/restart-services.ps1

92 lines
2.3 KiB
PowerShell

param(
[switch]$FrontendOnly,
[switch]$BackendOnly,
[switch]$AdminOnly,
[switch]$McpOnly,
[switch]$WithMcp,
[string]$DatabaseUrl = "postgres://postgres:postgres%402025%21@10.0.0.2:5432/termi-api_development",
[string]$McpApiKey = "termi-mcp-local-dev-key",
[string]$BackendApiBase = "http://127.0.0.1:5150/api",
[int]$McpPort = 5151
)
$ErrorActionPreference = "Stop"
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$stopScript = Join-Path $repoRoot "stop-services.ps1"
$devScript = Join-Path $repoRoot "dev.ps1"
$frontendScript = Join-Path $repoRoot "start-frontend.ps1"
$backendScript = Join-Path $repoRoot "start-backend.ps1"
$adminScript = Join-Path $repoRoot "start-admin.ps1"
$mcpScript = Join-Path $repoRoot "start-mcp.ps1"
if (@($FrontendOnly, $BackendOnly, $AdminOnly, $McpOnly).Where({ $_ }).Count -gt 1) {
throw "Use only one of -FrontendOnly, -BackendOnly, -AdminOnly, or -McpOnly."
}
Write-Host "[restart] Stopping target services first..." -ForegroundColor Cyan
if ($FrontendOnly) {
& $stopScript -FrontendOnly
}
elseif ($BackendOnly) {
& $stopScript -BackendOnly
}
elseif ($AdminOnly) {
& $stopScript -AdminOnly
}
elseif ($McpOnly) {
& $stopScript -McpOnly
}
else {
& $stopScript -WithMcp:$WithMcp
}
Start-Sleep -Seconds 1
if ($FrontendOnly) {
Start-Process powershell -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-File", $frontendScript
)
Write-Host "[restart] Frontend window restarted." -ForegroundColor Green
exit 0
}
if ($BackendOnly) {
Start-Process powershell -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-File", $backendScript,
"-DatabaseUrl", $DatabaseUrl
)
Write-Host "[restart] Backend window restarted." -ForegroundColor Green
exit 0
}
if ($AdminOnly) {
Start-Process powershell -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-File", $adminScript
)
Write-Host "[restart] Admin window restarted." -ForegroundColor Green
exit 0
}
if ($McpOnly) {
Start-Process powershell -ArgumentList @(
"-NoExit",
"-ExecutionPolicy", "Bypass",
"-File", $mcpScript,
"-ApiKey", $McpApiKey,
"-BackendApiBase", $BackendApiBase,
"-Port", $McpPort
)
Write-Host "[restart] MCP window restarted." -ForegroundColor Green
exit 0
}
& $devScript -DatabaseUrl $DatabaseUrl -WithMcp:$WithMcp