From fac6007944cd398632610638c990930d33860146 Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 4 Jul 2023 10:59:54 +0100 Subject: [PATCH] refactor: improve exit handling and code organization - Refactored the exit_handler function to handle shutdown commands more efficiently. - Added an exit trap to ensure proper execution of the exit_handler function on SIGQUIT, SIGINT, and SIGTERM signals. - Improved code organization by moving the "Loading exit handler" message to a separate line for clarity. - Updated the entrypoint.sh file with similar changes for consistency. --- entrypoint-user.sh | 14 ++++++++++++++ entrypoint.sh | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/entrypoint-user.sh b/entrypoint-user.sh index c9d3245..eebaaf8 100755 --- a/entrypoint-user.sh +++ b/entrypoint-user.sh @@ -1,4 +1,17 @@ #!/bin/bash + +exit_handler() { + # Execute the shutdown commands + echo -e "stopping ${GAMESERVER}" + exec gosu "${USERNAME}" ./"${GAMESERVER}" stop + exitcode=$? + exit ${exitcode} +} + +# Exit trap +echo -e "Loading exit handler" +trap exit_handler SIGQUIT SIGINT SIGTERM + # Setup game server if [ ! -f "${GAMESERVER}" ]; then echo -e "" @@ -24,6 +37,7 @@ if [ -z "$(ls -A -- "/data/serverfiles" 2> /dev/null)" ]; then ./"${GAMESERVER}" auto-install install=1 else + echo -e "" # Sponsor to display LinuxGSM logo ./"${GAMESERVER}" sponsor fi diff --git a/entrypoint.sh b/entrypoint.sh index 856ef87..3e3091f 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,7 +3,7 @@ exit_handler() { # Execute the shutdown commands echo -e "stopping ${GAMESERVER}" - exec gosu "${USERNAME}" ./${GAMESERVER} stop + exec gosu "${USERNAME}" ./"${GAMESERVER}" stop exitcode=$? exit ${exitcode} } @@ -11,6 +11,7 @@ exit_handler() { # Exit trap echo -e "Loading exit handler" trap exit_handler SIGQUIT SIGINT SIGTERM + DISTRO="$(grep "PRETTY_NAME" /etc/os-release | awk -F = '{gsub(/"/,"",$2);print $2}')" echo -e "" echo -e "Welcome to the LinuxGSM"