# Скрипт запуска BGP Server (FRR) param( [string]$ContainerName = "bgp-server", [string]$DataPath = "./data", [string]$LogsPath = "./logs", [switch]$Build, [switch]$Force ) Write-Host "=== BGP Server (FRR) Startup Script ===" -ForegroundColor Green # Проверка существования контейнера $containerExists = docker ps -a --filter "name=$ContainerName" --format "table {{.Names}}" | Select-String $ContainerName if ($containerExists) { Write-Host "Found existing container: $ContainerName" -ForegroundColor Yellow if (-not $Force) { $response = Read-Host "Do you want to stop and remove the existing container? (y/N)" if ($response -ne "y" -and $response -ne "Y") { Write-Host "Operation cancelled." -ForegroundColor Red exit 0 } } # Остановка и удаление старого контейнера Write-Host "Stopping container..." -ForegroundColor Yellow docker stop $ContainerName Write-Host "Removing container..." -ForegroundColor Yellow docker rm $ContainerName } # Создание директорий если не существуют if (-not (Test-Path $DataPath)) { Write-Host "Creating data directory: $DataPath" -ForegroundColor Yellow New-Item -ItemType Directory -Path $DataPath -Force | Out-Null } if (-not (Test-Path $LogsPath)) { Write-Host "Creating logs directory: $LogsPath" -ForegroundColor Yellow New-Item -ItemType Directory -Path $LogsPath -Force | Out-Null } # Создание файла с префиксами если не существует $prefixesFile = Join-Path $DataPath "prefixes.txt" if (-not (Test-Path $prefixesFile)) { Write-Host "Creating default prefixes file..." -ForegroundColor Yellow @" # Default prefixes file # Add your prefixes here, one per line 192.168.100.0/24 10.0.0.0/8 172.16.0.0/12 "@ | Out-File -FilePath $prefixesFile -Encoding UTF8 } # Сборка образа если требуется if ($Build) { Write-Host "Building Docker image..." -ForegroundColor Yellow docker build -t bgp-server-frr . if ($LASTEXITCODE -ne 0) { Write-Host "Failed to build image. Exiting." -ForegroundColor Red exit 1 } } # Запуск контейнера Write-Host "Starting BGP Server container..." -ForegroundColor Yellow $currentPath = Get-Location $dataVolume = "${currentPath}\${DataPath}:/app/data:ro" $logsVolume = "${currentPath}\${LogsPath}:/app/logs" docker run -d ` --name $ContainerName ` --restart unless-stopped ` -p 179:179 ` -v $dataVolume ` -v $logsVolume ` --cap-add NET_ADMIN ` --privileged ` bgp-server-frr if ($LASTEXITCODE -eq 0) { Write-Host "Container started successfully!" -ForegroundColor Green # Ожидание запуска Write-Host "Waiting for container to start..." -ForegroundColor Yellow Start-Sleep -Seconds 10 # Проверка статуса $status = docker ps --filter "name=$ContainerName" --format "table {{.Status}}" Write-Host "Container status: $status" -ForegroundColor Cyan # Проверка FRR статуса Write-Host "Checking FRR status..." -ForegroundColor Cyan docker exec $ContainerName vtysh -c "show version" 2>$null if ($LASTEXITCODE -eq 0) { Write-Host "FRR is running successfully!" -ForegroundColor Green # Показ BGP статуса Write-Host "BGP Summary:" -ForegroundColor Cyan docker exec $ContainerName vtysh -c "show ip bgp summary" 2>$null # Показ логов Write-Host "Recent logs:" -ForegroundColor Cyan docker logs --tail=10 $ContainerName Write-Host "`nBGP Server (FRR) is ready!" -ForegroundColor Green Write-Host "To view logs: docker logs -f $ContainerName" -ForegroundColor Cyan Write-Host "To check BGP status: docker exec $ContainerName vtysh -c 'show ip bgp summary'" -ForegroundColor Cyan Write-Host "To access FRR CLI: docker exec -it $ContainerName vtysh" -ForegroundColor Cyan } else { Write-Host "FRR failed to start properly. Check logs:" -ForegroundColor Red docker logs $ContainerName } } else { Write-Host "Failed to start container. Check the error above." -ForegroundColor Red exit 1 }