From 8cba93614494584dae9b0c06ee563dbc6c69c985 Mon Sep 17 00:00:00 2001 From: Gordian Edenhofer Date: Sun, 6 Mar 2016 13:50:10 +0100 Subject: [PATCH] Upgpkg: 1.9-6 On server stop, return to the prompt as soon as the server has completely shut down, not as soon as the shutdown command has been sent. Thereby fixing the restart capability. Introduce sanity check whether the servers is really down in idle_daemon and server_start as well. Signed-off-by: Gordian Edenhofer --- .SRCINFO | 4 ++-- PKGBUILD | 4 ++-- minecraftd.sh | 32 ++++++++++++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/.SRCINFO b/.SRCINFO index 1292327..5b54801 100644 --- a/.SRCINFO +++ b/.SRCINFO @@ -1,7 +1,7 @@ pkgbase = minecraft-server pkgdesc = Minecraft server unit files, script, and jar pkgver = 1.9 - pkgrel = 5 + pkgrel = 6 url = http://minecraft.net/ install = minecraft-server.install arch = any @@ -28,6 +28,6 @@ pkgbase = minecraft-server md5sums = fef6fadd0739ae03ff71ba61025be207 md5sums = afb84ad0316af0aca421b36eaa2bbd90 md5sums = 54438e0c47cc5083e0a4376688b46092 - md5sums = e2fae644262285b633db924b0a384613 + md5sums = 98fe0fdfe4021a522739e3e14601ad9f pkgname = minecraft-server diff --git a/PKGBUILD b/PKGBUILD index 3832b09..b5b55bf 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -4,7 +4,7 @@ pkgname=minecraft-server pkgver=1.9 -pkgrel=5 +pkgrel=6 pkgdesc="Minecraft server unit files, script, and jar" arch=('any') url="http://minecraft.net/" @@ -28,7 +28,7 @@ md5sums=('ff68834eee875bcf367422c67673207c' 'fef6fadd0739ae03ff71ba61025be207' 'afb84ad0316af0aca421b36eaa2bbd90' '54438e0c47cc5083e0a4376688b46092' - 'e2fae644262285b633db924b0a384613') + '98fe0fdfe4021a522739e3e14601ad9f') _game="minecraft" _server_root="/srv/minecraft" diff --git a/minecraftd.sh b/minecraftd.sh index 1dc109d..43e5d40 100755 --- a/minecraftd.sh +++ b/minecraftd.sh @@ -92,15 +92,20 @@ idle_server_daemon() { # Stop the game server if no player was active for at least ${IDLE_IF_TIME} if [[ "${no_player}" -ge "${IDLE_IF_TIME}" ]]; then IDLE_SERVER="false" ${myname} stop - - # Game server is down, listen on port ${GAME_PORT} for incoming connections - sleep 1 + # Wait for game server to go down + for i in {1..90}; do + screen -S "${SESSION_NAME}" -Q select . > /dev/null + [[ $? -eq 1 ]] && break + [[ $i -eq 90 ]] && echo -e "\e[39;1m An error occured while trying to reset the idle_server! \e[0m" + sleep 0.1 + done + # Listen on port ${GAME_PORT} for incoming connections echo "Netcat is listening on port ${GAME_PORT} for incoming connections..." ${NETCAT_CMD} -v -l -p ${GAME_PORT} [[ $? -eq 0 ]] && echo "Netcat caught an connection. The server is coming up again...." IDLE_SERVER="false" ${myname} start fi - else + elif [[ $? -eq 0 ]]; then no_player=0 fi else @@ -136,8 +141,13 @@ server_start() { ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null if [[ $? -eq 0 ]]; then ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -X quit - sleep 0.5 - ${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon" + # Restart as soon as the idle_server_daemon has shut down completely + for i in {1..30}; do + ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null + [[ $? -eq 1 ]] && ${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon" && break + [[ $i -eq 30 ]] && echo -e "\e[39;1m An error occured while trying to reset the idle_server! \e[0m" + sleep 0.1 + done else echo -en "Starting idle server daeomon... " ${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon" @@ -178,7 +188,14 @@ server_stop() { sleep 1 done game_command stop - echo -e "\e[39;1m done\e[0m" + + # Finish as soon as the server has shut down completely + for i in {1..30}; do + ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null + [[ $? -eq 1 ]] && echo -e "\e[39;1m done\e[0m" && break + [[ $i -eq 30 ]] && echo -e "\e[39;1m ERROR\e[0m" + sleep 0.1 + done else echo "The corresponding screen session for ${SESSION_NAME} was already dead." fi @@ -221,7 +238,6 @@ server_restart() { ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null if [[ $? -eq 0 ]]; then server_stop - sleep 0.5 server_start else server_start