itzg / docker-minecraft-server

Docker image that provides a Minecraft Server that will automatically download selected version at startup
https://docker-minecraft-server.readthedocs.io/
Apache License 2.0
9.16k stars 1.52k forks source link

Suspended server is killed #1729

Closed LoockyCZ closed 1 year ago

LoockyCZ commented 2 years ago

Describe the problem

If the server has been suspended, the server will be killed when the container is stopped. The STOP_DURATION timeout occurs. If the server has not yet been suspended or is awakened, the process is correctly terminated immediately. From what I understand by reading the code docker-minecraft-server and mc-server-runner, the java process must be woken up (pkill -CONT java), otherwise the "stop" command from mc-server-runner will not be processed.

Container definition

docker-compose.yml

version: '3.7'
services:
  mc-server:
    image: itzg/minecraft-server:java17
    container_name: mc-server
    restart: always
    stop_grace_period: 2m
    ports:
      - 25565:25565
    env_file:
      - env.env

env.env

EXEC_DIRECTLY=false
TYPE=PAPER
OVERRIDE_SERVER_PROPERTIES=true
SERVER_PORT=25565
EULA=true
ENABLE_AUTOPAUSE=true
AUTOPAUSE_TIMEOUT_EST=300
AUTOPAUSE_TIMEOUT_INIT=300
AUTOPAUSE_TIMEOUT_KN=120
AUTOPAUSE_PERIOD=10
MAX_TICK_TIME=-1
MAX_PLAYERS=2
DIFFICULTY=easy
MAX_WORLD_SIZE=5000
HARDCORE=false
SNOOPER_ENABLED=false
JVM_DD_OPTS=disable.watchdog:true

Container logs

Suspended server:

mc-server     | [Autopause loop] MC Server listening for connections - pausing in 300 seconds
mc-server     | [20:52:12 INFO]: [LevelTools] No new updates found.
mc-server     | [Autopause loop] No client connected since startup / knocked - pausing
mc-server     | [20:57:13 INFO]: Thread RCON Client /127.0.0.1 started
mc-server     | [20:57:20 INFO]: [Rcon: Saved the game]
mc-server     | [20:57:20 INFO]: Thread RCON Client /127.0.0.1 shutting down
mc-server     | [20:57:20 WARN]: Can't keep up! Is the server overloaded? Running 10679ms or 213 ticks behind
mc-server     | [2022-09-12T20:57:20+00:00] [Autopause] Pausing Java process
mc-server     | 2022-09-12T20:58:47.923Z        INFO    mc-server-runner        Sending 'stop' to Minecraft server...
mc-server     | 2022-09-12T20:58:47.932Z        INFO    mc-server-runner        Waiting for completion...
mc-server     | 2022-09-12T21:00:48.050Z        ERROR   mc-server-runner        Took too long, so killing server process
mc-server     | 2022-09-12T21:00:48.452Z        WARN    mc-server-runner        Minecraft server process failed {"exitCode": -1}
mc-server     | 2022-09-12T21:00:48.454Z        INFO    mc-server-runner        Done

Unsuspended server

mc-server     | [Autopause loop] MC Server listening for connections - pausing in 300 seconds
mc-server     | 2022-09-12T21:09:27.084Z        INFO    mc-server-runner        Sending 'stop' to Minecraft server...
mc-server     | 2022-09-12T21:09:27.091Z        INFO    mc-server-runner        Waiting for completion...
mc-server     | [21:09:27 INFO]: Stopping the server
mc-server     | [21:09:27 INFO]: Stopping server
mc-server     | [21:09:28 INFO]: Saving players
mc-server     | [21:09:28 INFO]: Saving worlds
mc-server     | [21:09:30 INFO]: Saving chunks for level 'ServerLevel[world]'/minecraft:overworld
mc-server     | failed to ping localhost:25565 : could not connect to Minecraft server: dial tcp 127.0.0.1:25565: connect: connection refused/auto/autopause-fcns.sh: line 34: ((: > 0 : syntax error: operand expected (error token is "> 0 ")
mc-server     | [21:09:40 INFO]: Saving chunks for level 'ServerLevel[world_nether]'/minecraft:the_nether
mc-server     | [21:09:40 INFO]: Saving chunks for level 'ServerLevel[world_the_end]'/minecraft:the_end
mc-server     | [21:09:40 INFO]: ThreadedAnvilChunkStorage (world): All chunks are saved
mc-server     | [21:09:40 INFO]: ThreadedAnvilChunkStorage (DIM-1): All chunks are saved
mc-server     | [21:09:40 INFO]: ThreadedAnvilChunkStorage (DIM1): All chunks are saved
mc-server     | [21:09:40 INFO]: ThreadedAnvilChunkStorage: All dimensions are saved
mc-server     | [21:09:41 INFO]: Flushing Chunk IO
mc-server     | [21:09:41 INFO]: Closing Thread Pool
mc-server     | 2022-09-12 21:09:41,116 Log4j2-AsyncAppenderEventDispatcher-1-Async WARN Advanced terminal features are not available in this environment
mc-server     | [21:09:41 INFO]: Closing Server
mc-server     | 2022-09-12T21:09:41.844Z        INFO    mc-server-runner        Done
github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Please add a comment describing the reason to keep this issue open.

taggart commented 1 year ago

It looks like you are running PaperMC? The autopause description section of the README explains you need also need to do something special for the JVM in that case.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Please add a comment describing the reason to keep this issue open.

itzg commented 1 year ago

I finally thought of something can be done in mc-server-runner:

LoockyCZ commented 1 year ago

I don't know how clean this solution is, but for my purposes I use this patch. https://github.com/itzg/docker-minecraft-server/commit/b49e4400aa809106449ccdafac0a6b8e65ceba68

itzg commented 1 year ago

Thanks for info. It's a decent modification but I don't like that it puts mc-server-runner in the background. It is supposed end up as PID 1 and that change defeats that.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Please add a comment describing the reason to keep this issue open.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Please add a comment describing the reason to keep this issue open.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Please add a comment describing the reason to keep this issue open.

Botnolink commented 1 month ago

I have An Error

[00:04:07] [Server thread/WARN]: **** SERVER IS RUNNING IN OFFLINE/INSECURE MODE!

[00:04:07] [Server thread/WARN]: The server will make no attempt to authenticate usernames. Beware.

[00:04:07] [Server thread/WARN]: While this makes the game possible to play without internet access, it also opens up the ability for hackers to connect with any username they choose.

[00:04:07] [Server thread/WARN]: To change this, set "online-mode" to "true" in the server.properties file.

[00:04:07] [Server thread/INFO]: Preparing level "world" Killed