Skip to content

Commit fac6007

Browse files
committed
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.
1 parent 667c690 commit fac6007

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

entrypoint-user.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
#!/bin/bash
2+
3+
exit_handler() {
4+
# Execute the shutdown commands
5+
echo -e "stopping ${GAMESERVER}"
6+
exec gosu "${USERNAME}" ./"${GAMESERVER}" stop
7+
exitcode=$?
8+
exit ${exitcode}
9+
}
10+
11+
# Exit trap
12+
echo -e "Loading exit handler"
13+
trap exit_handler SIGQUIT SIGINT SIGTERM
14+
215
# Setup game server
316
if [ ! -f "${GAMESERVER}" ]; then
417
echo -e ""
@@ -24,6 +37,7 @@ if [ -z "$(ls -A -- "/data/serverfiles" 2> /dev/null)" ]; then
2437
./"${GAMESERVER}" auto-install
2538
install=1
2639
else
40+
echo -e ""
2741
# Sponsor to display LinuxGSM logo
2842
./"${GAMESERVER}" sponsor
2943
fi

entrypoint.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
exit_handler() {
44
# Execute the shutdown commands
55
echo -e "stopping ${GAMESERVER}"
6-
exec gosu "${USERNAME}" ./${GAMESERVER} stop
6+
exec gosu "${USERNAME}" ./"${GAMESERVER}" stop
77
exitcode=$?
88
exit ${exitcode}
99
}
1010

1111
# Exit trap
1212
echo -e "Loading exit handler"
1313
trap exit_handler SIGQUIT SIGINT SIGTERM
14+
1415
DISTRO="$(grep "PRETTY_NAME" /etc/os-release | awk -F = '{gsub(/"/,"",$2);print $2}')"
1516
echo -e ""
1617
echo -e "Welcome to the LinuxGSM"

0 commit comments

Comments
 (0)