diff options
author | Gordian Edenhofer | 2021-10-20 22:15:40 +0200 |
---|---|---|
committer | Gordian Edenhofer | 2021-10-20 22:27:13 +0200 |
commit | de19532d88b4c7ea21fcdd518bc9e8efd40f0dc2 (patch) | |
tree | 4b9dd800e8b736e89de432059952742a86421df9 | |
parent | c8486ae490bfc2e6922466b273e461e9b41b2483 (diff) | |
download | aur-de19532d88b4c7ea21fcdd518bc9e8efd40f0dc2.tar.gz |
upgpkg: minecraft-server 1.17.1-3
Print the output of the server to the terminal if startup fails.
Evaluate a failure during startup by constantly inspecting the output of
the server for the first 15 seconds during startup.
Relates to #13 .
upgpkg: cuberite 1.12.2c1_afe07fe-1
upgpkg: cuberite-bin 1.12.2b284-3
upgpkg: papermc 1.17.1+b341-1
upgpkg: spigot 1.17.1+b131-4
-rw-r--r-- | .SRCINFO | 5 | ||||
-rw-r--r-- | PKGBUILD | 5 | ||||
-rwxr-xr-x | minecraftd.sh | 56 |
3 files changed, 54 insertions, 12 deletions
@@ -1,8 +1,9 @@ pkgbase = minecraft-server pkgdesc = Minecraft server unit files, script, and jar pkgver = 1.17.1 - pkgrel = 2 + pkgrel = 3 url = https://minecraft.net/ + install = minecraft-server.install arch = any license = custom depends = java-runtime-headless>=16 @@ -32,6 +33,6 @@ pkgbase = minecraft-server sha512sums = a62c8c04e08dbac0db0aa2eeb505d70f8fd925bd2e427899512ba3ac828d4644e1c43c8d92325c6bc49c8d9ecb40cb5c44bf5957a63980b1e2cf86fdb38a05a7 sha512sums = a74f4e31065b6c6f5c830182de05a8c75a6de6eaac7b3dc26479827646ef20ab872509aac88be613048c97d378711c38612ec7ac92d22134acefd40f6e0a99da sha512sums = 30e434ba183527da8047b1ffe403a083f1af34dbd229b5871222e9da0004cdf5d4152eaa4b73215befcb1233d08cc757af32ad6b572f4b6d2a623b6f120aa0d9 - sha512sums = 52ff440342aa218e81aaca452db2e7a867809e3dc4a99b3726aa7189ed38a9e08e838475d60578e87dda90fa0ece86ea6d496ab3ef901365dc9e809c548ea281 + sha512sums = d774b5ccf23fdda4db6b28956b75ef26ba5afc2c842ebaf31a15c339d4a48de9fd3e97ae0e1d21bee05a6b3c118be1ad139c3f7a08f7f2b5e63206aa7bace123 pkgname = minecraft-server @@ -5,7 +5,7 @@ pkgname=minecraft-server pkgver=1.17.1 _nonce=a16d67e5807f57fc4e550299cf20226194497dc2 -pkgrel=2 +pkgrel=3 pkgdesc="Minecraft server unit files, script, and jar" arch=('any') url="https://minecraft.net/" @@ -15,6 +15,7 @@ optdepends=("tar: needed in order to create world backups" "netcat: required in order to suspend an idle server") conflicts=('minecraft-server-systemd' 'minecraft-canary') backup=('etc/conf.d/minecraft') +install="${pkgname}.install" # See https://launchermeta.mojang.com/mc/game/version_manifest.json for a list of all releases source=("minecraft_server.${pkgver}.jar"::"https://launcher.mojang.com/v1/objects/${_nonce}/server.jar" "minecraftd-backup.service" @@ -32,7 +33,7 @@ sha512sums=('fe6e48e2cee38224d2c88f04c19afca9c21fddbe6077b5538e0a0581c2f6c4478ec 'a62c8c04e08dbac0db0aa2eeb505d70f8fd925bd2e427899512ba3ac828d4644e1c43c8d92325c6bc49c8d9ecb40cb5c44bf5957a63980b1e2cf86fdb38a05a7' 'a74f4e31065b6c6f5c830182de05a8c75a6de6eaac7b3dc26479827646ef20ab872509aac88be613048c97d378711c38612ec7ac92d22134acefd40f6e0a99da' '30e434ba183527da8047b1ffe403a083f1af34dbd229b5871222e9da0004cdf5d4152eaa4b73215befcb1233d08cc757af32ad6b572f4b6d2a623b6f120aa0d9' - '52ff440342aa218e81aaca452db2e7a867809e3dc4a99b3726aa7189ed38a9e08e838475d60578e87dda90fa0ece86ea6d496ab3ef901365dc9e809c548ea281') + '855afa53509439adc26e12a54d63659dcafc90b423e633a52862e71bbb58107a46f228cac60b79e5cf677b3c49e36e715ec05c7b56329559fac9fe0e7ea0fb9c') _game="minecraft" _server_root="/srv/minecraft" diff --git a/minecraftd.sh b/minecraftd.sh index 90e6f94d17ef..c806c650c6e2 100755 --- a/minecraftd.sh +++ b/minecraftd.sh @@ -20,6 +20,7 @@ declare -r game="minecraft" # Command and parameter declaration with which to start the server [[ -n "${SERVER_START_CMD}" ]] && declare -r SERVER_START_CMD=${SERVER_START_CMD} || SERVER_START_CMD="java -Xms512M -Xmx1024M -jar './${MAIN_EXECUTABLE}' nogui" +[[ -n "${SERVER_START_SUCCESS}" ]] && declare -r SERVER_START_SUCCESS=${SERVER_START_SUCCESS} || SERVER_START_SUCCESS="done" # System parameters for the control script [[ -n "${IDLE_SERVER}" ]] && tmp_IDLE_SERVER=${IDLE_SERVER} || IDLE_SERVER="false" @@ -43,6 +44,8 @@ set -u # Exit if a single command breaks and its failure is not handled accordingly set -e +MAX_SERVER_START_TIME=150 + # Check whether sudo is needed at all if [[ "$(whoami)" == "${GAME_USER}" ]]; then SUDO_CMD="" @@ -169,12 +172,38 @@ server_start() { else echo -en "Starting server..." ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}" + # Use a plain file as command buffers for the server startup and switch to a FIFO pipe later + ${SUDO_CMD} touch "${GAME_COMMAND_DUMP}" + # Ensure pipe-pine is started before the server itself by splitting the session creation and server startup + ${SUDO_CMD} tmux -L "${SESSION_NAME}" new-session -s "${SESSION_NAME}" -c "${SERVER_ROOT}" -d /bin/bash + ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -L "command_lock" + ${SUDO_CMD} tmux -L "${SESSION_NAME}" pipe-pane -t "${SESSION_NAME}":0.0 "cat > ${GAME_COMMAND_DUMP}" + ${SUDO_CMD} tmux -L "${SESSION_NAME}" send-keys -t "${SESSION_NAME}":0.0 "exec ${SERVER_START_CMD}" Enter + for ((i=1; i<=MAX_SERVER_START_TIME; i++)); do + sleep "${sleep_time:-0.1}" + if ! socket_session_is_alive "${SESSION_NAME}"; then + echo -e "\e[39;1m failed\e[0m\n" + >&2 ${SUDO_CMD} cat "${GAME_COMMAND_DUMP}" + ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}" + # Session is dead but remain-on-exit left it open; close it for sure + ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${SESSION_NAME}" + exit 1 + elif grep -q -i "${SERVER_START_SUCCESS}" "${GAME_COMMAND_DUMP}"; then + echo -e "\e[39;1m done\e[0m" + break + elif [[ $i -eq ${MAX_SERVER_START_TIME} ]]; then + echo -e "\e[39;1m skipping\e[0m" + >&2 echo -e "Server startup has not finished yet; continuing anyways" + fi + done + ${SUDO_CMD} tmux -L "${SESSION_NAME}" pipe-pane -t "${SESSION_NAME}":0.0 + # Let the command buffer be a FIFO pipe + ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}" ${SUDO_CMD} mkfifo "${GAME_COMMAND_DUMP}" - ${SUDO_CMD} tmux -L "${SESSION_NAME}" new-session -s "${SESSION_NAME}" -c "${SERVER_ROOT}" -d "${SERVER_START_CMD}" + ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -U "command_lock" # Mimic GNU screen and allow for both C-a and C-b as prefix ${SUDO_CMD} tmux -L "${SESSION_NAME}" set -g prefix2 C-a - echo -e "\e[39;1m done\e[0m" fi if [[ "${IDLE_SERVER,,}" == "true" ]]; then @@ -189,12 +218,12 @@ server_start() { ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${IDLE_SESSION_NAME}" # Restart as soon as the idle_server_daemon has shut down completely for i in {1..100}; do + sleep 0.1 if ! socket_has_session "${IDLE_SESSION_NAME}"; then ${SUDO_CMD} tmux -L "${SESSION_NAME}" new-session -s "${IDLE_SESSION_NAME}" -d "${myname} idle_server_daemon" break fi [[ $i -eq 100 ]] && echo -e "An \e[39;1merror\e[0m occurred while trying to reset the idle_server!" - sleep 0.1 done else echo -en "Starting idle server daemon..." @@ -216,7 +245,7 @@ server_stop() { if socket_has_session "${IDLE_SESSION_NAME}"; then echo -en "Stopping idle server daemon..." - ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${IDLE_SESSION_NAME}":0.0 + ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${IDLE_SESSION_NAME}" echo -e "\e[39;1m done\e[0m" else echo "The corresponding tmux session for ${IDLE_SESSION_NAME} was already dead." @@ -285,7 +314,7 @@ server_status() { # Calculating memory usage for p in $(${SUDO_CMD} pgrep -f "${MAIN_EXECUTABLE}"); do ps -p"${p}" -O rss | tail -n 1; - done | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =", count, "(tmux,", count-1, "x server)"; print "Total memory usage =", sum/1024, "MB" ;};' + done | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =", count, "(tmux +", count, "x server)"; print "Total memory usage =", sum/1024, "MB" ;};' else echo -e "Status:\e[39;1m stopped\e[0m" fi @@ -429,13 +458,24 @@ server_console() { # Check if there is a session available socket_has_session() { if [[ "$(whoami)" != "${GAME_USER}" ]]; then - ${SUDO_CMD} tmux -L "${SESSION_NAME}" has-session -t "${1}":0.0 2> /dev/null - return $? + ${SUDO_CMD} tmux -L "${SESSION_NAME}" has-session -t "${1}":0.0 2> /dev/null + return $? fi tmux -L "${SESSION_NAME}" has-session -t "${1}":0.0 2> /dev/null return $? } +socket_session_is_alive() { + if socket_has_session "${1}"; then + if [[ "$(whoami)" != "${GAME_USER}" ]]; then + return $(${SUDO_CMD} tmux -L "${SESSION_NAME}" list-panes -t "${1}":0.0 -F '#{pane_dead}' 2> /dev/null) + fi + return $(tmux -L "${SESSION_NAME}" list-panes -t "${1}":0.0 -F '#{pane_dead}' 2> /dev/null) + else + return 1 + fi +} + # Help function, no arguments required help() { cat <<-EOF @@ -490,7 +530,7 @@ case "${1:-}" in ;; idle_server_daemon) - # This shall be a hidden function which should only be invoced internally + # This shall be a hidden function which should only be invoked internally idle_server_daemon ;; |