Skip to content

Commit 8fa4800

Browse files
Filter Linux docker container processes from terminationProcess.sh on host node (#4210)
Signed-off-by: Andrew Leonard <anleonar@redhat.com> Signed-off-by: Andrew Leonard <anleonar@redhat.com>
1 parent 2cf9779 commit 8fa4800

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

terminateTestProcesses.sh

+17-5
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,29 @@ else
5353
PSCOMMAND="ps -fu $1"
5454
fi
5555

56-
if $PSCOMMAND | egrep "${match_str}" | egrep -v "${ignore_str}"; then
56+
LINUX_DOCKER_FILTER=""
57+
if [ `uname` = "Linux" ]; then
58+
if egrep "\/docker\/" /proc/1/cgroup >nul; then
59+
echo Running in a Linux docker container
60+
else
61+
echo Running on a Linux host
62+
# Filter any possible docker container processes by cgroup containing "/docker"
63+
PSCOMMAND="ps -o cgroup,pid,state,tname,time,command -u $1"
64+
LINUX_DOCKER_FILTER="| egrep -v '^[^[:space:]]+\/docker'"
65+
fi
66+
fi
67+
68+
if eval "$PSCOMMAND | egrep '${match_str}' | egrep -v '${ignore_str}' ${LINUX_DOCKER_FILTER}"; then
5769
echo Boooo - there are rogue processes kicking about
5870
echo Issuing a kill to all processes shown above
59-
$PSCOMMAND | egrep "${match_str}" | egrep -v "${ignore_str}" | awk '{print $2}' | xargs -n1 kill
71+
eval "$PSCOMMAND | egrep '${match_str}' | egrep -v '${ignore_str}' ${LINUX_DOCKER_FILTER} | awk '{print \$2}' | xargs -n1 kill"
6072
echo Sleeping for 10 seconds...
6173
sleep 10
62-
if $PSCOMMAND | egrep "${match_str}" | egrep -v "${ignore_str}"; then
74+
if eval "$PSCOMMAND | egrep '${match_str}' | egrep -v '${ignore_str}' ${LINUX_DOCKER_FILTER}"; then
6375
echo Still processes left going to remove those with kill -KILL ...
64-
$PSCOMMAND | egrep "${match_str}" | egrep -v "${ignore_str}" | awk '{print $2}' | xargs -n1 kill -KILL
76+
eval "$PSCOMMAND | egrep '${match_str}' | egrep -v '${ignore_str}' ${LINUX_DOCKER_FILTER} | awk '{print \$2}' | xargs -n1 kill -KILL"
6577
echo DONE - One final check ...
66-
if $PSCOMMAND | egrep "${match_str}" | egrep -v "${ignore_str}"; then
78+
if eval "$PSCOMMAND | egrep '${match_str}' | egrep -v '${ignore_str}' ${LINUX_DOCKER_FILTER}"; then
6779
echo "Cleanup failed, processes still remain..."
6880
exit 127
6981
fi

0 commit comments

Comments
 (0)