Docker Catch Sigterm

Posted by Tom in ·

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           

Trackbacks

Use the following link to trackback from your own site:

https://tom.hastings.dev/trackbacks?article_id=20

Leave a comment

Leave a comment

(show email/url »)