Created
September 11, 2015 13:30
-
-
Save iocanel/0a33dc5c89e06e0dcec9 to your computer and use it in GitHub Desktop.
Signal trapping in Docker tests
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
#!/bin/bash | |
function cleanup { | |
echo "Cleaning Up!" | |
echo "Container $HOSTNAME exited" > /path/to/volume | |
} | |
echo "My pid is $$" | |
trap 'kill ${!}; cleanup' SIGTERM | |
trap 'kill ${!}; cleanup' SIGKILL | |
trap 'kill ${!}; cleanup' SIGINT | |
//hide dind stuff so Jimmi won't find out. | |
sleep infinity |
This works for me:
#!/bin/bash
trap 'echo TRAPed signal' TERM INT
pid=
function cleanup {
echo "Cleaning Up!"
kill $pid TERM
echo "Container $HOSTNAME exited"
}
echo "My pid is $$"
sleep 10000000 &
pid=$!
wait
yeah, you're the man ;)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works for me with this dockerfile
and this x.sh