Skip to content

Commit

Permalink
MariaDB/CouchDB: Kill all leftover children when invoking `docker sto…
Browse files Browse the repository at this point in the history
…p` (#1491)

When `docker stop` invokes the SIGTERM signal, services will be stopped
and leftover children from the main run.sh process will be killed with rkill.
Dependency: pslist (part of the docker image).
  • Loading branch information
khurtado authored May 27, 2024
1 parent 8bcd434 commit 7015550
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docker/pypi/wmagent-couchdb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ RUN apt-get update && apt-get install -y vim less sudo wget unzip python pip
# # Install some debugging tools
RUN apt-get install -y hostname net-tools iputils-ping procps emacs-nox tcpdump && apt-get clean

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

RUN pip install CMSCouchapp

ENV COUCH_PORT=5984
Expand Down
24 changes: 23 additions & 1 deletion docker/pypi/wmagent-couchdb/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 CouchDB"
manage stop

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

echo -e "\nKilling children proceses 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 for CouchDB
thisUser=$(id -un)
thisGroup=$(id -gn)
Expand Down Expand Up @@ -30,7 +51,8 @@ manage start | tee -a $COUCH_LOG_DIR/run.log
manage pushapps | tee -a $COUCH_LOG_DIR/run.log

echo "start sleeping....zzz"
sleep infinity
sleep infinity &
wait

# # start the service
# manage start
2 changes: 1 addition & 1 deletion docker/pypi/wmagent-mariadb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ENV MDB_TAG=$MDB_TAG
RUN echo MDB_TAG=$MDB_TAG

RUN apt-get update && apt-get install -y vim less sudo wget unzip python3 pip \
hostname net-tools iputils-ping procps emacs-nox tcpdump && apt-get clean
hostname net-tools iputils-ping procps emacs-nox tcpdump pslist && apt-get clean

# ENV MDB_PORT=
ENV MDB_ROOT_DIR=/data
Expand Down
24 changes: 23 additions & 1 deletion docker/pypi/wmagent-mariadb/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 MariaDB"
manage stop-mariadb

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

echo -e "\nKilling children proceses 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 for MariaDB
thisUser=$(id -un)
thisGroup=$(id -gn)
Expand Down Expand Up @@ -28,4 +49,5 @@ manage init-mariadb 2>&1 | tee -a $MDB_LOG_DIR/run.log
manage start-mariadb 2>&1 | tee -a $MDB_LOG_DIR/run.log

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

0 comments on commit 7015550

Please sign in to comment.