-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup-workers.sh
More file actions
executable file
·41 lines (35 loc) · 1.15 KB
/
cleanup-workers.sh
File metadata and controls
executable file
·41 lines (35 loc) · 1.15 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
#!/usr/bin/env bash
set -euo pipefail
# cleanup-workers.sh - Remove stopped worker containers
#
# Usage: cleanup-workers.sh [--all]
#
# Without --all: Removes only stopped (exited) worker containers
# With --all: Removes ALL worker containers (including running - use with caution)
REMOVE_ALL=false
if [[ $# -gt 0 && "$1" == "--all" ]]; then
REMOVE_ALL=true
fi
if [[ "$REMOVE_ALL" == "true" ]]; then
echo "WARNING: This will remove ALL worker containers (including running ones)"
read -p "Are you sure? (yes/no): " CONFIRM
if [[ "$CONFIRM" != "yes" ]]; then
echo "Aborted."
exit 0
fi
echo "Removing all worker containers..."
docker ps -a --filter "name=yak-worker-" --format "{{.Names}}" | while read -r container; do
echo " Removing: $container"
docker rm -f "$container"
done
else
echo "Removing stopped worker containers..."
docker ps -a --filter "name=yak-worker-" --filter "status=exited" --format "{{.Names}}" | while read -r container; do
echo " Removing: $container"
docker rm "$container"
done
fi
echo "Cleanup complete."
echo ""
echo "Remaining workers:"
docker ps -a --filter "name=yak-worker-" --format " {{.Names}}\t{{.Status}}"