From 113dd2146aa8fbcb7e835c1fb99430c446924b55 Mon Sep 17 00:00:00 2001 From: Kuldip Madnani Date: Tue, 6 Nov 2018 18:50:19 -0600 Subject: [PATCH] Added some minor changes to the docker orphan clean up process. (#3657) * Added changes to clean up orphan containers and reload docker & kubelet directories. * Added new files for cleaning up orphans and docker & kubelet directories * Added new lines at the end of these files * removed the trailing whitespaces from main.yml and clean-up.yml * Updated as per the review comments * Updated as per the review comments * Removed service_facts and package_facts because they are not supported in ansible 2.4.0 * Corrected yaml syntax errors * Removed the use of json_query filter and utilized selectattr * Removed trailing spaces * Changed the default value of docker_clean_up to false * Added Changes to only include cleanup-docker-orphans.sh * Reverted back changes done inside handler. * Removed trailing spaces and made default value of docker_orphan_clean_up as true * Reverted the default value of docker_orphan_clean_up as false * Made the docker clean up as drop in * Made the docker clean up as drop in * Reverted the value of boolean docker_orphan_clean_up to false * Converted ExecStop to ExecSTartPost. Removed the live restore check from the orphan script --- .../docker/files/cleanup-docker-orphans.sh | 10 +++++----- .../docker/templates/docker-orphan-cleanup.conf.j2 | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/roles/container-engine/docker/files/cleanup-docker-orphans.sh b/roles/container-engine/docker/files/cleanup-docker-orphans.sh index 5db82f88b..28f7205ab 100644 --- a/roles/container-engine/docker/files/cleanup-docker-orphans.sh +++ b/roles/container-engine/docker/files/cleanup-docker-orphans.sh @@ -10,9 +10,9 @@ list_descendants () } count_shim_processes=$(pgrep -f ^docker-containerd-shim | wc -l) -live_restore=$(docker info --format {{.LiveRestoreEnabled}} 2>/dev/null) -if [ ${count_shim_processes} -gt 0 ] && [ -n "${live_restore}" -a "${live_restore}" == "true" ]; then + +if [ ${count_shim_processes} -gt 0 ]; then # Find all container pids from shims orphans=$(pgrep -P $(pgrep -d ',' -f ^docker-containerd-shim) |\ # Filter out valid docker pids, leaving the orphans @@ -28,11 +28,11 @@ if [ ${count_shim_processes} -gt 0 ] && [ -n "${live_restore}" -a "${live_restor # Recursively kill all child PIDs of orphan shims echo -e "Killing orphan container PIDs and descendants: \n$(ps -O ppid= $orphan_container_pids)" - #kill -9 $orphan_container_pids || true + kill -9 $orphan_container_pids || true else echo "No orphaned containers found" fi else - echo "Either live-restore is turned off or the node doesn't have any shim processes." -fi \ No newline at end of file + echo "The node doesn't have any shim processes." +fi diff --git a/roles/container-engine/docker/templates/docker-orphan-cleanup.conf.j2 b/roles/container-engine/docker/templates/docker-orphan-cleanup.conf.j2 index 70754ac57..787a941ed 100644 --- a/roles/container-engine/docker/templates/docker-orphan-cleanup.conf.j2 +++ b/roles/container-engine/docker/templates/docker-orphan-cleanup.conf.j2 @@ -1,2 +1,2 @@ [Service] -ExecStop=-{{ bin_dir }}/cleanup-docker-orphans.sh \ No newline at end of file +ExecStartPost=-{{ bin_dir }}/cleanup-docker-orphans.sh \ No newline at end of file