aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorGordian Edenhofer2021-07-13 09:42:29 +0200
committerGordian Edenhofer2021-07-13 09:50:11 +0200
commit5d4228fc1e5cb64ba90a4e7eb58bcb1f885afba8 (patch)
tree6856cdde9de2ac067ac8168fc8c21369fdb4707f
parent1ca635493b8d505492a4cdd567c48baddf6e025d (diff)
downloadaur-5d4228fc1e5cb64ba90a4e7eb58bcb1f885afba8.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--.SRCINFO4
-rw-r--r--PKGBUILD4
-rw-r--r--cuberite.install7
-rwxr-xr-xcuberite.sh97
4 files changed, 66 insertions, 46 deletions
diff --git a/.SRCINFO b/.SRCINFO
index 096881bd889d..20ad5c5ba2bf 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,7 +1,7 @@
pkgbase = cuberite-bin
pkgdesc = A Minecraft-compatible multiplayer game server that is written in C++ and designed to be efficient with memory and CPU, as well as having a flexible Lua Plugin API. It is compatible with the vanilla Minecraft client.
pkgver = 1.12.2b258
- pkgrel = 1
+ pkgrel = 2
url = https://cuberite.org/
install = cuberite.install
arch = i686
@@ -37,7 +37,7 @@ pkgbase = cuberite-bin
sha512sums = 0e82acfe3e907f3976e96aebb146d12f076a26e4478f3330d4f0ded44956624094abc35e56402f6a994fb5852fbc7e901e4e2b8f1ae31f3e82224e6bc15eba0b
sha512sums = 09047f4df9591b2d61885c842cbd9abde590b0069945f2e10fd402ad93f0f0abd3c2557e61200388038708960f5d82e22d332efe83cf1acf0895f56dd2e5d5d0
sha512sums = 9282301a67a612a4b757324274b6deea16d57e919b3c367a92414d7b74fe0ec4f5e54748ccf0ff14f6c62e8dbc5cb211afebfff8ad5abe63945afccf9484378f
- sha512sums = ee9c0fdcae1b104688ba90eb3173968be548240067b22272ccb1da0512c3773fde33ee23d5cb4cb27e08b21638a4d3007c26c0878d3d0c35fb2daf4b5e1dd79b
+ sha512sums = 2c2a2603340f06e88afbc180495b8a14e263caaec61d8899da98b61f47acdb35869c5aa9cfb23d2a1fe3ad17ab6854889011bae44c71cff970cfdceb006a312f
source_i686 = Cuberite.b268_i686.tar.gz::https://builds.cuberite.org/view/all/job/linux-i386/268/artifact/Cuberite.tar.gz
sha512sums_i686 = 12a94ca2f55be3fbc147b1ddee2782c99bdc20619050cb15196e6b802691cb9e8003258e1fbc6a582dae731c40a823a19519e2ea29056c34f4f041905bc4129b
source_x86_64 = Cuberite.b258_x86_64.tar.gz::https://builds.cuberite.org/view/all/job/linux-x86_64/258/artifact/Cuberite.tar.gz
diff --git a/PKGBUILD b/PKGBUILD
index ea9eca0a3853..dd6899f83127 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -7,7 +7,7 @@ _build_i686=268
_build_x86_64=258
_build_armv7h=258
pkgver="${_pkgver}b${_build_x86_64}"
-pkgrel=1
+pkgrel=2
pkgdesc="A Minecraft-compatible multiplayer game server that is written in C++ and designed to be efficient with memory and CPU, as well as having a flexible Lua Plugin API. It is compatible with the vanilla Minecraft client."
arch=('i686' 'x86_64' 'armv7h')
url="https://cuberite.org/"
@@ -35,7 +35,7 @@ sha512sums=('4b4161558343dd2ec4d6b2be41b958e061df2a41961d9476ac1d38f28530043f997
'0e82acfe3e907f3976e96aebb146d12f076a26e4478f3330d4f0ded44956624094abc35e56402f6a994fb5852fbc7e901e4e2b8f1ae31f3e82224e6bc15eba0b'
'09047f4df9591b2d61885c842cbd9abde590b0069945f2e10fd402ad93f0f0abd3c2557e61200388038708960f5d82e22d332efe83cf1acf0895f56dd2e5d5d0'
'9282301a67a612a4b757324274b6deea16d57e919b3c367a92414d7b74fe0ec4f5e54748ccf0ff14f6c62e8dbc5cb211afebfff8ad5abe63945afccf9484378f'
- 'ee9c0fdcae1b104688ba90eb3173968be548240067b22272ccb1da0512c3773fde33ee23d5cb4cb27e08b21638a4d3007c26c0878d3d0c35fb2daf4b5e1dd79b')
+ '2c2a2603340f06e88afbc180495b8a14e263caaec61d8899da98b61f47acdb35869c5aa9cfb23d2a1fe3ad17ab6854889011bae44c71cff970cfdceb006a312f')
sha512sums_i686=('12a94ca2f55be3fbc147b1ddee2782c99bdc20619050cb15196e6b802691cb9e8003258e1fbc6a582dae731c40a823a19519e2ea29056c34f4f041905bc4129b')
sha512sums_x86_64=('ad6a944ee505caa2b3e9e01f3dec8635bd49eabedc36702c86b331d08638af24117b978b80af7ddbc087e3495363d3cf0354057d21148636e485b26f0603d7bd')
sha512sums_armv7h=('9ed1c27426ca734688517fd025a41a256a7fadfbb7023dfaf71d7c89e362840010673dc9955d9c682c61d203a5118c0012c3c7fd662e24ef11410e0d26ab1549')
diff --git a/cuberite.install b/cuberite.install
index 38a7b913062c..40a79d7cd064 100644
--- a/cuberite.install
+++ b/cuberite.install
@@ -2,6 +2,13 @@ _game="cuberite"
_user="cuberite"
_server_root="/srv/cuberite"
+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."
}
diff --git a/cuberite.sh b/cuberite.sh
index 28412d7b49e1..61813e2ee351 100755
--- a/cuberite.sh
+++ b/cuberite.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