Upgpkg: 1.9-5

Fix issues with how the idle_server is handled.
(Tested and at least works for me...)
This commit is contained in:
Gordian Edenhofer 2016-03-05 12:18:45 +01:00
parent 495689d898
commit 904e9c8273
3 changed files with 28 additions and 23 deletions

View File

@ -1,7 +1,7 @@
pkgbase = minecraft-server pkgbase = minecraft-server
pkgdesc = Minecraft server unit files, script, and jar pkgdesc = Minecraft server unit files, script, and jar
pkgver = 1.9 pkgver = 1.9
pkgrel = 4 pkgrel = 5
url = http://minecraft.net/ url = http://minecraft.net/
install = minecraft-server.install install = minecraft-server.install
arch = any arch = any
@ -28,6 +28,6 @@ pkgbase = minecraft-server
md5sums = fef6fadd0739ae03ff71ba61025be207 md5sums = fef6fadd0739ae03ff71ba61025be207
md5sums = afb84ad0316af0aca421b36eaa2bbd90 md5sums = afb84ad0316af0aca421b36eaa2bbd90
md5sums = 54438e0c47cc5083e0a4376688b46092 md5sums = 54438e0c47cc5083e0a4376688b46092
md5sums = f0916bc22215b5dfabb5566e4850bcb8 md5sums = e2fae644262285b633db924b0a384613
pkgname = minecraft-server pkgname = minecraft-server

View File

@ -4,7 +4,7 @@
pkgname=minecraft-server pkgname=minecraft-server
pkgver=1.9 pkgver=1.9
pkgrel=4 pkgrel=5
pkgdesc="Minecraft server unit files, script, and jar" pkgdesc="Minecraft server unit files, script, and jar"
arch=('any') arch=('any')
url="http://minecraft.net/" url="http://minecraft.net/"
@ -28,7 +28,7 @@ md5sums=('ff68834eee875bcf367422c67673207c'
'fef6fadd0739ae03ff71ba61025be207' 'fef6fadd0739ae03ff71ba61025be207'
'afb84ad0316af0aca421b36eaa2bbd90' 'afb84ad0316af0aca421b36eaa2bbd90'
'54438e0c47cc5083e0a4376688b46092' '54438e0c47cc5083e0a4376688b46092'
'f0916bc22215b5dfabb5566e4850bcb8') 'e2fae644262285b633db924b0a384613')
_game="minecraft" _game="minecraft"
_server_root="/srv/minecraft" _server_root="/srv/minecraft"

View File

@ -6,7 +6,7 @@ declare -r game="minecraft"
# General rule for the variable-naming-schema: # General rule for the variable-naming-schema:
# Variables in capital letters may be passed through the command line others not. # Variables in capital letters may be passed through the command line others not.
# Avoid altering any of those later in the code since they may be readonly. # Avoid altering any of those later in the code since they may be readonly (IDLE_SERVER is an exception!)
# You may use this script for any game server of your choice, just alter the config file # You may use this script for any game server of your choice, just alter the config file
[[ ! -z "${SERVER_ROOT}" ]] && declare -r SERVER_ROOT=${SERVER_ROOT} || SERVER_ROOT="/srv/${game}" [[ ! -z "${SERVER_ROOT}" ]] && declare -r SERVER_ROOT=${SERVER_ROOT} || SERVER_ROOT="/srv/${game}"
@ -25,7 +25,7 @@ declare -r game="minecraft"
[[ ! -z "${JAVA_PARMS}" ]] && declare -r JAVA_PARMS=${JAVA_PARMS} || JAVA_PARMS="-Xmx${MAXHEAP} -Xms${MINHEAP} -XX:ParallelGCThreads=${THREADS}" [[ ! -z "${JAVA_PARMS}" ]] && declare -r JAVA_PARMS=${JAVA_PARMS} || JAVA_PARMS="-Xmx${MAXHEAP} -Xms${MINHEAP} -XX:ParallelGCThreads=${THREADS}"
# System parameters for the control script # System parameters for the control script
[[ ! -z "${IDLE_SERVER}" ]] && declare -r IDLE_SERVER=${IDLE_SERVER} || IDLE_SERVER="false" [[ ! -z "${IDLE_SERVER}" ]] && tmp_IDLE_SERVER=${IDLE_SERVER} || IDLE_SERVER="false"
[[ ! -z "${IDLE_SESSION_NAME}" ]] && declare -r IDLE_SESSION_NAME=${IDLE_SESSION_NAME} || IDLE_SESSION_NAME="idle_server" [[ ! -z "${IDLE_SESSION_NAME}" ]] && declare -r IDLE_SESSION_NAME=${IDLE_SESSION_NAME} || IDLE_SESSION_NAME="idle_server"
[[ ! -z "${GAME_PORT}" ]] && declare -r GAME_PORT=${GAME_PORT} || GAME_PORT="25565" [[ ! -z "${GAME_PORT}" ]] && declare -r GAME_PORT=${GAME_PORT} || GAME_PORT="25565"
[[ ! -z "${CHECK_PLAYER_TIME}" ]] && declare -r CHECK_PLAYER_TIME=${CHECK_PLAYER_TIME} || CHECK_PLAYER_TIME="30" [[ ! -z "${CHECK_PLAYER_TIME}" ]] && declare -r CHECK_PLAYER_TIME=${CHECK_PLAYER_TIME} || CHECK_PLAYER_TIME="30"
@ -34,6 +34,9 @@ declare -r game="minecraft"
# Variables passed over the command line will always override the one from a config file # Variables passed over the command line will always override the one from a config file
source /etc/conf.d/${game} || echo "Could not source /etc/conf.d/${game}" source /etc/conf.d/${game} || echo "Could not source /etc/conf.d/${game}"
# Preserve the content of IDLE_SERVER without making it readonly
[[ ! -z ${tmp_IDLE_SERVER} ]] && IDLE_SERVER=${tmp_IDLE_SERVER}
# Check whether sudo is needed at all # Check whether sudo is needed at all
if [[ $(whoami) == ${GAME_USER} ]]; then if [[ $(whoami) == ${GAME_USER} ]]; then
SUDO_CMD="" SUDO_CMD=""
@ -74,21 +77,31 @@ idle_server_daemon() {
no_player=0 no_player=0
while true; do while true; do
# Retry in ${CHECK_PLAYER_TIME} seconds
sleep ${CHECK_PLAYER_TIME}
screen -S "${SESSION_NAME}" -Q select . > /dev/null screen -S "${SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
# Game server is up and running # Game server is up and running
screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`" screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`"
# The "player_delimiter" in awk print needs to be 6 for the spigot server # The "player_delimiter" in awk print needs to be 6 for the spigot server
# since the according information is contained in the 6th not in th 4th column # since the according information is contained in the 6th not in th 4th column
if [[ -z $(tail -n 1 "${LOGPATH}/latest.log" | awk '{ print $4 }') ]]; then if [[ $? -eq 0 && -z $(tail -n 1 "${LOGPATH}/latest.log" | awk '{ print $4 }') ]]; then
# No player was seen on the server through list # No player was seen on the server through list
no_player=$((no_player + CHECK_PLAYER_TIME)) no_player=$((no_player + CHECK_PLAYER_TIME))
# Stop the game server if no player was active for at least ${IDLE_IF_TIME} # Stop the game server if no player was active for at least ${IDLE_IF_TIME}
[[ "${no_player}" -ge "${IDLE_IF_TIME}" ]] && IDLE_SERVER="false" ${myname} stop 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
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 else
no_player=0 no_player=0
# Retry in ${CHECK_PLAYER_TIME} seconds
sleep ${CHECK_PLAYER_TIME}
fi fi
else else
# Game server is down, listen on port ${GAME_PORT} for incoming connections # Game server is down, listen on port ${GAME_PORT} for incoming connections
@ -96,7 +109,6 @@ idle_server_daemon() {
${NETCAT_CMD} -v -l -p ${GAME_PORT} ${NETCAT_CMD} -v -l -p ${GAME_PORT}
echo "Netcat caught an connection. The server is coming up again...." echo "Netcat caught an connection. The server is coming up again...."
IDLE_SERVER="false" ${myname} start IDLE_SERVER="false" ${myname} start
sleep ${CHECK_PLAYER_TIME}
fi fi
done done
} }
@ -123,21 +135,14 @@ server_start() {
# Start the idle server daemon # Start the idle server daemon
${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
echo "An idles server screen session called ${IDLE_SESSION_NAME} is already running. Please close it first." ${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"
else else
echo -en "Starting idle server daeomon... " echo -en "Starting idle server daeomon... "
${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon" ${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon"
echo -e "\e[39;1m done\e[0m" echo -e "\e[39;1m done\e[0m"
fi fi
else
# Though IDLE_SERVER is not set to true it could still be running and just have not noticed that the
# server was started, e.g. by manually triggering server_start again. Reset the idle daemon in this case.
${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.1
${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon"
fi
fi fi
} }
@ -216,7 +221,7 @@ server_restart() {
${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
server_stop server_stop
sleep 0.1 sleep 0.5
server_start server_start
else else
server_start server_start
@ -337,7 +342,7 @@ server_command() {
${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then
sleep 0.1s & sleep 0.2s &
sleep_pid=$! sleep_pid=$!
game_command "$@" & game_command "$@" &
tail -f --pid=${sleep_pid} -n 0 "${LOGPATH}/latest.log" tail -f --pid=${sleep_pid} -n 0 "${LOGPATH}/latest.log"