summaryrefslogtreecommitdiff
path: root/tcwg-cleanup-stale-containers.sh
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2018-06-05 09:15:35 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2018-06-05 09:15:35 +0000
commit2e4fdbae2316426664cad36deb296e8386e732d6 (patch)
tree52f12f5abd25a8e30dfebcb73022d53dc853950b /tcwg-cleanup-stale-containers.sh
parent064ebd6fc83c94c8a0cab6b1e1af89706d7fb000 (diff)
tcwg-cleanup-stale-containers.sh: Add cleanup of ssh-agent processes.
Change-Id: Ia50672fbab9ade7922feb12a6199f4ae581c18cd
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-xtcwg-cleanup-stale-containers.sh24
1 files changed, 22 insertions, 2 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh
index 6515e9e0..d757cc5e 100755
--- a/tcwg-cleanup-stale-containers.sh
+++ b/tcwg-cleanup-stale-containers.sh
@@ -10,7 +10,11 @@ Options:
--cleanup-stopped-hours HOURS
Cleanup running/stopped containers that have been created more
than HOURS ago. Setting HOURS to negative values will
- run the cleanup in dry-run mode.
+ run the cleanup in dry-run mode. Value "0" disables the cleanup.
+
+ --cleanup-ssh-agent-hours HOURS
+ Cleanup stale ssh-agent processes that were started more than
+ HOURS ago. Value "0" disables the cleanup.
--cleanup-images true/false
Whether to cleanup untagged images
@@ -18,6 +22,10 @@ Options:
--cleanup-volumes true/false
Whether to cleanup dangling volumes
+ --max-containers N
+ Check that number of containers after cleanups doesn't exceed N.
+ Value "0" disables the check.
+
--verbose true/false
Whether to run in verbose mode
EOF
@@ -26,6 +34,7 @@ EOF
cleanup_running_hours="-10"
cleanup_stopped_hours="-240"
+cleanup_ssh_agent_hours="-48"
cleanup_images=false
cleanup_volumes=false
verbose=false
@@ -35,6 +44,7 @@ while [ $# -gt 0 ]; do
case $1 in
--cleanup-running-hours) cleanup_running_hours="$2"; shift ;;
--cleanup-stopped-hours) cleanup_stopped_hours="$2"; shift ;;
+ --cleanup-ssh-agent-hours) cleanup_ssh_agent_hours="$2"; shift ;;
--cleanup-images) cleanup_images="$2"; shift ;;
--cleanup-volumes) cleanup_volumes="$2"; shift ;;
--max-containers) max_containers="$2"; shift ;;
@@ -58,7 +68,9 @@ do_cleanup_containers ()
local cleanup_containers=true
local only_jenkins_containers=true
- if [ "$hours" -lt "0" ]; then
+ if [ "$hours" -eq "0" ]; then
+ exit 0
+ elif [ "$hours" -lt "0" ]; then
hours="$((0-$hours))"
cleanup_containers=false
fi
@@ -181,6 +193,14 @@ if [ ${#rm_images[@]} != 0 ]; then
fi
fi
+# This is a workaround for https://issues.jenkins-ci.org/browse/JENKINS-49097.
+# Matrix jobs leave stale ssh-agent processes, which accumulate into hundreds.
+# This cleanup has nothing to do with docker containers, but creating
+# a separate script/job for a one-liner doesn't seem to worth it.
+if [ "$cleanup_ssh_agent_hours" -gt "0" ]; then
+ killall --older-than ${cleanup_ssh_agent_hours}h -u $USER ssh-agent
+fi
+
# Check if we have more containers than max_containers
nb_containers=$($DOCKER ps -a | wc -l)