diff options
author | Gordian Edenhofer | 2021-07-13 09:42:29 +0200 |
---|---|---|
committer | Gordian Edenhofer | 2021-07-13 09:50:11 +0200 |
commit | 1732e8c68c66b860493c9efc1b309a72eb7305a6 (patch) | |
tree | b318fddde00f9b581b10c975e36a83a5e6bd38b3 | |
parent | b6e85ebbf7e76abe8aa1db7cbc280e8a1be6e22d (diff) | |
download | aur-1732e8c68c66b860493c9efc1b309a72eb7305a6.tar.gz |
upgpkg: minecraft-server 1.17.1-2
Sync the minecraft-server management script across different
minecraft-server flavors.
Notify the user of the switch to tmux during post-install with a
consistent message.
upgpkg: cuberite 1.12.2c0_094cd61-2
upgpkg: cuberite-bin 1.12.2b258-2
upgpkg: papermc 1.17.1+b100-2
upgpkg: spigot 1.17.1+b131-2
-rw-r--r-- | .SRCINFO | 4 | ||||
-rw-r--r-- | PKGBUILD | 4 | ||||
-rw-r--r-- | papermc.install | 7 | ||||
-rwxr-xr-x | papermc.sh | 97 |
4 files changed, 66 insertions, 46 deletions
@@ -1,7 +1,7 @@ pkgbase = papermc pkgdesc = Next generation of Minecraft server, compatible with Spigot plugins and offering uncompromising performance pkgver = 1.17.1+b100 - pkgrel = 1 + pkgrel = 2 url = https://papermc.io/ install = papermc.install arch = any @@ -31,7 +31,7 @@ pkgbase = papermc sha512sums = 51c5345155e8640d4f1eaef0c8cfb890ae46063f2d4e7a0fe181ad4c8ff7b96fea88b0f9fc74031d589dfd61602f37b440f183ca1859835930fe69d37508cd42 sha512sums = f29c4044d9e3cc5ab137c21f7e62399b36d7e1f777d5558a39f7b4a01de75bdf2de0b8678e424accc03934ca7db9ebb6a22c78c8c4497759287dd55e1c3eb456 sha512sums = fe268d7380f881229100700b1d4f4897904a630aa65b0b06bba08be5d5918f208d497e01fc5306deecd5d93a78cfdb7e9c7f1c3b910b3a414ce9af186a05224d - sha512sums = 1982a9628e775a6ffad7c72718378d9b84b70e932a9adc0cf5fd467bfba033b62ef77a9c5f41b6d7062fcf2ab6044d4a248e31191b8e00c5e76ef6fc36eb5053 + sha512sums = bb0633de2da12b0f9e8c9ba29ef61c91785e9e6fb65f7712d60cf99d2045a38321073b78d7a7e1b34078e5627acbe42e8f3ad7164bbf6eef27dbbb3c5d41d748 sha512sums = c40cba5dfbf5af5d206cd42fa2b43f2321b481f83ab79c9ce4eaa76f204abab48ff2d8b8526a1a3d82636be97f18596d4343b0efc72a7082642e4af8d1b561c5 sha512sums = 115fe7213d7edd0e3159607a31b28edb6e6b3bd1d454d516973e38c8cf0b803275c2c4e59b29e2260561270d931c71bad134046535e5add309e0a8d055cde0ff sha512sums = 8621db1c6355b4467081ae1860a78a910c1ab3e50c8b1d71a70d701cca46131933c5d8d1352d42e0d79f75bd40e73e4fc825b9fb5be80326ef65c115244aa9df @@ -5,7 +5,7 @@ _pkgver=1.17.1 _build=100 _license_commit=40b3461 pkgver="${_pkgver}+b${_build}" -pkgrel=1 +pkgrel=2 pkgdesc="Next generation of Minecraft server, compatible with Spigot plugins and offering uncompromising performance" arch=('any') url="https://papermc.io/" @@ -31,7 +31,7 @@ sha512sums=('34366f0d5e116c011e2ff2dba884b3c5dda6444e0fb28115bc5e12ee839551a77ad '51c5345155e8640d4f1eaef0c8cfb890ae46063f2d4e7a0fe181ad4c8ff7b96fea88b0f9fc74031d589dfd61602f37b440f183ca1859835930fe69d37508cd42' 'f29c4044d9e3cc5ab137c21f7e62399b36d7e1f777d5558a39f7b4a01de75bdf2de0b8678e424accc03934ca7db9ebb6a22c78c8c4497759287dd55e1c3eb456' 'fe268d7380f881229100700b1d4f4897904a630aa65b0b06bba08be5d5918f208d497e01fc5306deecd5d93a78cfdb7e9c7f1c3b910b3a414ce9af186a05224d' - '1982a9628e775a6ffad7c72718378d9b84b70e932a9adc0cf5fd467bfba033b62ef77a9c5f41b6d7062fcf2ab6044d4a248e31191b8e00c5e76ef6fc36eb5053' + 'bb0633de2da12b0f9e8c9ba29ef61c91785e9e6fb65f7712d60cf99d2045a38321073b78d7a7e1b34078e5627acbe42e8f3ad7164bbf6eef27dbbb3c5d41d748' 'c40cba5dfbf5af5d206cd42fa2b43f2321b481f83ab79c9ce4eaa76f204abab48ff2d8b8526a1a3d82636be97f18596d4343b0efc72a7082642e4af8d1b561c5' '115fe7213d7edd0e3159607a31b28edb6e6b3bd1d454d516973e38c8cf0b803275c2c4e59b29e2260561270d931c71bad134046535e5add309e0a8d055cde0ff' '8621db1c6355b4467081ae1860a78a910c1ab3e50c8b1d71a70d701cca46131933c5d8d1352d42e0d79f75bd40e73e4fc825b9fb5be80326ef65c115244aa9df') diff --git a/papermc.install b/papermc.install index e4a957933eeb..1a7be7a8e92f 100644 --- a/papermc.install +++ b/papermc.install @@ -2,6 +2,13 @@ _game="papermc" _user="papermc" _server_root="/srv/papermc" +post_upgrade() { + echo "The management script switched from GNU screen to tmux." + echo "Manual intervention is needed to close the previous GNU screen sessions:" + echo "Use \`sudo -u ${_user} screen -S ${_game} -rx\` to attach to the ${_game} session and stop it." + echo "Do the same for the \`idle_server_${_game}\` session if one is running." +} + post_install() { echo "The world data is stored under ${_server_root} and the server runs as ${_user} user to increase security." echo "Use the ${_game} script under /usr/bin/${_game} to start, stop or backup the server." diff --git a/papermc.sh b/papermc.sh index e4e7ed485025..cfc90446ac2d 100755 --- a/papermc.sh +++ b/papermc.sh @@ -68,22 +68,23 @@ fi # Pipe any given argument to the game server console, # sleep for $sleep_time and return its output if $return_stdout is set game_command() { + ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -L "command_lock" if [[ -z "${return_stdout:-}" ]]; then - ${SUDO_CMD} screen -S "${SESSION_NAME}" -X stuff "$(printf "%s\r" "$*")" + ${SUDO_CMD} tmux -L "${SESSION_NAME}" send-keys -t "${SESSION_NAME}":0.0 "$*" Enter else - ${SUDO_CMD} screen -S "${SESSION_NAME}" -X log on - ${SUDO_CMD} screen -S "${SESSION_NAME}" -X stuff "$(printf "%s\r" "$*")" + ${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 "$*" Enter sleep "${sleep_time:-0.3}" - ${SUDO_CMD} screen -S "${SESSION_NAME}" -X log off + ${SUDO_CMD} tmux -L "${SESSION_NAME}" pipe-pane -t "${SESSION_NAME}":0.0 ${SUDO_CMD} cat "${GAME_COMMAND_DUMP}" - ${SUDO_CMD} rm "${GAME_COMMAND_DUMP}" fi + ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -U "command_lock" } # Check whether there are player on the server through list is_player_online() { response="$(sleep_time=0.6 return_stdout=true game_command list)" - # Delete leading line and free response string from fancy characters + # Delete leading line and fancy characters from free response string response="$(echo "${response}" | sed -r -e 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[JKmsuG]//g')" # 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 easily be retrieved. @@ -103,7 +104,7 @@ is_player_online() { # 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 + # This function is run within a tmux session of the GAME_USER therefore SUDO_CMD can be omitted if [[ "$(whoami)" != "${GAME_USER}" ]]; then >&2 echo "Somehow this hidden function was not executed by the ${GAME_USER} user." >&2 echo "This should not have happend. Are you messing around with this script? :P" @@ -114,17 +115,14 @@ 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" + printf "no_player: %10ss check_player_time: %10ss idle_if_time: %10ss\n" "${no_player}" "${CHECK_PLAYER_TIME}" "${IDLE_IF_TIME}" # Retry in ${CHECK_PLAYER_TIME} seconds sleep ${CHECK_PLAYER_TIME} - if screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${SESSION_NAME}"; then # Game server is up and running - if [[ "$(screen -S "${SESSION_NAME}" -ls | sed -n "s/.*${SESSION_NAME}\s\+//gp")" == "(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 + if SUDO_CMD="" is_player_online; 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} @@ -132,7 +130,7 @@ idle_server_daemon() { IDLE_SERVER="false" ${myname} stop # Wait for game server to go down for i in {1..100}; do - screen -S "${SESSION_NAME}" -Q select . > /dev/null || break + socket_has_session "${SESSION_NAME}" || break [[ $i -eq 100 ]] && echo -e "An \e[39;1merror\e[0m occurred while trying to reset the idle_server!" sleep 0.1 done @@ -163,12 +161,16 @@ idle_server_daemon() { # Start the server if it is not already running server_start() { # Start the game server - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then - echo "A screen ${SESSION_NAME} session is already running. Please close it first." + if socket_has_session "${SESSION_NAME}"; then + echo "A tmux ${SESSION_NAME} session is already running. Please close it first." else echo -en "Starting server..." - ${SUDO_CMD} screen -dmS "${SESSION_NAME}" /bin/bash -c "cd '${SERVER_ROOT}'; ${SERVER_START_CMD}" - ${SUDO_CMD} screen -S "${SESSION_NAME}" -X logfile "${GAME_COMMAND_DUMP}" + ${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}" + + # 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 @@ -180,12 +182,12 @@ server_start() { fi # Start the idle server daemon - if ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null; then - ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -X quit + if socket_has_session "${IDLE_SESSION_NAME}"; then + ${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 - if ! ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null; then - ${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon" + 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!" @@ -193,7 +195,7 @@ server_start() { done else echo -en "Starting idle server daemon..." - ${SUDO_CMD} screen -dmS "${IDLE_SESSION_NAME}" /bin/bash -c "${myname} idle_server_daemon" + ${SUDO_CMD} tmux -L "${SESSION_NAME}" new-session -s "${IDLE_SESSION_NAME}" -d "${myname} idle_server_daemon" echo -e "\e[39;1m done\e[0m" fi fi @@ -209,17 +211,17 @@ server_stop() { exit 12 fi - if ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${IDLE_SESSION_NAME}"; then echo -en "Stopping idle server daemon..." - ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -X quit + ${SUDO_CMD} tmux -L "${SESSION_NAME}" kill-session -t "${IDLE_SESSION_NAME}":0.0 echo -e "\e[39;1m done\e[0m" else - echo "The corresponding screen session for ${IDLE_SESSION_NAME} was already dead." + echo "The corresponding tmux session for ${IDLE_SESSION_NAME} was already dead." fi fi # Gracefully exit the game server - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${SESSION_NAME}"; then # Game server is up and running, gracefully stop the server when there are still active players # Check for active player @@ -243,7 +245,8 @@ server_stop() { # Finish as soon as the server has shut down completely for i in {1..100}; do - if ! ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if ! socket_has_session "${SESSION_NAME}"; then + ${SUDO_CMD} rm -f "${GAME_COMMAND_DUMP}" echo -e "\e[39;1m done\e[0m" break fi @@ -251,7 +254,7 @@ server_stop() { sleep 0.1 done else - echo "The corresponding screen session for ${SESSION_NAME} was already dead." + echo "The corresponding tmux session for ${SESSION_NAME} was already dead." fi } @@ -265,7 +268,7 @@ server_status() { exit 12 fi - if ${SUDO_CMD} screen -S "${IDLE_SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${IDLE_SESSION_NAME}"; then echo -e "Idle server daemon status:\e[39;1m running\e[0m" else echo -e "Idle server daemon status:\e[39;1m stopped\e[0m" @@ -273,13 +276,13 @@ server_status() { fi # Print status information for the game server - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${SESSION_NAME}"; then echo -e "Status:\e[39;1m running\e[0m" # 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, "(screen, bash,", count-2, "x server)"; print "Total memory usage =", sum/1024, "MB" ;};' + done | gawk '{ count ++; sum += $2 }; END {count --; print "Number of processes =", count, "(tmux,", count-1, "x server)"; print "Total memory usage =", sum/1024, "MB" ;};' else echo -e "Status:\e[39;1m stopped\e[0m" fi @@ -287,7 +290,7 @@ server_status() { # Restart the complete server by shutting it down and starting it again server_restart() { - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${SESSION_NAME}"; then server_stop server_start else @@ -306,7 +309,7 @@ backup_files() { echo "Starting backup..." fname="$(date +%Y_%m_%d_%H.%M.%S).tar.gz" ${SUDO_CMD} mkdir -p "${BACKUP_DEST}" - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${SESSION_NAME}"; then game_command save-off game_command save-all sync && wait @@ -338,7 +341,7 @@ backup_restore() { fi # Only allow the user to restore a backup if the server is down - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${SESSION_NAME}"; then >&2 echo -e "The \e[39;1mserver should be down\e[0m in order to restore the world data." exit 3 fi @@ -404,24 +407,34 @@ server_command() { exit 1 fi - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then + if socket_has_session "${SESSION_NAME}"; then return_stdout=true game_command "$@" else echo "There is no ${SESSION_NAME} session to connect to." fi } -# Enter the screen game session +# Enter the tmux game session server_console() { - if ${SUDO_CMD} screen -S "${SESSION_NAME}" -Q select . > /dev/null; then - # Circumvent a permission bug related to running GNU screen as a different user, - # see e.g. https://serverfault.com/questions/116775/sudo-as-different-user-and-running-screen - ${SUDO_CMD} script -q -c "screen -S \"${SESSION_NAME}\" -rx" /dev/null + if socket_has_session "${SESSION_NAME}"; then + ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -L "command_lock" + ${SUDO_CMD} tmux -L "${SESSION_NAME}" attach -t "${SESSION_NAME}":0.0 + ${SUDO_CMD} tmux -L "${SESSION_NAME}" wait-for -U "command_lock" else echo "There is no ${SESSION_NAME} session to connect to." fi } +# 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 $? + fi + tmux -L "${SESSION_NAME}" has-session -t "${1}":0.0 2> /dev/null + return $? +} + # Help function, no arguments required help() { cat <<-EOF @@ -436,7 +449,7 @@ help() { backup Backup the world data restore [filename] Restore the world data from a backup command <command> Run the given command at the ${game} server console - console Enter the server console through a screen session + console Enter the server console through a tmux session Copyright (c) Gordian Edenhofer <gordian.edenhofer@gmail.com> EOF |