Browse Source

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.
pull/22/head
Daniel Gibbs 2 years ago
parent
commit
fac6007944
  1. 14
      entrypoint-user.sh
  2. 3
      entrypoint.sh

14
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

3
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"

Loading…
Cancel
Save