Add CTRL+C catching

This commit is contained in:
JeremyStar™ 2024-01-26 15:38:08 +01:00
parent 30dd6d21ee
commit c18ec3d06f
2 changed files with 11 additions and 10 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
server server
config.env

View file

@ -54,20 +54,20 @@ function accept_eula() {
echo "eula=true" > /data/eula.txt echo "eula=true" > /data/eula.txt
} }
function kill_server() {
kill -SIGINT "$CHILDPID"
}
function run() { function run() {
echo ":: Starting server" echo ":: Starting server"
cd /data cd /data
# We want to use ${ARGS} without using parenthesis # We want to use ${ARGS} without using parenthesis
# shellcheck disable=SC2086 # shellcheck disable=SC2086
"/usr/lib/jvm/java-${MCSD_JAVA_VERSION}-openjdk/bin/java" -jar "/data/server.jar" ${ARGS} "/usr/lib/jvm/java-${MCSD_JAVA_VERSION}-openjdk/bin/java" -jar "/data/server.jar" ${ARGS} &
export "exitcode=${?}" export "CHILDPID=${!}"
# yes it is assigned you idiot trap kill_server SIGTERM
# shellcheck disable=SC2154 trap kill_server SIGINT
if [ "${exitcode}" == "0" ]; then wait
echo ":: The server was shut down successfully"
else
echo ":: The server was forcefully shut down (code ${exitcode})"
fi
case "${MCSD_AUTO_RESTART}" in case "${MCSD_AUTO_RESTART}" in
"true") "true")
echo ":: Restarting server after shutdown" echo ":: Restarting server after shutdown"
@ -88,7 +88,7 @@ function main() {
initialize initialize
check check
accept_eula 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 run
} }