Upgpkg: 1.9.2-2
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 through the use of sed. This surpasses the usefulness of the player_delimiter. Increase waiting period between executing the list game-command and scanning the logs from 0.3 seconds to 0.6 seconds. Tweak tail -f command in server_command. Use ${_game} variable aggressively in PKGBUILD.
This commit is contained in:
parent
bba22bf616
commit
349829f1e1
4
.SRCINFO
4
.SRCINFO
|
@ -1,7 +1,7 @@
|
|||
pkgbase = minecraft-server
|
||||
pkgdesc = Minecraft server unit files, script, and jar
|
||||
pkgver = 1.9.2
|
||||
pkgrel = 1
|
||||
pkgrel = 2
|
||||
url = http://minecraft.net/
|
||||
install = minecraft-server.install
|
||||
arch = any
|
||||
|
@ -28,6 +28,6 @@ pkgbase = minecraft-server
|
|||
md5sums = fef6fadd0739ae03ff71ba61025be207
|
||||
md5sums = afb84ad0316af0aca421b36eaa2bbd90
|
||||
md5sums = 00045683c06924d765ac14887218ffcc
|
||||
md5sums = 48cb57c426c7725483cd0c9af24048df
|
||||
md5sums = f130c76d285297071c3e0d2988631dfe
|
||||
|
||||
pkgname = minecraft-server
|
||||
|
|
22
PKGBUILD
22
PKGBUILD
|
@ -4,7 +4,7 @@
|
|||
|
||||
pkgname=minecraft-server
|
||||
pkgver=1.9.2
|
||||
pkgrel=1
|
||||
pkgrel=2
|
||||
pkgdesc="Minecraft server unit files, script, and jar"
|
||||
arch=('any')
|
||||
url="http://minecraft.net/"
|
||||
|
@ -13,9 +13,9 @@ depends=('java-runtime-headless' 'screen' 'sudo' 'bash')
|
|||
optdepends=("tar: needed in order to create world backups"
|
||||
"netcat: required in order to suspend an idle server")
|
||||
conflicts=('minecraft-server-systemd' 'minecraft-canary')
|
||||
options=(!strip)
|
||||
install=${pkgname}.install
|
||||
backup=('etc/conf.d/minecraft')
|
||||
options=(!strip)
|
||||
install="${pkgname}.install"
|
||||
source=("https://s3.amazonaws.com/Minecraft.Download/versions/${pkgver}/minecraft_server.${pkgver}.jar"
|
||||
"minecraftd-backup.service"
|
||||
"minecraftd-backup.timer"
|
||||
|
@ -28,19 +28,19 @@ md5sums=('560d467028f17a70997151ed0053deb6'
|
|||
'fef6fadd0739ae03ff71ba61025be207'
|
||||
'afb84ad0316af0aca421b36eaa2bbd90'
|
||||
'00045683c06924d765ac14887218ffcc'
|
||||
'48cb57c426c7725483cd0c9af24048df')
|
||||
'f130c76d285297071c3e0d2988631dfe')
|
||||
|
||||
_game="minecraft"
|
||||
_server_root="/srv/minecraft"
|
||||
|
||||
package() {
|
||||
install -Dm644 minecraftd.conf "${pkgdir}/etc/conf.d/${_game}"
|
||||
install -Dm755 minecraftd.sh "${pkgdir}/usr/bin/${_game}d"
|
||||
install -Dm644 minecraftd.service "${pkgdir}/usr/lib/systemd/system/${_game}d.service"
|
||||
install -Dm644 minecraftd-backup.service "${pkgdir}/usr/lib/systemd/system/${_game}d-backup.service"
|
||||
install -Dm644 minecraftd-backup.timer "${pkgdir}/usr/lib/systemd/system/${_game}d-backup.timer"
|
||||
install -Dm644 minecraft_server.${pkgver}.jar "${pkgdir}${_server_root}/minecraft_server.${pkgver}.jar"
|
||||
ln -s "minecraft_server.${pkgver}.jar" "${pkgdir}${_server_root}/minecraft_server.jar"
|
||||
install -Dm644 ${_game}d.conf "${pkgdir}/etc/conf.d/${_game}"
|
||||
install -Dm755 ${_game}d.sh "${pkgdir}/usr/bin/${_game}d"
|
||||
install -Dm644 ${_game}d.service "${pkgdir}/usr/lib/systemd/system/${_game}d.service"
|
||||
install -Dm644 ${_game}d-backup.service "${pkgdir}/usr/lib/systemd/system/${_game}d-backup.service"
|
||||
install -Dm644 ${_game}d-backup.timer "${pkgdir}/usr/lib/systemd/system/${_game}d-backup.timer"
|
||||
install -Dm644 ${_game}_server.${pkgver}.jar "${pkgdir}${_server_root}/${_game}_server.${pkgver}.jar"
|
||||
ln -s "${_game}_server.${pkgver}.jar" "${pkgdir}${_server_root}/${_game}_server.jar"
|
||||
|
||||
# Link the log files
|
||||
mkdir -p "${pkgdir}/var/log/"
|
||||
|
|
|
@ -37,11 +37,6 @@ 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}
|
||||
|
||||
# The variable defines the row in which the first player is printed. It is interpreted
|
||||
# by awk and depends on the flavor of the game server.
|
||||
# The stock minecraft server prints the first player in the 4th row, spigot in the 6th.
|
||||
player_delimiter=4
|
||||
|
||||
|
||||
# Check whether sudo is needed at all
|
||||
if [[ $(whoami) == ${GAME_USER} ]]; then
|
||||
|
@ -90,7 +85,9 @@ idle_server_daemon() {
|
|||
if [[ $? -eq 0 ]]; then
|
||||
# Game server is up and running
|
||||
screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`"
|
||||
if [[ $? -eq 0 && -z $(sleep 0.3; tail -n 1 "${LOGPATH}/latest.log" | awk "{ print \$${player_delimiter} }") ]]; then
|
||||
# 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 's/.*\: //' | tr -d '\n') ]]; then
|
||||
# No player was seen on the server through list
|
||||
no_player=$((no_player + CHECK_PLAYER_TIME))
|
||||
# Stop the game server if no player was active for at least ${IDLE_IF_TIME}
|
||||
|
@ -188,7 +185,9 @@ server_stop() {
|
|||
|
||||
# Gracefully stop the server when there are still active players
|
||||
${SUDO_CMD} screen -S "${SESSION_NAME}" -X stuff "`printf \"list\r\"`"
|
||||
if [[ $? -eq 0 && -z $(sleep 0.3; tail -n 1 "${LOGPATH}/latest.log" | awk "{ print \$${player_delimiter} }") ]]; then
|
||||
# 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 's/.*\: //' | tr -d '\n') ]]; then
|
||||
# No player was seen on the server through list
|
||||
echo -en "Server is going down..."
|
||||
game_command stop
|
||||
|
@ -374,10 +373,9 @@ server_command() {
|
|||
|
||||
${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null
|
||||
if [[ $? -eq 0 ]]; then
|
||||
sleep 0.3 &
|
||||
sleep_pid=$!
|
||||
${SUDO_CMD} sleep 0.3 & tail -f --pid=$! -n 0 "${LOGPATH}/latest.log" &
|
||||
game_command "$@"
|
||||
${SUDO_CMD} tail -f --pid=${sleep_pid} -n 0 "${LOGPATH}/latest.log"
|
||||
wait
|
||||
else
|
||||
echo "There is no ${SESSION_NAME} session to connect to."
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue
Block a user