Skip to content

Instantly share code, notes, and snippets.

@Koriit
Last active February 26, 2020 10:17
Show Gist options
  • Save Koriit/130617ed45b8a61b45f6f8471ecae1a0 to your computer and use it in GitHub Desktop.
Save Koriit/130617ed45b8a61b45f6f8471ecae1a0 to your computer and use it in GitHub Desktop.
#!/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