I have a docker container running CentOS 7.
It is running a script wrapper_script.sh
as PID 1.
It also has below in the docker compose.
CMD ["/wrapper_script.sh"]
I tried docker stop
on the container. It is not executing the cleanup function. It is directly stopping the container.
Tried docker kill --signal="SIGTERM" <containername>
. It is also not executing the cleanup function. Also note, this is not killing/stopping the container itself.
Please help on fixing this. Any suggestion is appreciated.
wrapper_script.sh
is as below:
#!/usr/bin/env bash
cleanup() {
echo "Cleaning up..."
/wrapper-script-stop.sh
}
trap 'cleanup' SIGTERM EXIT
/run-something.sh
while sleep 60; do
ps aux |grep run-something.sh |grep -q -v grep
PROCESS_1_STATUS=$?
if [ $PROCESS_1_STATUS -ne 0 ]; then
echo "One of the processes has already exited."
exit 1
fi
done