Created
May 5, 2015 08:36
-
-
Save marvell/b87df6598e5f3ac3f4a2 to your computer and use it in GitHub Desktop.
#docker
This file contains 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 | |
set -x | |
pid=0 | |
# SIGUSR1-handler | |
my_handler() { | |
echo "my_handler" | |
} | |
# SIGTERM-handler | |
term_handler() { | |
if [ $pid -ne 0 ]; then | |
kill -SIGTERM "$pid" | |
wait "$pid" | |
fi | |
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 ${!}; my_handler' SIGUSR1 | |
trap 'kill ${!}; term_handler' SIGTERM | |
# run application | |
node program & | |
pid="$!" | |
# wait indefinitely | |
while true | |
do | |
tail -f /dev/null & wait ${!} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment