Repository navigation
Expand file tree
/
Copy pathstop-all-labs.ps1
More file actions
68 lines (57 loc) · 2.42 KB
/
Copy pathstop-all-labs.ps1
File metadata and controls
68 lines (57 loc) · 2.42 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
# Script to stop all docker-compose files from specified folders
# Usage: .\stop-all-labs.ps1
$ErrorActionPreference = "Continue"
# Define folders to search for docker-compose files
$folders = @(
"Lilia_Lagunova",
"Nikita_Sharonov",
"Sofya_Kototova",
"SQL-IntelliJ_Lab8"
)
$composeFiles = @()
Write-Host "Searching for docker-compose.yml files..." -ForegroundColor Cyan
# Find all docker-compose.yml files in specified folders
foreach ($folder in $folders) {
if (Test-Path $folder) {
$files = Get-ChildItem -Path $folder -Filter "docker-compose.yml" -Recurse -File
foreach ($file in $files) {
# Skip Nikita_Sharonov/Lab6
if ($file.FullName -notlike "*Nikita_Sharonov\Lab6*" -and $file.FullName -notlike "*Nikita_Sharonov/Lab6*") {
$composeFiles += $file.FullName
Write-Host " Found: $($file.FullName)" -ForegroundColor Green
} else {
Write-Host " Skipping: $($file.FullName)" -ForegroundColor Yellow
}
}
} else {
Write-Host " Folder '$folder' not found, skipping..." -ForegroundColor Yellow
}
}
if ($composeFiles.Count -eq 0) {
Write-Host "No docker-compose.yml files found!" -ForegroundColor Red
exit 1
}
Write-Host "`nFound $($composeFiles.Count) file(s)" -ForegroundColor Cyan
Write-Host "Stopping all docker-compose files...`n" -ForegroundColor Cyan
# Stop each docker-compose file from its directory
foreach ($composeFile in $composeFiles) {
$directory = Split-Path -Parent $composeFile
$fileName = Split-Path -Leaf $composeFile
Write-Host "========================================" -ForegroundColor Magenta
Write-Host "Stopping: $fileName" -ForegroundColor Magenta
Write-Host "Directory: $directory" -ForegroundColor Magenta
Write-Host "========================================" -ForegroundColor Magenta
$originalLocation = Get-Location
Set-Location $directory
docker-compose down
if ($LASTEXITCODE -eq 0) {
Write-Host "Successfully stopped: $fileName" -ForegroundColor Green
} else {
Write-Host "Error stopping: $fileName" -ForegroundColor Red
}
Set-Location $originalLocation
Write-Host ""
}
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "All docker-compose files stopped!" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan