Docker Catch Sigterm
Sometimes I like to stash commands that I use regularly. Below is a snippet of code that I find helpful from time to time. Here is a good script for catching sigterms inside of a docker container.
#!/bin/bash
term_handler() {
${TOMCAT_DIR}/bin/shutdown.sh
exit 143; # 128 + 15 -- SIGTERM
}
# setup handlers
# on callback, kill the last background process, which is tail -f /dev/null and execute the specified handler
trap 'kill ${!}; term_handler' SIGTERM
# run application
${TOMCAT_DIR}/bin/startup.sh
ln -sf /dev/stdout ${TOMCAT_DIR}/catalina.out
# wait forever
while true
do
tail -f /dev/null & wait ${!}
done
Leave a comment