diff options
author | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-07 15:58:22 +0000 |
---|---|---|
committer | Christophe Lyon <christophe.lyon@linaro.org> | 2019-03-07 15:58:22 +0000 |
commit | f91cadd371b18475234861422db4ef347f16b2ad (patch) | |
tree | 69f45a05cad4f95ff61ce2fa39e32c0dc2c22a02 /tcwg-cleanup-stale-containers.sh | |
parent | a7205ca33e25f8763fa6ccbc365ba9b370698da3 (diff) |
tcwg-cleanup-stale-containers.sh: Make output easier to understand.
Add a few more messages, to make the Jenkins console easier to understand.
Change-Id: I2bab8aaf5333c4e7f8d8d8681986c961336f1fd6
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-x | tcwg-cleanup-stale-containers.sh | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh index df723dba..d5d999d9 100755 --- a/tcwg-cleanup-stale-containers.sh +++ b/tcwg-cleanup-stale-containers.sh @@ -65,7 +65,11 @@ do_cleanup_containers () local hours="$1" local docker_ps_opts="$2" local action="$3" + local action_msg="$4" + local msg="$5" + local cleanup_containers=true + local dryrun_msg="" local only_jenkins_containers=true if [ "$hours" -eq "0" ]; then @@ -73,8 +77,10 @@ do_cleanup_containers () elif [ "$hours" -lt "0" ]; then hours="$((0-$hours))" cleanup_containers=false + dryrun_msg=" (DRYRUN)" fi + echo "$msg (more than ${hours}h)${dryrun_msg}" echo "Container report before:" $DOCKER ps $docker_ps_opts @@ -109,10 +115,10 @@ do_cleanup_containers () local res local status="0" if [ ${#rm_containers[@]} != 0 ]; then - echo "Removing containers: ${rm_containers[@]}" + echo "Containers to ${action_msg}: ${rm_containers[@]}" if $cleanup_containers; then for container in "${rm_containers[@]}"; do - echo "Removing container $container" + echo "Container to ${action_msg}: $container" $DOCKER $action $container & res=0; wait $! || res=$? if [ $res != 0 ]; then @@ -121,7 +127,7 @@ do_cleanup_containers () fi done else - echo "DRY_RUN: NOT REMOVING CONTAINERS" + echo "DRY_RUN: NOT ACTING ON CONTAINERS" echo "Increasing exit code to indicate stale containers" status="1" fi @@ -129,19 +135,19 @@ do_cleanup_containers () echo "Containers report after:" $DOCKER ps $docker_ps_opts else - echo "Found no container to remove" + echo "Found no container to ${action_msg}" fi exit $status } res="0" -do_cleanup_containers $cleanup_running_hours "" "stop" & +do_cleanup_containers $cleanup_running_hours "" "stop" "stop" "Stopping long-running containers" & wait $! || res=$? status=$res res="0" -do_cleanup_containers $cleanup_stopped_hours "-a" "rm -fv" & +do_cleanup_containers $cleanup_stopped_hours "-a" "rm -fv" "remove" "Removing containers stopped long ago" & wait $! || res=$? status=$(($status|(2*$res))) @@ -215,7 +221,7 @@ if [ "$cleanup_ssh_agent_hours" -gt "0" ]; then status=$(($status|16)) ;; 1) - echo "WARNING: could not kill stale ssh-agent processes" + echo "WARNING: could not kill stale ssh-agent processes or there was no stale ssh-agent older than ${cleanup_ssh_agent_hours}h" ;; esac fi |