Recent Discussions

Modded Server-Start Script closing after exiting SSH; tmux session however is staying alive

Unanswered
Polar bear posted this in #questions
Messages3 messages
Views0 views
Polar bearOP
Hello, I am having an issue I have not ran in to before in my years of using Ubuntu and utilizing virtual servers (professionally and recreationally)

When I run my start script (the gist.github link below) my server starts in a new background tmux session and
I can safely detach and reattach it no issues it stays alive.

However if I exit my ssh session, the server dies either at startup or when its ready to join. I have no idea why this
is happening, I am also running a vanilla server on a different port on the same machine and I do not have this issue.


Modded Server start script + files (Has the background tmux / ssh exit issue):
https://gist.github.com/Boostem/41b47ea9dbf6172a8bcf5da8a2131d5d

Vanilla Server start script (does not have ssh exit issue):
#!/bin/bash
SESSION_NAME="vanilla"

# Check if the session already exists
if ! tmux has-session -t $SESSION_NAME 2>/dev/null; then
    echo "Starting Minecraft server in a new tmux session: $SESSION_NAME"

    # Start a new detached tmux session and run the server
    tmux new-session -d -s $SESSION_NAME bash -c 'java -Xmx4G -Xms4G -jar minecraft_server.1.21.4.jar nogui; exec bash'
else
    echo "Minecraft server is already running in tmux session: $SESSION_NAME"
fi

Above is my script I am using to start my vanilla server, same tmux start logic and have no issue with the server closing when i close my SSH terminal.


My question and issue here: Why is closing my SSH terminal closing my modded minecraft server despite being in a background a tmux session? I am able to attach/detach from it with no issue when its running but if I detach and close my ssh session the server just stops entirely.
image.png
image.png
Polar bearOP
Turns out the fit was adding
-Djava.awt.headless=true 

to

the:
server-setup-config.yaml


# Java args that are supposed to be used when the server launches
  # keep in mind java args often need ' - ' in front of it to work, use clarifying parentheses to make sure it uses it correctly
  # reference: https://aikar.co/2018/07/02/tuning-the-jvm-g1gc-garbage-collector-flags-for-minecraft/
  # tested on Java 8 and 11
  javaArgs:
    - '-XX:+UseG1GC'
    - '-XX:+ParallelRefProcEnabled'
    - '-XX:MaxGCPauseMillis=200'
    - '-XX:+UnlockExperimentalVMOptions'
    - '-XX:+DisableExplicitGC'
    - '-XX:+AlwaysPreTouch'
    - '-XX:G1NewSizePercent=30'
    - '-XX:G1MaxNewSizePercent=40'
    - '-XX:G1HeapRegionSize=8M'
    - '-XX:G1ReservePercent=20'
    - '-XX:G1HeapWastePercent=5'
    - '-XX:G1MixedGCCountTarget=4'
    - '-XX:InitiatingHeapOccupancyPercent=15'
    - '-XX:G1MixedGCLiveThresholdPercent=90'
    - '-XX:G1RSetUpdatingPauseTimePercent=5'
    - '-XX:SurvivorRatio=32'
    - '-XX:+PerfDisableSharedMem'
    - '-XX:MaxTenuringThreshold=1'
    - '-Dusing.aikars.flags=https://mcflags.emc.gs'
    - -Daikars.new.flags=true
    - -Dfml.readTimeout=180 # servertimeout
    - -Dfml.queryResult=confirm # auto /fmlconfirm
    - --add-opens=java.base/sun.security.util=ALL-UNNAMED # java16+ support
    - --add-opens=java.base/java.util.jar=ALL-UNNAMED # java16+ support
    - '-XX:+IgnoreUnrecognizedVMOptions' # java16+ support
    - -Djava.awt.headless=true 


The start script was simply starting the server jar, the serverstarter.2.4.0.jar was NOT the server, which in hindsight makes sense... The error came from forcing the server to run as a systemc service and would receive the error:

Minecraft: Can't connect to X11 window server using 'localhost:10.0' as the value of the DISPLAY variable.

So that got me thinking: There is an attempted popup happening. Lets force this to run headless
!solved
Loading...