Skip to content

Instantly share code, notes, and snippets.

@marvell
Created May 5, 2015 08:36
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 marvell/b87df6598e5f3ac3f4a2 to your computer and use it in GitHub Desktop.
Save marvell/b87df6598e5f3ac3f4a2 to your computer and use it in GitHub Desktop.
#docker
#!/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