Skip to content

Commit

Permalink
WMAgent: When invoking docker stop, kill leftover children (#1488)
Browse files Browse the repository at this point in the history
Trap SIGTERM signal, stop WMAgent services and then kill any leftover children
from the run.sh parent process recursively using rkill (from pslist utility)

Dependency: pslist (from container)
  • Loading branch information
khurtado authored May 24, 2024
1 parent 86492bf commit ca9926d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions docker/pypi/wmagent-base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RUN apt-get install -y libmariadb-dev-compat libmariadb-dev apache2-utils cron m
# Install some debugging tools
RUN apt-get install -y hostname net-tools iputils-ping procps && apt-get clean

# Install recursive ps utility tool
RUN apt-get install -y pslist && apt-get clean

# copy oracle client:
COPY --from=oracle /usr/lib/oracle /usr/lib/oracle
ENV LD_LIBRARY_PATH=/usr/lib/oracle
Expand Down
24 changes: 23 additions & 1 deletion docker/pypi/wmagent/run.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
#!/bin/bash

_service_gracefull_exit() {
ppid=$$
echo "Full list of currently running processes:"
ps auxf

echo -e "\nStopping WMAgent"
manage stop-agent

echo -e "\nList of all child processes of pid $ppid upon agent graceful exit:"
pslist $ppid

echo -e "\nKilling children processes recursively"
rkill -9 $ppid

echo -e "\nFull list of currently running processes after killing children:"
ps auxf
}

# Trap SIGTERM signal (e.g.: when doing docker stop)
trap _service_gracefull_exit SIGTERM

### Basic initialization wrapper for WMAgent to serve as the main entry point for the WMAgent Docker container
wmaUser=$(id -un)
wmaGroup=$(id -gn)
Expand All @@ -20,4 +41,5 @@ echo "Start initialization"
$WMA_ROOT_DIR/init.sh | tee -a $WMA_LOG_DIR/init.log || true

echo "Start sleeping now ...zzz..."
sleep infinity
sleep infinity &
wait

0 comments on commit ca9926d

Please sign in to comment.