Created
February 8, 2016 17:41
-
-
Save BiggerNoise/b337535ccbb11c1e3094 to your computer and use it in GitHub Desktop.
Simple Dockerfile and bash scripts for playing around with signals & docker
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM debian:jessie | |
MAINTAINER Koan Health <[email protected]> | |
ADD ./run.sh /usr/bin/ | |
CMD ["run.sh"] | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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