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.23k stars 1.52k forks source link

Autopause not resuming #555

Closed michaelwijnands-zuyd closed 2 years ago

michaelwijnands-zuyd commented 4 years ago

Running Docker with docker-minecraft through Docker-compose. Running with portforwarding on port 25565. MC version 15.5.2

I've enabled autopause on my server with Watchdog disabled. The server pause starts as it should when a user has been disconnected for 15 minutes. However when entering the game (and letting it ping) the server doesn't wake up. When trying to connect to the server this doesn't work. The only thing that made my server awake again was by manually starting the RCON connection.

[16:06:43] [Server thread/INFO]: com.mojang.authlib.GameProfile@xxxxx[id=<null>,name=Username,properties={},legacy=false] (/XX.XX.XX.XX) lost connection: Disconnected,
[init] Running as uid=1000 gid=1000 with /data as 'drwxrwxr-x    5 1000     1000          4096 Jun 10 15:02 /data',
[init] Resolved version given LATEST into 1.15.2,
[init] Autopause functionality enabled,
[init] server.properties already created, skipping,
[init] Resolving type given VANILLA,
[init] log4j2.xml already created, skipping,
[init] Checking for JSON files.,
[init] Setting initial memory to 1G and max to 1G,
[init] Starting the Minecraft server...,
[15:42:57] [main/WARN]: Ambiguity between arguments [teleport, destination] and [teleport, targets] with inputs: [Player, 0123, @e, ID],
[15:42:57] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, destination] with inputs: [0.1 -0.5 .9, 0 0 0],
[15:42:57] [main/WARN]: Ambiguity between arguments [teleport, location] and [teleport, targets] with inputs: [0.1 -0.5 .9, 0 0 0],
[15:42:57] [main/WARN]: Ambiguity between arguments [teleport, targets] and [teleport, destination] with inputs: [Player, 0123, ID],
[15:42:57] [main/WARN]: Ambiguity between arguments [teleport, targets, location] and [teleport, targets, destination] with inputs: [0.1 -0.5 .9, 0 0 0],
[15:42:57] [Server thread/INFO]: Starting minecraft server version 1.15.2,
[15:42:57] [Server thread/INFO]: Loading properties,
[15:42:57] [Server thread/INFO]: Default game type: SURVIVAL,
[15:42:57] [Server thread/INFO]: Generating keypair,
[15:42:58] [Server thread/INFO]: Starting Minecraft server on *:25565,
[15:42:58] [Server thread/INFO]: Using epoll channel type,
[15:42:59] [Server thread/INFO]: Preparing level "world",
[15:42:59] [Server thread/INFO]: Reloading ResourceManager: Default,
[Autopause loop] MC Server listening for connections - stopping in 600 seconds,
[15:43:42] [Server thread/INFO]: Loaded 6 recipes,
[15:43:42] [Server thread/INFO]: Loaded 825 advancements,
[15:43:42] [Server thread/INFO]: Preparing start region for dimension minecraft:overworld,
[15:43:44] [Server thread/INFO]: Preparing spawn area: 0%,
[15:43:45] [Server thread/INFO]: Preparing spawn area: 20%,
[15:43:45] [Server thread/INFO]: Time elapsed: 2983 ms,
[15:43:45] [Server thread/INFO]: Done (46.793s)! For help, type "help",
[15:43:45] [RCON Listener #1/INFO]: RCON running on 0.0.0.0:25575,
[15:43:45] [Server thread/INFO]: Starting remote control listener,
[15:44:42] [User Authenticator #1/INFO]: UUID of player User is UUID,
[15:44:42] [Server thread/INFO]: User[/XX.XX.XX.XX] logged in with entity id 155 at (69.90212833930714, 63.0, 105.1181025440748),
[15:44:42] [Server thread/INFO]: User joined the game,
[Autopause loop] Client connected - waiting for disconnect,
[15:44:54] [Server thread/INFO]: User lost connection: Disconnected,
[15:44:54] [Server thread/INFO]: User left the game,
[Autopause loop] All clients disconnected - stopping in 600 seconds,
[Autopause loop] No client reconnected - stopping,
[15:54:55] [RCON Listener #1/INFO]: Rcon connection from: /127.0.0.1,
[15:54:56] [Server thread/INFO]: [Rcon: Saved the game],
[2020-06-10T15:54:56+0200] [Autopause] Pausing Java process,
[2020-06-10T16:06:43+0200] [Autopause] Knocked, resuming Java process,
[16:06:43] [RCON Listener #1/INFO]: Rcon connection from: /127.0.0.1,
[16:06:43] [Server thread/WARN]: Can't keep up! Is the server overloaded? Running 707737ms or 14154 ticks behind,
[16:06:43] [Server thread/INFO]: com.mojang.authlib.GameProfile@id[id=<null>,name=User,properties={},legacy=false] (/XX.XX.XX.XX) lost connection: Disconnected,
[16:06:43] [Server thread/INFO]: com.mojang.authlib.GameProfile@id[id=<null>,name=User,properties={},legacy=false] (/XX.XX.XX.XX) lost connection: Disconnected

What's going wrong?

itzg commented 4 years ago

@Oekn5w do you have any thoughts on how to investigate further?

itzg commented 4 years ago

@michaelwijnands-zuyd in the meantime, if you can provide your compose file, that might help.

michaelwijnands-zuyd commented 4 years ago

Here's my compose file:

networks:
    traefik-public:
      external: true

services:
  minecraft:
    container_name: minecraft
    image: itzg/minecraft-server
    ports:
      - "25565:25565"
    volumes:
      - ${USERDIR}/docker/minecraft:/data
    environment:
      EULA: "TRUE"
      ENABLE_RCON: "TRUE"
      ENABLE_AUTOPAUSE: "TRUE"
      AUTOPAUSE_TIMEOUT_EST: "600"
      TZ: ${TZ}
    restart: always
    networks:
      - traefik-public

I use traefik-public as network but Traefik actually isn't handling the requests because the game didn't connect at all, so I just manually forwarded my port. I did this because I read in the readme that network mode 'host' isn't supported for autopause.

Oekn5w commented 4 years ago

Hmm, I think the network is important in this, with the compose I can't recreate it though (definition is external). I haven't worked with Traefik, I'm afraid. Two things that I would have tested if it worked:

michaelwijnands-zuyd commented 4 years ago

How does Knocking work?

Tried to knock through /bin/bash through the container of mc itself first:

bash-4.4# knock 127.0.0.1 25575:tcp
bash-4.4#

Also tried service knockd stop but whatever I try, it doesn't do anything. I'm using the console of portainer to access the container.

Oekn5w commented 4 years ago

knocking doesn't work from inside the container, because, as far as I understood, knockd latches itself to the interface, it doesn't listen on ports. The rcon port should be accessible from the traefik network, even when it is not directed from the host. knockd isn't started as service, it's started in https://github.com/itzg/docker-minecraft-server/blob/b273bf29478ebe6f390d8d914addf4c2cb96e487/files/autopause/autopause-daemon.sh#L7 (this is running as minecraft user, so sudo is neccessary) as daemon. Therefore I suggested killing the running process from bash with something along killall -SIGTERM knockd and running the above line (you're root in bash) without daemon. This should (a) print the interface it is attaching to in this configuration and (b) print some line when it is successfully knocked.

Running the rcon client from within the container does not knock the interface. Before it was merged we had the docker health command spawning healthchecks that tried to interact with the paused process and didn't time out (same scenario, accessing the MC port from within).

Also host_network was declared unsupported because knockd couldn't attach to the host eth0.

Can you provide the container's ifconfig output please? As far as I can see it doesn't contain sensitive data, no promises though.

Oekn5w commented 4 years ago

Hmm, maybe we should spawn a daemon for each interface, if that's what is causing problems

groxel commented 4 years ago

I have the same issue with bridge network.

Startring docker:

docker run -d -it -e EULA=TRUE -e VERSION=1.15.2 -e MEMORY=2G -e USE_AIKAR_FLAGS=TRUE -e TYPE=SPIGOT -e ENABLE_AUTOPAUSE=true -e AUTOPAUSE_TIMEOUT_EST=600 -e AUTOPAUSE_TIMEOUT_INIT=180 -e AUTOPAUSE_TIMEOUT_KN=120 -e AUTOPAUSE_PERIOD=10 -p 25565:25565 -v /home/mc/mc-spigot:/data --name mc-spigot itzg/minecraft-server:1.3.0-multiarch --noconsole`

After 2 minutes server goes to sleep:

[Autopause loop] No client connected since startup / knocked - stopping
[14:11:59] [RCON Listener #1/INFO]: Rcon connection from: /127.0.0.1
[14:11:59] [Server thread/INFO]: [Rcon: Saved the game]
[2020-06-21T14:11:59+03:00] [Autopause] Pausing Java process

docker inspect mc-spigot:

        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "23932da9e94d98ec12aa6386759e328caf2d197dece5edb875ec7b0f82970cb4",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "25565/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "25565"
                    }
                ],
                "25575/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/23932da9e94d",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "c61cf21c4c579c929c9414412ba9ad4d1fc0039405bc0ddbb7084f11c34f7127",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "2293ffa88cb251cf20a6f2804e2c470465535df7825c4f82af8255f98b75c64f",
                    "EndpointID": "c61cf21c4c579c929c9414412ba9ad4d1fc0039405bc0ddbb7084f11c34f7127",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
itzg commented 4 years ago

FYI, latest image (and tagged at 1.8.0) includes knock 0.8.1-r0

dnib1 commented 3 years ago

i mean its the same thing with my server also, and now my minecraft altogether is autopausing

Oekn5w commented 3 years ago

@dnib1 can you please elaborate? What is your setup (which tag), how are you running the container? Keep in mind, that since the comments above I've added the ability to select the interface to listen to, so the information above might be outdated.

tekook commented 3 years ago

I'm having the same issue, here is my docker-compose.yml version: "3"

services:
  vanilla-jei:
    image: itzg/minecraft-server:java8
    ports:
      - 25565:25565
    environment:
      EULA: "TRUE"
      ENABLE_AUTOPAUSE: "TRUE"
      RCON_PASSWORD: "********"
      TYPE: "FORGE"
      VERSION: "1.16.5"
      FORGEVERSION: "36.0.44"
    volumes:
      - ./vanilla-jei-data:/data

My server crashes everyday after some hours of pausing. Heres the crash log: 2021-03-05-1.log

It seems that the minecraft watchdog kills the server, cause the ticks took way to long.

mcblum commented 3 years ago

I believe I'm experiencing the same issue. The Java process autopauses, but it never wakes up. Is there something specific that I have to do to wake it up other than launch Minecraft and have it ping the server?

Oekn5w commented 3 years ago

@tekook from the readme in autopause:

From the server's point of view, the pausing causes a single tick to take as long as the process is stopped, so the server watchdog might intervene after the process is continued, possibly forcing a container restart. To prevent this, ensure that the max-tick-time in the server.properties file is set correctly. Non-vanilla versions might have their own configuration file, you might have to disable their watchdogs separately (e.g. PAPER Servers).

I've just created a Forge server with your versions (and current java8 tag, one commit after 2021.6.0-java8) and noticed, that the initial properties file is created without the disabled watchdog. After restarting with -1 set in the server.properties file it's working as expected. When you grep for autopause in the logs you should see that a warning was printed at server start. It can easily be missed because forge stuff clutters the logs. Forge doesn't have a separate watchdogs (with reference to the last quoted sentence).

@mcblum same as above (my previous comment), I need more information on this. What is your setup (which tag), how are you running the container? Can you provide a compose file and the relevant log entries? (Edited:) And no, the mere pinging from the Multiplayer tab in the client is sufficient to wake the process, if set correctly.

tekook commented 3 years ago

@Oekn5w thanks for the info. I set the max-tick-time to -1 and will reenable autopause and check this afternoon.

finndo77 commented 3 years ago

appears to be the oldest open issue for this (https://github.com/itzg/docker-minecraft-server/issues/555, https://github.com/itzg/docker-minecraft-server/issues/651, and https://github.com/itzg/docker-minecraft-server/issues/744 that I have found).

The short version seems to be that when AutoPause is enabled, the server eventually exits (gracefully) as the tick time exceeds the maximum allowed. per the linked issues, it does not seem that any other config setting affects it, just autopause.

this is a server log file from a Paper minecraft server that was launched and no one ever logged on before it crashed. 2021-03-12-2.log

launch command: docker run -d -e INIT_MEMORY=600M -e MAX_MEMORY=3G -e ICON=/mnt/minecraft-2/earth/icon.png -e USE_AIKAR_FLAGS=true -e MOTD="A Minecraft Survival World" -e ENABLE_AUTOPAUSE=TRUE -e EULA=TRUE -e ONLINE_MODE=FALSE -e ENFORCE_WHITELIST=TRUE -e MAX_WORLD_SIZE=90000 -e FORCE_GAMEMODE=true -e SERVER_NAME=earth -e TYPE=PAPER -e VERSION=1.16.5 -p 8123:8123 -p 25565:25565 -v /mnt/minecraft-2/minecraft/plugins:/plugins -v /mnt/minecraft-2/earth:/data -v /etc/timezone:/etc/timezone:ro --name mc-earth itzg/minecraft-server:adopt11

note that I have since removed autopause and have not been having the issue since.

tekook commented 3 years ago

@Oekn5w thanks for the info.

I set the max-tick-time to -1 and will reenable autopause and check this afternoon.

FYI, max-tick-time to -1 worked like a charm.

itzg commented 3 years ago

@finndo77 it doesn't look like you disabled the watchdog by setting

https://github.com/itzg/docker-minecraft-server#max-tick-time

which is mentioned here

https://github.com/itzg/docker-minecraft-server#autopause

however, I do see now that it could be more explicit in how to disable the watchdog in the common case.

itzg commented 3 years ago

...I have added more emphasis and details to

https://github.com/itzg/docker-minecraft-server#autopause

mafiaboy01 commented 3 years ago

I'm seeing a similar issue to @finndo77. When the server starts from being paused it throws the same errors in his logs and causes the container to restart. I have max-tick-time=-1 and running the latest image.

docker-compose.yaml

version: "3"
services:
  minecraft:
    image: itzg/minecraft-server
    container_name: minecraft
    ports:
      - "25565:25565"
    volumes:
      - /media/ssd1/minecraft:/data
    environment:
      EULA: "TRUE"
      OVERRIDE_SERVER_PROPERTIES: "TRUE"
      TYPE: "SPIGOT"
      ENABLE_RCON: "true"
      RCON_PASSWORD: "xxxxxx"
      RCON_PORT: 28016
      # enable env variable replacement
      REPLACE_ENV_VARIABLES: "TRUE"
      # define an optional prefix for your env variables you want to replace
      ENV_VARIABLE_PREFIX: "CFG_"
      # and here are the actual variables
      CFG_DB_HOST: "http://localhost:3306"
      CFG_DB_NAME: "xxxxxx"
      CFG_DB_PASSWORD: "xxxxxx"
      WHITELIST: "xxxxxx"
      INIT_MEMORY: "1G"
      MAX_MEMORY: "8G"
      ENABLE_AUTOPAUSE: "TRUE"
      AUTOPAUSE_TIMEOUT_EST: "600"
      MAX_TICK_TIME: "-1"
      OPS: "xxxxxx"
      OVERRIDE_WHITELIST: "true"
    restart: unless-stopped
  rcon:
    image: itzg/rcon
    container_name: rcon
    ports:
      - "4326:4326"
      - "4327:4327"
    environment:
      RWA_USERNAME: xxxxxx
      RWA_PASSWORD: xxxxxx
      RWA_ADMIN: "TRUE"
      RWA_RCON_HOST: minecraft
      RWA_RCON_PASSWORD: xxxxxx
      RWA_RCON_PORT: 28016 
    volumes:
      - /media/ssd1/minecraft:/opt/rcon-web-admin/db
    restart: unless-stopped

server.properties

#Minecraft server properties
#Thu Mar 18 17:45:47 GMT 2021
spawn-protection=16
max-tick-time=-1
query.port=25565
server-name=Dedicated Server
generator-settings=
sync-chunk-writes=true
force-gamemode=false
allow-nether=true
enforce-whitelist=false
gamemode=survival
broadcast-console-to-ops=true
enable-query=false
player-idle-timeout=0
text-filtering-config=
difficulty=easy
spawn-monsters=true
broadcast-rcon-to-ops=true
op-permission-level=4
pvp=true
entity-broadcast-range-percentage=100
snooper-enabled=true
level-type=default
hardcore=false
enable-status=true
enable-command-block=true
max-players=20
network-compression-threshold=256
resource-pack-sha1=
max-world-size=29999984
function-permission-level=2
rcon.port=28016
server-port=25565
debug=false
texture-pack=
server-ip=
spawn-npcs=true
allow-flight=false
level-name=world
view-distance=10
resource-pack=
spawn-animals=true
white-list=true
rcon.password=xxxxxx
generate-structures=true
max-build-height=256
online-mode=true
level-seed=
use-native-transport=true
prevent-proxy-connections=false
enable-jmx-monitoring=false
enable-rcon=true
motd=A Spigot Minecraft Server powered by Docker
rate-limit=0

Seems like it may be Spigot related but not sure what the resolution for this ticket was: https://hub.spigotmc.org/jira/browse/SPIGOT-6306

resumeFromPauseCrash.log

itzg commented 3 years ago

Hmm, that's weird it's trying a ./start.sh

[17:45:34] [Spigot Watchdog Thread/INFO]: Startup script './start.sh' does not exist! Stopping server.

In this image there's /start but not a start.sh and I don't see any references to that.

@mafiaboy01 did you make sure disable any watchdog Spigot is doing? You only showed the vanilla properties.

mafiaboy01 commented 3 years ago

It seems to be related to Spigot because I switched to Forge (I'm new to Minecraft so figuring out what type of server to run) which doesn't have this issue.

From what I read seems like the max-tick-time paremeter in the spigot.yml needs to be set to 1000 do disable it.

    max-tick-time:
      tile: 1000
      entity: 1000

But I haven't tested this myself.

Tailslide commented 3 years ago

I have the same issue with a fabric server. Set max-tick-time to -1 and it never unpauses. I don't get anything in the log after [Autopause] Pausing Java process

Tailslide commented 3 years ago

For me the issue I think this line in /autopause/knockd-config.cfg:

sudo /sbin/su-exec minecraft:minecraft /autopause/resume.sh

I am not running as UID/GID 1000 .. if I manually run this with the correct user and group it resumes but not if I manually run the line above.

Oekn5w commented 3 years ago

Confirmed, see linked issue.

Edit: Not confirmed, I didn't have the port forwarding set. Let's discuss in the issue I opened.

jmighion commented 3 years ago

I'm seeing something similar. I'm curious if it has to do with https://github.com/itzg/docker-minecraft-server/blob/master/files/autopause/autopause-daemon.sh#L98 The only way resume.sh is called is if there's an rcon client listed in the ps output. Maybe I just don't know what all starts an rcon client connect, but it doesn't appear to be happening on the Multiplayer page ping or attempt to connect.

The only way I've been able to get autopause to resume is to manually exec an rcon-cli connection like podman exec -it pause rcon-cli. That kind of defeats the purpose if that's required, so I'm guessing something is wrong.

Snippet of output:

[Autopause loop] No client reconnected - stopping
[21:45:55] [RCON Listener #1/INFO]: Thread RCON Client /0:0:0:0:0:0:0:1 started
[21:45:55] [Server thread/INFO]: [Rcon: Saved the game]
[21:45:55] [RCON Client /0:0:0:0:0:0:0:1 #4/INFO]: Thread RCON Client /0:0:0:0:0:0:0:1 shutting down
[2021-06-05T21:45:55+00:00] [Autopause] Pausing Java process
[2021-06-05T22:05:41+00:00] [Autopause] Knocked, resuming Java process
[22:05:41] [Server thread/WARN]: Can't keep up! Is the server overloaded? Running 1185651ms or 23713 ticks behind
[22:05:41] [RCON Listener #1/INFO]: Thread RCON Client /0:0:0:0:0:0:0:1 started
[Autopause loop] Server was knocked - waiting for clients or timeout
[22:05:41] [Server thread/INFO]: com.mojang.authlib.GameProfile@4bd2d1f5[id=<null>,name=GodsSyntaxError,properties={},legacy=false] (/10.0.2.100:41914) lost connection: Disconnected
[22:05:41] [Server thread/INFO]: com.mojang.authlib.GameProfile@595c6c8e[id=<null>,name=GodsSyntaxError,properties={},legacy=false] (/10.0.2.100:41924) lost connection: Disconnected
[22:05:41] [Server thread/INFO]: com.mojang.authlib.GameProfile@771cdee8[id=<null>,name=GodsSyntaxError,properties={},legacy=false] (/10.0.2.100:41922) lost connection: Disconnected
[22:05:41] [Server thread/INFO]: com.mojang.authlib.GameProfile@3b349526[id=<null>,name=GodsSyntaxError,properties={},legacy=false] (/10.0.2.100:41906) lost connection: Disconnected
[22:05:42] [RCON Client /0:0:0:0:0:0:0:1 #5/INFO]: Thread RCON Client /0:0:0:0:0:0:0:1 shutting down
[Autopause loop] No client connected since startup / knocked - stopping
[22:06:11] [RCON Listener #1/INFO]: Thread RCON Client /0:0:0:0:0:0:0:1 started
[22:06:11] [Server thread/INFO]: [Rcon: Saved the game]
[22:06:11] [RCON Client /0:0:0:0:0:0:0:1 #6/INFO]: Thread RCON Client /0:0:0:0:0:0:0:1 shutting down
[2021-06-05T22:06:11+00:00] [Autopause] Pausing Java process

Command: podman run --privileged -d -p 25566:25565 -v /home/jmighion/minecraft:/data:Z --name pause -e EULA=TRUE -e OPS=GodsSyntaxError -e INIT_MEMORY=1G -e MAX_MEMORY=4G -e WHITELIST=GodsSyntaxError -e ENFORCE_WHITELIST=true -e RCON_PORT=25576 -e RCON_PASSWORD=pauser -e ENABLE_AUTOPAUSE=TRUE -e MAX_TICK_TIME=-1 -e AUTOPAUSE_KNOCK_INTERFACE=tap0 -e AUTOPAUSE_TIMEOUT_EST=60 -e AUTOPAUSE_TIMEOUT_INIT=30 -e AUTOPAUSE_TIMEOUT_KN=30 -e OVERRIDE_SERVER_PROPERTIES=true itzg/minecraft-server

I've disabled the max tick, overriding the server properties, and set a non-standard rcon port and password. Things look to work if an rcon-cli connection is made, but that's the only way.

Oekn5w commented 3 years ago

rcon is the only way to resume from inside the container. knockd handles the resuming independent from the autopause daemon. Are you sure that the tap0 interface is the correct one? Which other interfaces do you see in the container ( ifconfig -s inside)

jmighion commented 3 years ago
$ podman exec -it mc /bin/bash
root@1fb642264605:/data# ifconfig -s
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
lo       65536 386954954      0      0 0      386954954      0      0      0 LRU
tap0     65520     4690      0      0 0          4502      0      0      0 BRU

I went with tap0 because the docs said Using the loopback interface (lo) does likely not yield the desired results. I tried again with lo and still couldn't get the server to resume without exec-ing rcon-cli on the container. So I'm not sure what I'm missing for knockd or autopause to resume the server without manually starting it via rcon-cli.

jmighion commented 3 years ago

Might there be a problem with me running the container with podman as a user vs docker as root? Podman with --privileged allowed autopause and knockd to start, but I'm wondering if there's more that necessary for listening on the network interface from a user vs root perspective.

Tailslide commented 3 years ago

You could try --cap-add=NET_ADMIN instead of priveledged

jmighion commented 3 years ago

It needs privileged or to be ran as root. I might have some more time tomorrow to try root. Without privileged :

[init] Starting the Minecraft server...
could not open tap0: tap0: You don't have permission to capture on that device (socket: Operation not permitted)
[Autopause loop] Failed to start knockd daemon.
[Autopause loop] Probable cause: Unable to attach to interface "tap0".
[Autopause loop] Available interfaces within the docker container:
[Autopause loop]   lo tap0
Oekn5w commented 3 years ago

podmon runs the containers as non-root, correct? In that case, docker really might solve the issue, or something to have access to the interfaces

jmighion commented 3 years ago

It can and I am running it as a separate user just for security because the server will be exposed to the internet. Tomorrow I might get a chance to test a local one as root and will report back.

On Sat, Jun 12, 2021 at 3:47 PM Michael Kirsch @.***> wrote:

podmon runs the containers as non-root, correct? In that case, docker really might solve the issue, or something to have access to the interfaces

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/itzg/docker-minecraft-server/issues/555#issuecomment-860122509, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADANPQLD34A55D5UDDMJLTTSPPZXANCNFSM4N2NTRRQ .

Tonkari commented 2 years ago

FYI, latest image (and tagged at 1.8.0) includes knock 0.8.1-r0

I noticed that knockd is on version 0.7 in the current "latest" image. Can you update that to 0.8 as well? 0.7 lacks IPv6 support and i had to mount knockd 0.8 myself to resume it via IPv6

jmighion commented 2 years ago

Forgot about this thread! Thanks for the bump. I should maybe just create a separate issue, but updating here because there's already history here.

Tested out with podman as root like was suggested above. That works for autopause. I noticed as a rootfull container, it had eth0 for it's interface. All settings for the container that I tried as root worked with autopause! Still required some capabilities for autopause to work, but I didn't have time to narrow that down and just ran with --privileged.

I tried updating the network for the rootless container to have eth0 as well, but that did not change anything. I did this with --net bridge and the container then had eth0 like the rootfull one did. Still required me to run rcon-cli though to get it to wake up again.

FYI --privileged and --cap-add are mutually exclusive now for podman. --privileged add all the capabilities that are available. One note from the docs that caught my attention was

Rootless containers cannot have more privileges than the account that launched them.

My guess is the rootless user is missing some permissions that are required for knockd to work properly.

itzg commented 2 years ago

I noticed that knockd is on version 0.7 in the current "latest" image. Can you update that to 0.8 as well? 0.7 lacks IPv6 support and i had to mount knockd 0.8 myself to resume it via IPv6

I am pulling knockd via the base image distro release, so it is constrained to 0.7.0:

https://github.com/itzg/docker-minecraft-server/blob/f97cea4b06ee1c236b5199ec848df9005d3f53a1/Dockerfile#L22

NotFluffy commented 2 years ago

I'm having this problem with only one of my servers.

I have 2 containers running at the same time, 1 vanilla and 1 modded. Both server.properties are the same, both have environment "ENABLE_AUTOPAUSE=TRUE". The modded server never comes back from pause.

I've noticed the vanilla server gets "knocked" every 5 minutes or so while the modded server does not. How do I configure the modded server to get knocked (I would suppose that would take care of the problem) ?

EDIT : I've figured out that it seems to only be servers not on the default minecraft port on my side.

ports:
      - 25566:25565

EDIT2: I've been trying to find a way to listen to the port and have a script send a rcon command to the server to wake it up. I'm really not that good to figure out how so right now I took out pause :/

NotFluffy commented 2 years ago

I've been trying to figure out how to make this work all week and finally got it.

I tested on vanilla servers on a docker swarm and on 2 modded servers with docker-compose, the only ones that do not get out of autopause are the servers that do not have the default minecraft port.

Compose file important parts :

    ports:
      - 25566:25565
    environment:
      - OVERRIDE_SERVER_PROPERTIES=TRUE
      - MAX_TICK_TIME=-1
      - ENABLE_AUTOPAUSE=TRUE
      - AUTOPAUSE_TIMEOUT_INIT=30
      - AUTOPAUSE_TIMEOUT_EST=10

Autopause logs :

[init] Running as uid=1000 gid=1000 with /data as 'drwxrwxr-x. 13 65534 65534 29 Nov 18 20:35 /data'
[init] Resolved version given 1.17.1 into 1.17.1
[init] Autopause functionality enabled
[Autopause loop] MC Server listening for connections - stopping in 30 seconds
[Autopause loop] No client connected since startup / knocked - stopping
[22:15:28] [RCON Listener #1/INFO]: Thread RCON Client /127.0.0.1 started
[22:15:29] [Server thread/INFO]: [Rcon: Saved the game]
[22:15:29] [RCON Client /127.0.0.1 #2/INFO]: Thread RCON Client /127.0.0.1 shutting down
[2021-11-18T22:15:30-05:00] [Autopause] Pausing Java process

Doing ifconfig inside the container, I get eth0, eth1 and lo. Installed tcpdump ('cus I don't know what else to use) I figured out eth1 is the active interface for the server. Doing tcpdump -ani eth1 port 25565 I do get a "ping" when I try to connect to the server. I looked what was in knockd-config.cfg and manually sending /usr/sbin/gosu minecraft:minecraft /autopause/resume.sh does what it should do.

I added :

    environment:
      - AUTOPAUSE_KNOCK_INTERFACE=eth1

And voila! The server now finally resumes as I was expecting it to!

I was not thinking I was using any special server configuration (ubuntu cli), so I did not expect to have to set the knock interface.

As an FYI : vanilla minecraft works A+ on a docker swarm. You "just" need a shared storage between all workers which is a bit of work to get going but really nice. I have not been able to make it work on a modded server yet.

itzg commented 2 years ago

@NotFluffy that's great you figured out your scenario! I'm not sure what would lead to a container having two interfaces other than maybe the networks config. Can you provide the rest of your compose file?

NotFluffy commented 2 years ago

Here are the 2 vanilla server compose files.

I tried to keep them as close as possible to each other to make sure nothing else could explain the problem.

version: '3.9'

services:
  minecraft_test:
    image: itzg/minecraft-server:java16
    networks:
      - mc
    ports:
      - 25565:25565
    volumes:
      - data:/data
    environment:
      - EULA=TRUE
      - VERSION=1.17.1
      - TYPE=VANILLA
      - OVERRIDE_SERVER_PROPERTIES=TRUE
      - MOTD=A test
      - DIFFICULTY=easy
      - ENABLE_WHITELIST=true
      - OVERRIDE_OPS=true
      - OPS=me
      - ANNOUNCE_PLAYER_ACHIEVEMENTS=true
      - SNOOPER_ENABLED=false
      - MAX_TICK_TIME=-1
      - VIEW_DISTANCE=10
      - INIT_MEMORY=750m
      - MEMORY=4G
      - TZ=America/Toronto
      - ENABLE_AUTOPAUSE=TRUE
      - AUTOPAUSE_TIMEOUT_INIT=30
      - AUTOPAUSE_TIMEOUT_EST=10
      - DEBUG=true

volumes:
  data:
    name: mc_test_data
    external: true

networks:
  mc:
    name: mc_test
    external: true
version: '3.9'

services:
  minecraft_vanilla:
    image: itzg/minecraft-server:java16
    networks:
      - mc
    ports:
      - 25566:25565
    volumes:
      - data:/data
    environment:
      - EULA=TRUE
      - VERSION=1.17.1
      - TYPE=VANILLA
      - OVERRIDE_SERVER_PROPERTIES=TRUE
      - MOTD=The server with a big circle house.
      - DIFFICULTY=hard
      - ENABLE_WHITELIST=true
      - OVERRIDE_OPS=true
      - OPS=someone,me
      - ANNOUNCE_PLAYER_ACHIEVEMENTS=true
      - SNOOPER_ENABLED=false
      - MAX_TICK_TIME=-1
      - VIEW_DISTANCE=10
      - INIT_MEMORY=750m
      - MEMORY=4G
      - TZ=America/Toronto
      - ENABLE_AUTOPAUSE=TRUE
      - AUTOPAUSE_TIMEOUT_INIT=30
      - AUTOPAUSE_TIMEOUT_EST=10
      - AUTOPAUSE_KNOCK_INTERFACE=eth1
      - DEBUG=true

volumes:
  data:
    name: mc_vanilla_data
    external: true

networks:
  mc:
    name: mc_vanilla
    external: true

Creation of networks : docker network create -d overlay --attachable mc_vanilla docker network create -d overlay --attachable mc_test

And just for anyone who wants to make this on a docker swarm, you have to create the volumes from the shared storage on each workers (do not prune volumes, it will delete these and you don't want that) :

docker volume create --driver local \
-o o=bind \
-o type=none \
-o device=/shared_storage/vanilla_mc/data \
mc_vanilla_data
woeisme commented 2 years ago

what is the correct syntax to add JVM_DD_OPTS=disable.watchdog:true to a docker-compose.yml file?

github-actions[bot] commented 2 years 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.

travis-anderson commented 2 years ago

Additional related info: Using the alpine image does not have gosu installed by default, and thus the resume script cannot run.

woeisme commented 1 year ago

what is the correct syntax to add JVM_DD_OPTS=disable.watchdog:true to a docker-compose.yml file?

Since I came across my OWN question 2 years later while setting this up, the correct format for a paper docker-compose.yml is JVM_DD_OPTS: disable.watchdog=true