diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 097b194..8b7984c 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -2,10 +2,22 @@ set -e +handle() { + SIGNAL=$(( $? - 128 )) + echo "Caught signal ${SIGNAL}, stopping gracefully" + kill -s ${SIGNAL} $(pidof node) 2>/dev/null +} + +trap handle INT TERM + if ! which -- "${1}"; then # first arg is not an executable - xvfb-run -a --server-args="-screen 0 1024x768x24" -- node /app/ "$@" - exit $? + xvfb-run -a --server-args="-screen 0 1024x768x24" -- node /app/ "$@" & + # Wait exits immediately on signals which have traps set. Store return value and wait + # again for all jobs to actually complete before continuing. + wait $! || RETVAL=$? + wait + exit ${RETVAL} fi exec "$@"