aboutsummarylogtreecommitdiffstats
path: root/papermc.sh
diff options
context:
space:
mode:
authorGordian Edenhofer2021-10-20 22:15:40 +0200
committerGordian Edenhofer2021-10-20 22:27:13 +0200
commit78fe0aa9d8400a31fe4a6f9009466f500a7379cc (patch)
tree41bfad4f5727eb0b525e26beaf07c86b6f901a02 /papermc.sh
parent94d319e9c95f7fd5f5bde33297392cdd50978f83 (diff)
downloadaur-78fe0aa9d8400a31fe4a6f9009466f500a7379cc.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
Diffstat (limited to 'papermc.sh')
-rwxr-xr-xpapermc.sh56
1 files changed, 48 insertions, 8 deletions
diff --git a/papermc.sh b/papermc.sh
index 4edfeec09aa4..db2ee09f912c 100755
--- a/papermc.sh
+++ b/papermc.sh
@@ -20,6 +20,7 @@ declare -r game="papermc"
# 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
;;