joesturge / lazymc-docker-proxy

Put your Minecraft containers to rest when idle.
GNU General Public License v3.0
27 stars 4 forks source link

Read MOTD configuration from server.properties file, and hotswap confiurations #98

Open Rubicj opened 2 months ago

Rubicj commented 2 months ago

I'd like to set something up to automatically rotate MOTDs. I can change the MOTD of the actual MC server by writing to the server.properties file, but when the server is sleeping/started that's not shown, and instead it shows the contents of the labels, such as lazymc.motd.sleeping.

Is there a good way to update those MOTDs periodically? I plan to have a cronjob running every period (ideally seconds, otherwise minutes) that selects a random message, then applies it to the server.

In case it's relevant, my abbriviated compose file:

networks:
  minecraft-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.0.0/16

services:
  lazymc:
    container_name: lazymc
    image: ghcr.io/joesturge/lazymc-docker-proxy:latest
    networks:
      minecraft-network:
        ipv4_address: 172.20.0.2
    environment:
      RUST_LOG: DEBUG
    restart: unless-stopped
    volumes:
      - /mnt/cache/appdata/minecraft/data:/server/mc:ro
      - /var/run/docker.sock:/var/run/docker.sock:ro
    ports:
      - "25565:25565"
  minecraft:
    image: itzg/minecraft-server:java17
    tty: true
    stdin_open: true
    container_name: minecraft
    networks:
      minecraft-network:
        ipv4_address: 172.20.0.3
    environment:
      VERSION: 1.19.2
      EULA: true
      TYPE: CURSEFORGE
      CF_SERVER_MOD: a modpack
      MEMORY: 16G
      ENABLE_WHITELIST: true
      DISABLE_HEALTHCHECK: true
      DIFFICULTY: normal
    volumes:
      - /mnt/cache/appdata/minecraft/data:/data
      - /mnt/cache/appdata/minecraft/appdata:/appdata
      - /mnt/cache/appdata/minecraft/modpacks:/modpacks:ro
    restart: no
    labels:
      - lazymc.enabled=true
      - lazymc.group=mc
      - lazymc.server.address=172.20.0.3:25565
      - lazymc.public.version=1.19.2
      - lazymc.time.sleep_after=300
      - lazymc.time.minimum_online_time=600
      - lazymc.server.directory=/server/mc

If my minecraft container is stopped, and I recreate the image with different lazymc.motd.sleeping labels, the new labels aren't pulled in unless I restart the lazymc container. That's not a complete dealbreaker, as lazymc does restart very quickly, but if if the container takes 5s to restart and I do this once a minute, that means there's a one-in-twelve chance that when someone tries to connect, lazymc will be restarting. Additionally, when a player tries to join, lazymc then can't find the new container to start.

joesturge commented 2 months ago

Thanks for the question, im afriad at the moment there is no way to do this without changing the lazymc.motd.* labels and restarting the lazymc container. I have an open issue for hotswapping server configurations which may solve this in the future: #75, you would just have to have a script which changes the label on the mc container but at the moment this will not work.

I could add a feature which checks the server properties for the MOTD configuration then update the that way on the fly. However non of this is supported yet

joesturge commented 2 months ago

Ill update this issue as an enhancement feature and keep open for now

joesturge commented 2 months ago

for the time being also try using something like: https://github.com/itzg/docker-bungeecord/ to change the MOTD before proxying it to the lazymc server