Last active
February 26, 2020 10:17
-
-
Save Koriit/130617ed45b8a61b45f6f8471ecae1a0 to your computer and use it in GitHub Desktop.
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
#!/bin/sh | |
# Close container on SIGTERM | |
# It's a bit hacky but here is the thing | |
onSIGTERM(){ | |
# Now pass SIGTERM to application | |
kill -15 $applicationPid | |
# And wait for it to gracefully close | |
wait $applicationPid | |
# Now we can close this script and also the running container since this script would be run with PID 1 | |
exit 0 | |
} | |
trap "onSIGTERM" 15 | |
# Waiting on some host | |
WAIT_HOST=localhost | |
WAIT_PORT=8080 | |
while ! nc --send-only --recv-only $WAIT_HOST $WAIT_PORT >> /dev/null 2>&1; do | |
sleep 1 | |
done | |
# Starting application | |
./appplication & | |
applicationPid=$! | |
# We cannot close this script because this would stop the container | |
wait $applicationPid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment