Skip to content

Instantly share code, notes, and snippets.

@BiggerNoise
Created February 8, 2016 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BiggerNoise/b337535ccbb11c1e3094 to your computer and use it in GitHub Desktop.
Save BiggerNoise/b337535ccbb11c1e3094 to your computer and use it in GitHub Desktop.
Simple Dockerfile and bash scripts for playing around with signals & docker
FROM debian:jessie
MAINTAINER Koan Health <development@koanhealth.com>
ADD ./run.sh /usr/bin/
CMD ["run.sh"]
#!/usr/bin/env bash
function graceful_exit {
echo 'Got QUIT, I will actually exit in 5 seconds'
sleep 5
exit
}
# trap TERM and change to QUIT
trap "echo 'Got INT, <har har har>'" INT
trap "echo 'Got TERM, <har har har>'" TERM
trap graceful_exit QUIT
echo "Traps set, waiting for wabbits..."
while true
do
echo 'I laugh at your other signals, send QUIT to Stop'
sleep 2
done
# Laugh at my signal
docker kill --signal=INT $(docker ps | grep run\.sh | awk '{print $1}')
# send the quit signal and wait for the container to exit
docker kill -s QUIT $(docker ps | grep run\.sh | awk '{print $1}') && docker wait $(docker ps | grep run\.sh | awk '{print $1}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment