summarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorBuildTools2016-05-30 16:45:53 -0700
committerBuildTools2016-05-30 16:45:53 -0700
commit646ae190defaf0d3efde3913e8eac32ce156961e (patch)
tree617cf02dabc2824474b6970d1adcc65e266961b5
parentd38a107bd665c844ee332a25b8a8a378b43ae6f5 (diff)
downloadaur-646ae190defaf0d3efde3913e8eac32ce156961e.tar.gz
bug fixes to script
-rw-r--r--.SRCINFO9
-rwxr-xr-xPKGBUILD8
-rwxr-xr-xspigot.sh58
3 files changed, 49 insertions, 26 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 5900e83cb1c..a8bf6443030 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,9 +1,9 @@
# Generated by mksrcinfo v8
-# Fri May 13 02:45:36 UTC 2016
+# Mon May 30 23:43:59 UTC 2016
pkgbase = spigot
pkgdesc = High performance Minecraft server implementation
pkgver = 1.9.4
- pkgrel = 1
+ pkgrel = 2
url = https://www.spigotmc.org/
install = spigot.install
arch = any
@@ -15,6 +15,7 @@ pkgbase = spigot
depends = sudo
depends = fontconfig
depends = bash
+ depends = sed
optdepends = tar: needed in order to create world backups
optdepends = netcat: required in order to suspend an idle server
provides = minecraft-server=1.9.4
@@ -31,12 +32,12 @@ pkgbase = spigot
source = spigot.service
source = spigot.conf
source = spigot.sh
- md5sums = 98ba43d2f5eafb0d883c0dafc00e19e8
+ md5sums = SKIP
md5sums = 7bb2dc610c5f55e133bd41ab608ec7a1
md5sums = 872d2e03799f1f8f0c75acdebce91894
md5sums = 1eb2d5f485cf9eff7a99c826ad56fcf4
md5sums = f04e0bcf8d771b0d1dc0206dc173d77a
- md5sums = 6ee73f849e2caf6d8c89c73a80cc0c33
+ md5sums = 65ca43c8ed21347e6c98a7d0aac480f0
pkgname = spigot
diff --git a/PKGBUILD b/PKGBUILD
index 3fa07a46182..f68a4c279a4 100755
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,12 +1,12 @@
# Maintainer: Gordian Edenhofer <gordian.edenhofer[at]yahoo[dot]de>
pkgname=spigot
pkgver=1.9.4
-pkgrel=1
+pkgrel=2
pkgdesc="High performance Minecraft server implementation"
arch=(any)
url="https://www.spigotmc.org/"
license=("LGPL")
-depends=(java-runtime-headless screen sudo fontconfig bash)
+depends=(java-runtime-headless screen sudo fontconfig bash sed)
optdepends=("tar: needed in order to create world backups"
"netcat: required in order to suspend an idle server")
makedepends=(java-environment git)
@@ -21,12 +21,12 @@ source=("https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/art
"${pkgname}.conf"
"${pkgname}.sh")
noextract=("BuildTools.jar")
-md5sums=('98ba43d2f5eafb0d883c0dafc00e19e8'
+md5sums=('SKIP'
'7bb2dc610c5f55e133bd41ab608ec7a1'
'872d2e03799f1f8f0c75acdebce91894'
'1eb2d5f485cf9eff7a99c826ad56fcf4'
'f04e0bcf8d771b0d1dc0206dc173d77a'
- '6ee73f849e2caf6d8c89c73a80cc0c33')
+ '65ca43c8ed21347e6c98a7d0aac480f0')
_game="spigot"
_server_root="/srv/craftbukkit"
diff --git a/spigot.sh b/spigot.sh
index dc4f0ed8832..9b0efc5468f 100755
--- a/spigot.sh
+++ b/spigot.sh
@@ -65,6 +65,26 @@ game_command() {
${SUDO_CMD} screen -S "${SESSION_NAME}" -X stuff "`printf \"$*\r\"`"
}
+# Check whether there are player on the server through list
+is_player_online() {
+ game_command list
+ sleep 0.6
+ # The list command prints a line containing the usernames after the last occurrence of ": "
+ # and since playernames may not contain this string the clean player-list can be easily retrieved.
+ # Otherwiese check the first digit after the last occurrence of "There are". If it is 0 then there
+ # are no players on the server. Should this test fail as well. Assume that a player is online.
+ if [[ -z $(tail -n 1 "${LOGPATH}/latest.log" | sed -r -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' -e 's/.*\: //' | tr -d '\n') ]]; then
+ # No player is online
+ return 0;
+ elif [[ $(tail -n 10 "${LOGPATH}/latest.log" | grep "There are" | sed -r -e '$!d' -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' -e 's/.*\: //' -e 's/^([^.]+).*$/\1/; s/^[^0-9]*([0-9]+).*$/\1/' | tr -d '\n') -gt 0 ]]; then
+ # No player is online
+ return 0;
+ else
+ # A player is online (or it could not be determined)
+ return 1;
+ fi
+}
+
# Check whether the server is visited by a player otherwise shut it down
idle_server_daemon() {
# This function is run within a screen session of the GAME_USER therefore SUDO_CMD can be omitted
@@ -78,18 +98,20 @@ idle_server_daemon() {
no_player=0
while true; do
+ echo -e "no_player: ${no_player}s\tcheck_player_time: ${CHECK_PLAYER_TIME}s\tidle_if_time: ${IDLE_IF_TIME}s"
# Retry in ${CHECK_PLAYER_TIME} seconds
sleep ${CHECK_PLAYER_TIME}
screen -S "${SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then
# Game server is up and running
- screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`"
- # The list command prints a line containing the usernames after the last occurrence of ": "
- # and since playernames may not contain this string the clean player-list can be easily retrieved.
- if [[ $? -eq 0 && -z $(sleep 0.6; tail -n 1 "${LOGPATH}/latest.log" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | sed 's/.*\: //' | tr -d '\n') ]]; then
+ if [[ "$(screen -S "${SESSION_NAME}" -ls | sed -n 2p | awk '{ print $2 }')" == "(Attached)" ]]; then
+ # An administrator is connected to the console, pause player checking
+ echo "An admin is connected to the console. Pause player checking."
+ # Check for active player
+ elif SUDO_CMD="" is_player_online; then
# 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}
if [[ "${no_player}" -ge "${IDLE_IF_TIME}" ]]; then
IDLE_SERVER="false" ${myname} stop
@@ -100,22 +122,23 @@ idle_server_daemon() {
[[ $i -eq 100 ]] && echo -e "An \e[39;1merror\e[0m occurred while trying to reset the idle_server!"
sleep 0.1
done
- # Reset timer
- no_player=0
+ # Reset timer and give the player 300 seconds to connect after pinging
+ no_player=$(( IDLE_IF_TIME - 300 ))
# Game server is down, listen on port ${GAME_PORT} for incoming connections
- echo "Netcat is listening on port ${GAME_PORT} for incoming connections..."
+ echo -n "Netcat: "
${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
- elif [[ $? -eq 0 ]]; then
+ else
+ # Reset timer since there is an active player on the server
no_player=0
fi
else
- # Reset timer
- no_player=0
+ # Reset timer and give the player 300 seconds to connect after pinging
+ no_player=$(( IDLE_IF_TIME - 300 ))
# Game server is down, listen on port ${GAME_PORT} for incoming connections
- echo "Netcat is listening on port ${GAME_PORT} for incoming connections..."
+ echo -n "Netcat: "
${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
@@ -185,10 +208,9 @@ server_stop() {
${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null
if [[ $? -eq 0 ]]; then
# Game server is up and running, gracefully stop the server when there are still active players
- ${SUDO_CMD} screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`"
- # The list command prints a line containing the usernames after the last occurrence of ": "
- # and since playernames may not contain this string the clean player-list can be easily retrieved.
- if [[ $? -eq 0 && -z $(sleep 0.6; tail -n 1 "${LOGPATH}/latest.log" | sed -r 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g' | sed 's/.*\: //' | tr -d '\n') ]]; then
+
+ # Check for active player
+ if is_player_online; then
# No player was seen on the server through list
echo -en "Server is going down..."
game_command stop
@@ -317,7 +339,7 @@ backup_restore() {
i=1
for f in "${BACKUP_DEST}"/[0-9_.]*; do
echo -e " \e[39;1m$i)\e[0m\t$f"
- i=$((i+1))
+ i=$(( i + 1 ))
done
echo -en "Restore backup number: "
@@ -329,7 +351,7 @@ backup_restore() {
n=1
for f in "${BACKUP_DEST}"/[0-9_.]*; do
[[ ${n} -eq $user_choice ]] && FILE="$f"
- n=$((n+1))
+ n=$(( n + 1 ))
done
if [[ -z $FILE ]]; then
>&2 echo -e "\e[39;1mFailed\e[0m to interpret your input. Please enter the digit of the presented options."