summaryrefslogtreecommitdiff
path: root/tcwg-cleanup-stale-containers.sh
diff options
context:
space:
mode:
authorChristophe Lyon <christophe.lyon@linaro.org>2018-05-03 14:41:52 +0000
committerChristophe Lyon <christophe.lyon@linaro.org>2018-05-07 21:21:06 +0000
commit80cf879e418ced1dbf3b42496224e6584b09f842 (patch)
tree188fc728bb475cffa711f5a400a862b8edf7a303 /tcwg-cleanup-stale-containers.sh
parent46491cbff365d3e6a05119469be877f1d8b3d417 (diff)
tcwg-cleanup-stale-containers.sh: Check if we have more containers than a threshold.
Implements TCWG-1404. We want to make sure we do not have more containers left than a given threshold, to make sure there is no problem with automatically created containers becoming too numerous and not properly cleaned up. Change-Id: Ia740b58d1b75cdcd1fa134b551613e9b043ada34
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-xtcwg-cleanup-stale-containers.sh10
1 files changed, 10 insertions, 0 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh
index 7849811c..c4220733 100755
--- a/tcwg-cleanup-stale-containers.sh
+++ b/tcwg-cleanup-stale-containers.sh
@@ -29,6 +29,7 @@ cleanup_stopped_hours="-240"
cleanup_images=false
cleanup_volumes=false
verbose=false
+max_containers=0
while [ $# -gt 0 ]; do
case $1 in
@@ -36,6 +37,7 @@ while [ $# -gt 0 ]; do
--cleanup-stopped-hours) cleanup_stopped_hours="$2"; shift ;;
--cleanup-images) cleanup_images="$2"; shift ;;
--cleanup-volumes) cleanup_volumes="$2"; shift ;;
+ --max-containers) max_containers="$2"; shift ;;
--verbose) verbose="$2"; shift ;;
*) echo "ERROR: Wrong option: $1"; usage ;;
esac
@@ -174,4 +176,12 @@ if [ ${#rm_images[@]} != 0 ]; then
fi
fi
+# Check if we have more containers than max_containers
+nb_containers=$($DOCKER ps -a | wc -l)
+
+if [ ${max_containers} -gt 0 -a ${nb_containers} -gt ${max_containers} ]; then
+ echo "ERROR: Too many containers left after cleanup: ${nb_containers} (max: ${max_containers})"
+ status=$(($status|16))
+fi
+
exit $status