Docker Catch Sigterm1

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

Comments

Leave a comment

  • <a rel="nofollow noopener" href="https://blog.jumpandread.com/" rel="nofollow">https://blog.jumpandread.com/</a>

    Terrific article! That is the kind of information that aree supposed to be shared around tthe web. Shame oon Google for now not positioning thjis post upper! Come on over annd discuss wigh my sitye . Thank you =) xnxx

Leave a comment

(show email/url &raquo;)