From c18ec3d06f1b25de1e0817ef73dcb19a1890b462 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Fri, 26 Jan 2024 15:38:08 +0100 Subject: [PATCH] Add CTRL+C catching --- .gitignore | 1 + entrypoint.sh | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 254defd..d590ab8 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ server +config.env diff --git a/entrypoint.sh b/entrypoint.sh index 71f782e..e7074e0 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -54,20 +54,20 @@ function accept_eula() { echo "eula=true" > /data/eula.txt } +function kill_server() { + kill -SIGINT "$CHILDPID" +} + function run() { echo ":: Starting server" cd /data # We want to use ${ARGS} without using parenthesis # shellcheck disable=SC2086 - "/usr/lib/jvm/java-${MCSD_JAVA_VERSION}-openjdk/bin/java" -jar "/data/server.jar" ${ARGS} - export "exitcode=${?}" - # yes it is assigned you idiot - # shellcheck disable=SC2154 - if [ "${exitcode}" == "0" ]; then - echo ":: The server was shut down successfully" - else - echo ":: The server was forcefully shut down (code ${exitcode})" - fi + "/usr/lib/jvm/java-${MCSD_JAVA_VERSION}-openjdk/bin/java" -jar "/data/server.jar" ${ARGS} & + export "CHILDPID=${!}" + trap kill_server SIGTERM + trap kill_server SIGINT + wait case "${MCSD_AUTO_RESTART}" in "true") echo ":: Restarting server after shutdown" @@ -88,7 +88,7 @@ function main() { initialize check accept_eula - if [ "${MCSD_CLEAN_LOGS}" == "true" ]; then rm -rf "/data/logs"; fi + if [ "${MCSD_CLEAN_LOGS}" == "true" ]; then rm -rf "/data/logs" "/data/crash-reports"; fi run }