Recent Discussions

Autostart/Autoshutdown docker compose

Open in Discord
Unanswered
Schneider’s Smooth-fronted Caima… posted this in #questions
19 messages
1 view
Schneider’s Smooth-fronted CaimanOP
Heya, I am looking for a way to make the server go to sleep (use the least amount of resources as possible) after a certain period has passed with no users online, and automatically start it when a user connects.

I found this repo (https://github.com/oddlama/minecraft-server) but I am looking for something that is already setup to be working with a docker-compose and minimal setup from my side. Any suggestions?
Schneider’s Smooth-fronted CaimanOP
This is my current compose file:
services:
  mc:
    image: itzg/minecraft-server:latest
    tty: true
    stdin_open: true
    restart: unless-stopped
    ports:
      - "myport:25565"
    environment:
      EULA: "TRUE"
      TYPE: "PAPER"
      MEMORY: "8G"
      MAX_PLAYERS: "10"
      USE_AIKAR_FLAGS: "true"
      DIFFICULTY: "2"
      FORCE_GAMEMODE: "true"
      PVP: "false"
      ENABLE_AUTOPAUSE: "true"
      AUTOPAUSE_TIMEOUT_EST: "300"
      ENABLE_COMMAND_BLOCK: "true"
      MAX_TICK_TIME: "-1"
      ENABLE_WHITELIST: "true"
    volumes:
      - "/volume1/docker/minecraft/minecraft-server/data:/data"
Asian black bear
This functionality has been added to recent versions of Minecraft natively, which version are you using?
@Asian black bear This functionality has been added to recent versions of Minecraft natively, which version are you using?
Schneider’s Smooth-fronted CaimanOP
Server is currently running Paper 1.21.4. I enabled autopause, which is working, but the container still uses the full amount of assigned RAM (8GB) when idle
Asian black bear
Autopause as in pause-when-empty-seconds in server.properties?
@Asian black bear Autopause as in pause-when-empty-seconds in server.properties?
Schneider’s Smooth-fronted CaimanOP
yep: pause-when-empty-seconds=300
Asian black bear
I knew it frees CPU resources, I assumed memory as well. But it makes sense, Aikar's is telling it to use the full allocated amount for the GC
@Asian black bear I knew it frees CPU resources, I assumed memory as well. But it makes sense, Aikar's is telling it to use the full allocated amount for the GC
Schneider’s Smooth-fronted CaimanOP
oh okay, so you think I should not use Aikar's flags?
The server is supposed to be for 5 people max
Asian black bear
I actually always recommend using Aikar's Flags
I think the best solution would be to modify the flags to not use the full allocated memory but I'm not exactly sure how to do that with your container tbh
@Asian black bear I think the best solution would be to modify the flags to not use the full allocated memory but I'm not exactly sure how to do that with your container tbh
Schneider’s Smooth-fronted CaimanOP
I don't mind using another container if it fixes my problem, the server is running on my local NAS so I really only want it to take resources when there's users online
I thought this one looked great (https://github.com/oddlama/minecraft-server) but it's not made for docker
Asian black bear
There's nothing wrong with that image or setup (in fact it's often recommended by others), I just don't know personally how to change your startup command with it. I'll have to look into the docs.

But you'd want your startup command to look more like this:

java -Xms512M -Xmx8192M --add-modules=jdk.incubator.vector -XX:+UseG1GC -XX:+ParallelRefProcEnabled -XX:MaxGCPauseMillis=200 -XX:+UnlockExperimentalVMOptions -XX:+DisableExplicitGC -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 -XX:G1NewSizePercent=30 -XX:G1MaxNewSizePercent=40 -XX:G1HeapRegionSize=8M -XX:G1ReservePercent=20 -jar server.jar --nogui


Key changes:
minimum heap set to 512M
removed -XX:+AlwaysPreTouch (so Java will lazily request memory only when needed)
Asian black bear
Sure
Something like this
environment:
      INIT_MEMORY: 1G
      MAX_MEMORY: 8G
Schneider’s Smooth-fronted CaimanOP
Ah, I thought I needed to do something like this:
    environment:
      JVM_XX_OPTS: "-XX:MaxRAMPercentage=75"
      JVM_OPTS: "-someJVMOption someJVMOptionValue"
@Schneider’s Smooth-fronted Caiman Ah, I thought I needed to do something like this: environment: JVM_XX_OPTS: "-XX:MaxRAMPercentage=75" JVM_OPTS: "-someJVMOption someJVMOptionValue"
Southern African anchovy
MaxRAMPercentage usually is a good way to either waste memory or get oom'd on
Loading...