From b51b52ac0ee054c47e05092a689f62b3ccaba84d Mon Sep 17 00:00:00 2001 From: Manuel Cintron <4176113+mcntrn@users.noreply.github.com> Date: Mon, 17 Feb 2020 11:33:29 -0600 Subject: [PATCH] Fixing and issue where if the pids in the orphan list no longer exist then all systemd child processes would be killed. (#5636) --- .../docker/files/cleanup-docker-orphans.sh | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/roles/container-engine/docker/files/cleanup-docker-orphans.sh b/roles/container-engine/docker/files/cleanup-docker-orphans.sh index 2f12def43..d7a9a8f16 100644 --- a/roles/container-engine/docker/files/cleanup-docker-orphans.sh +++ b/roles/container-engine/docker/files/cleanup-docker-orphans.sh @@ -9,21 +9,16 @@ list_descendants () [[ -n "$children" ]] && echo "$children" } -shim_search="^docker-containerd-shim" +shim_search="^docker-containerd-shim|^containerd-shim" count_shim_processes=$(pgrep -f $shim_search | wc -l) -if [ ${count_shim_processes} -eq 0 ]; then - shim_search="^containerd-shim" - count_shim_processes=$(pgrep -f $shim_search | wc -l) -fi - if [ ${count_shim_processes} -gt 0 ]; then # Find all container pids from shims orphans=$(pgrep -P $(pgrep -d ',' -f $shim_search) |\ # Filter out valid docker pids, leaving the orphans egrep -v $(docker ps -q | xargs docker inspect --format '{{.State.Pid}}' | awk '{printf "%s%s",sep,$1; sep="|"}')) - if [[ -n "$orphans" ]] + if [[ -n "$orphans" && -n "$(ps -o ppid= $orphans)" ]] then # Get shim pids of orphans orphan_shim_pids=$(ps -o pid= $(ps -o ppid= $orphans))