From 30a8898ac4351264ecb094c1a2fb7ff49135d182 Mon Sep 17 00:00:00 2001 From: fithwum Date: Tue, 21 Jul 2026 12:06:17 -0700 Subject: [PATCH] tmux test --- testing/Dockerfile | 2 +- testing/install_script.sh | 6 +++-- testing/{start.sh => start-screen-1.sh} | 1 - testing/start-screen-2.sh | 34 +++++++++++++++++++++++++ testing/start-tmux.sh | 32 +++++++++++++++++++++++ 5 files changed, 71 insertions(+), 4 deletions(-) rename testing/{start.sh => start-screen-1.sh} (92%) create mode 100644 testing/start-screen-2.sh create mode 100644 testing/start-tmux.sh diff --git a/testing/Dockerfile b/testing/Dockerfile index 4ca9eac..e33c705 100644 --- a/testing/Dockerfile +++ b/testing/Dockerfile @@ -29,7 +29,7 @@ ARG INSTALL_SCRIPT=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/maste # Install Java & Dependencies. RUN apt-get -y update \ - && apt-get install -y --no-install-recommends bzip2 lsb-release jq screen \ + && apt-get install -y --no-install-recommends bzip2 lsb-release jq screen tmux \ && apt-get -y --fix-broken install \ && apt-get -y autoclean \ && apt-get -y autoremove \ diff --git a/testing/install_script.sh b/testing/install_script.sh index a5e617c..4c30470 100644 --- a/testing/install_script.sh +++ b/testing/install_script.sh @@ -16,7 +16,9 @@ EULA_FILE=$MC_DIR/eula.txt EULA_MARKER=$MC_DIR/.eula_accepted SERVER_PROPERTIES=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/server.properties -START_FILE=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/start.sh +START_FILE_1=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/start-screen-1.sh +START_FILE_2=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/start-screen-2.sh +START_FILE_3=https://gitea.fithwum.tech/fithwum/minecraft/raw/branch/master/testing/start-tmux.sh VERSION_CHECK=$(curl -s "https://piston-meta.mojang.com/mc/game/version_manifest_v2.json" | grep -Pom 1 '"url": "\K[^"]*'$MC_VERSION'.json') MC_SERVER_FILE=$(curl -s $VERSION_CHECK | jq --raw-output '.downloads.server.url') @@ -395,7 +397,7 @@ if [ -f $MC_DIR/start.sh ]; then echo "INFO ! start.sh found ... moving on." else echo "WARNING ! start.sh missing ... downloading default file." - wget --no-cache --show-progress --progress=bar:force:noscroll $START_FILE -O $MC_DIR/start.sh + wget --no-cache --show-progress --progress=bar:force:noscroll $START_FILE_3 -O $MC_DIR/start.sh chmod +x $MC_DIR/start.sh fi diff --git a/testing/start.sh b/testing/start-screen-1.sh similarity index 92% rename from testing/start.sh rename to testing/start-screen-1.sh index f1a623f..950c8e4 100644 --- a/testing/start.sh +++ b/testing/start-screen-1.sh @@ -3,7 +3,6 @@ # All rights reserved cd /mcserver -# exec ./run-$MC_TYPE-$MC_VERSION.sh # Check if a screen session is already running if screen -list | grep -q "mcserver"; then diff --git a/testing/start-screen-2.sh b/testing/start-screen-2.sh new file mode 100644 index 0000000..588c47a --- /dev/null +++ b/testing/start-screen-2.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# Copyright (c) 2026 fithwum +# All rights reserved + +LOGFILE=/mcserver/logs/latest.log +SESSION=mcserver + +cd /mcserver + +# Check if a screen session is already running +if screen -list | grep -q "$SESSION"; then + echo "INFO ! A screen session for the Minecraft server is already running." + cleanup() { + echo "[INFO] Stopping Minecraft..." + screen -S "$SESSION" -X $SESSION "stop$(printf '\r')" + # Wait up to 60 seconds + for i in {1..60}; do + if ! screen -list | grep -q "$SESSION"; then + break + fi + sleep 1 + done + # Kill it if it's still alive + screen -S "$SESSION" -X quit 2>/dev/null || true + exit 0 + } + trap cleanup SIGINT SIGTERM +else + # Start the Minecraft server in a detached screen session + echo "INFO ! Starting Minecraft Server in a screen session." + touch "$LOGFILE" + screen -L -Logfile "$LOGFILE" -S "$SESSION" bash -c ./run-$MC_TYPE-$MC_VERSION.sh + exec tail -F "$LOGFILE" +fi \ No newline at end of file diff --git a/testing/start-tmux.sh b/testing/start-tmux.sh new file mode 100644 index 0000000..e2f7c2a --- /dev/null +++ b/testing/start-tmux.sh @@ -0,0 +1,32 @@ +#!/bin/bash +# Copyright (c) 2026 fithwum +# All rights reserved + +LOGFILE=/mcserver/logs/latest.log +SESSION=mcserver + +cd /mcserver + +mkdir -p "$(dirname "$LOGFILE")" +touch "$LOGFILE" + +cleanup() { + echo "[INFO] Stopping Minecraft..." + if tmux has-session -t "$SESSION" 2>/dev/null; then + tmux send-keys -t "$SESSION" "stop" Enter + for i in {1..60}; do + tmux has-session -t "$SESSION" 2>/dev/null || break + sleep 1 + done + tmux kill-session -t "$SESSION" 2>/dev/null || true + fi + exit 0 +} + +trap cleanup SIGTERM SIGINT + +echo "INFO ! Starting Minecraft Server $MC_TYPE-$MC_VERSION" +tmux new-session -d -s "$SESSION" \ + "cd $MC_DIR && ./run-$MC_TYPE-$MC_VERSION.sh 2>&1 | tee -a '$LOGFILE'" + +exec tail -F "$LOGFILE" \ No newline at end of file