Skip to content

Instantly share code, notes, and snippets.

@nik-sta
Last active July 3, 2023 17:16
Show Gist options
  • Select an option

  • Save nik-sta/9f5d35ca7070de522b6128f35d18b60b to your computer and use it in GitHub Desktop.

Select an option

Save nik-sta/9f5d35ca7070de522b6128f35d18b60b to your computer and use it in GitHub Desktop.
Production-ready Entrypoint Bash Script for layered Spring Boot Applications
#!/bin/bash
JAVA_OPTS="${JAVA_OPTS:="-Dfile.encoding=UTF-8 -Duser.timezone=UTC -XX:NativeMemoryTracking=summary -XX:+HeapDumpOnOutOfMemoryError"}"
PORT="${PORT:="8080"}"
term_handler() {
if [ $pid -ne 0 ]; then
kill -SIGTERM "$pid"
wait "$pid"
fi
exit 143 # 128 + 15 -- SIGTERM
}
trap 'kill ${!}; term_handler' SIGTERM
cd /srv/"$APP" || exit
/opt/java/bin/java $JAVA_OPTS org.springframework.boot.loader.JarLauncher --bind 0.0.0.0:$PORT &
pid="$!"
while true; do
# Check if process is still running
kill -0 "$pid" 2>/dev/null
if [ $? -ne 0 ]; then
echo "Process $pid is not running, shutting down the container."
term_handler
fi
sleep 5
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment