Files

66 lines
2.4 KiB
PowerShell

# Скрипт остановки BGP Server (FRR)
param(
[string]$ContainerName = "bgp-server",
[switch]$Force
)
Write-Host "=== BGP Server (FRR) Stop Script ===" -ForegroundColor Green
# Проверка существования контейнера
$containerExists = docker ps -a --filter "name=$ContainerName" --format "table {{.Names}}" | Select-String $ContainerName
if (-not $containerExists) {
Write-Host "Container $ContainerName not found." -ForegroundColor Yellow
exit 0
}
# Проверка статуса контейнера
$containerRunning = docker ps --filter "name=$ContainerName" --format "table {{.Names}}" | Select-String $ContainerName
if ($containerRunning) {
Write-Host "Container $ContainerName is running. Stopping..." -ForegroundColor Yellow
if (-not $Force) {
$response = Read-Host "Do you want to stop the container? (y/N)"
if ($response -ne "y" -and $response -ne "Y") {
Write-Host "Operation cancelled." -ForegroundColor Red
exit 0
}
}
# Graceful shutdown - отзыв префиксов
Write-Host "Withdrawing prefixes..." -ForegroundColor Yellow
docker exec $ContainerName python3 /app/scripts/load_prefixes.py --withdraw 2>$null
# Остановка контейнера
Write-Host "Stopping container..." -ForegroundColor Yellow
docker stop $ContainerName
if ($LASTEXITCODE -eq 0) {
Write-Host "Container stopped successfully!" -ForegroundColor Green
} else {
Write-Host "Failed to stop container." -ForegroundColor Red
exit 1
}
} else {
Write-Host "Container $ContainerName is not running." -ForegroundColor Yellow
}
# Удаление контейнера если требуется
if ($Force) {
Write-Host "Removing container..." -ForegroundColor Yellow
docker rm $ContainerName 2>$null
if ($LASTEXITCODE -eq 0) {
Write-Host "Container removed successfully!" -ForegroundColor Green
} else {
Write-Host "Container was already removed or removal failed." -ForegroundColor Yellow
}
} else {
Write-Host "Container stopped but not removed." -ForegroundColor Cyan
Write-Host "To remove container, run: docker rm $ContainerName" -ForegroundColor Cyan
Write-Host "Or use -Force parameter to stop and remove in one command." -ForegroundColor Cyan
}
Write-Host "BGP Server (FRR) stopped successfully!" -ForegroundColor Green