From 8fcdab7dfdc0a9f17e90b86172939fa510b864fa Mon Sep 17 00:00:00 2001 From: Daniel Gibbs Date: Tue, 4 Jul 2023 14:52:30 +0100 Subject: [PATCH] refactor: improve exit handler and log tailing - Renamed the `exit_handler` function to `exit_handler_user` in `entrypoint-user.sh` - Updated the echo statements in the exit handler to use proper capitalization - Removed unnecessary `exec` command in the exit handler of both scripts - Modified trap signal from `exit_handler` to `exit_handler_user` in `entrypoint-user.sh` - Added background execution for log tailing in both scripts using `tail -F` - Added wait command at the end of each script to ensure completion --- entrypoint-user.sh | 11 ++++++----- entrypoint.sh | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/entrypoint-user.sh b/entrypoint-user.sh index eebaaf8..157e5da 100755 --- a/entrypoint-user.sh +++ b/entrypoint-user.sh @@ -1,16 +1,16 @@ #!/bin/bash -exit_handler() { +exit_handler_user() { # Execute the shutdown commands - echo -e "stopping ${GAMESERVER}" - exec gosu "${USERNAME}" ./"${GAMESERVER}" stop + echo -e "Stopping ${GAMESERVER}" + ./"${GAMESERVER}" stop exitcode=$? exit ${exitcode} } # Exit trap echo -e "Loading exit handler" -trap exit_handler SIGQUIT SIGINT SIGTERM +trap exit_handler_user SIGQUIT SIGINT SIGTERM # Setup game server if [ ! -f "${GAMESERVER}" ]; then @@ -64,4 +64,5 @@ sleep 5 sleep 2 echo -e "Tail log files" echo -e "=================================" -tail -F log/*/*.log +tail -F log/*/*.log & +wait diff --git a/entrypoint.sh b/entrypoint.sh index 3e3091f..967244c 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,7 +2,7 @@ exit_handler() { # Execute the shutdown commands - echo -e "stopping ${GAMESERVER}" + echo -e "Stopping ${GAMESERVER}" exec gosu "${USERNAME}" ./"${GAMESERVER}" stop exitcode=$? exit ${exitcode} @@ -59,4 +59,5 @@ export HOME=/data echo -e "" echo -e "Switch to user ${USERNAME}" echo -e "=================================" -exec gosu "${USERNAME}" /app/entrypoint-user.sh +exec gosu "${USERNAME}" /app/entrypoint-user.sh & +wait