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

ops.json and whitelist.json not redownloaded on restart #1505

Closed camalot closed 2 years ago

camalot commented 2 years ago

Describe the problem

If the /data/ops.json or /data/whitelist.json already exists, and OPS_FILE / WHITELIST_FILE are URLS, they are not downloaded to replace the existing files.

instead of a copy from /data/ops.json to the server directory, why not just use a symlink? example: ln -s /data/whitelist.json /data/FeedTheBeast/ServerFiles/whitelist.json.

Would also be great if there was a way to have it recheck the remote file periodically, so a server restart isn't required to update the whitelist. (this is probably an additional feature)

Container definition

version: '3.7'
networks:
  internal:
    driver: bridge
services:
  # https://github.com/itzg/docker-minecraft-server/blob/master/README.md
  minecraft-curseforge:
    hostname: minecraft-curseforge
    container_name: minecraft-curseforge
    image: itzg/minecraft-server:java17-alpine
    networks:
    - internal
    ports: 
    - 25565:25565
    restart: unless-stopped
    ulimits:
      nofile:
        soft: "65536"
        hard: "65536"
    deploy:
      resources:
        limits:
          memory: 6g
        reservations:
          memory: 2g
    environment:
      # OPS_FILE: /data/ops.json
      OPS_FILE: 'http://andeddu.local:10070/minecraft/ops.json'
      # WHITELIST_FILE: /data/whitelist.json
      WHITELIST_FILE: 'http://andeddu.local:10070/minecraft/whitelist.json'
      ENFORCE_WHITELIST: 'true'
      MEMORY: 5G
      TYPE: CURSEFORGE
      CF_SERVER_MOD: /modpacks/all_the_mods_7-0.3.20.zip
      ALLOW_NETHER: 'true'
      ANNOUNCE_PLAYER_ACHIEVEMENTS: 'true'
      MAX_PLAYERS: 20
      SNOOPER_ENABLED: 'false'
      HARDCORE: 'false'
      DIFFICULTY: easy
      GENERATE_STRUCTURES: 'true'
      MAX_BUILD_HEIGHT: 256
      SPAWN_ANIMALS: 'true'
      SPAWN_NPCS: 'true'
      SPAWN_MONSTERS: 'true'
      SPAWN_PROTECTION: 0
      VIEW_DISTANCE: 10
      MODE: survival
      PVP: 'false'
      LEVEL_TYPE: BIOMESOPLENTY
      ALLOW_FLIGHT: 'false'
      USE_MODPACK_START_SCRIPT: 'true'
      UID: 1000
      GID: 1000
      TZ: 'America/Chicago'
      EULA: 'true'
      tty: 'true'
      stdin_open: 'true'
    volumes:
    - /mnt/container_data/minecraft/curseforge/modpacks:/modpacks
    - /mnt/container_data/minecraft/curseforge/data:/data

Container logs

log output if the files exist:

[init] Looking for Feed-The-Beast / CurseForge server modpack.
[init] detected FTB, changing properties path to /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.20/server.properties
[init] server.properties already created, skipping
[init] Checking for JSON files.
[init] Setting initial memory to 5G and max to 5G
[init] Running FTB /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.20/startserver.sh in /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.2

log output if they do not already exist:

[init] Resolving type given CURSEFORGE
[init] Looking for Feed-The-Beast / CurseForge server modpack.
[init] detected FTB, changing properties path to /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.20/server.properties
[init] server.properties already created, skipping
[init] Downloading ops.json from http://andeddu.local:10070/minecraft/ops.json
[init] Downloading whitelist.json from http://andeddu.local:10070/minecraft/whitelist.json
[init] Checking for JSON files.
[init] Setting initial memory to 5G and max to 5G
[init] Running FTB /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.20/startserver.sh in /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.20
camalot commented 2 years ago

My workaround for this:

on the host machine i set up a chron job in /etc/cron.d/minecraft-whitelist-ops.job

NOTE: mc_user is an account on the host machine that has permission to the whitelist script

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/mnt/container_data/minecraft/curseforge/data/
MAILTO=root

*/5 * * * * mc_user whitelist.sh >> /dev/null 2>&1

whitelist.sh

I pull the whitelist and ops list, and if there are changes, I use rcon to reload the whitelist.

#!/bin/env bash
# data directory on the host
data_dir="/mnt/container_data/minecraft/curseforge/data"
# whitelist file on the host
whitelist_file=${data_dir}/whitelist.json
# ops file on the host
opslist_file=${data_dir}/ops.json
# get the md5 of the whitelist file
wl_md5=`md5sum ${whitelist_file} | awk '{ print $1 }'`
# get the md5 of the ops file
ops_md5=`md5sum ${opslist_file} | awk '{ print $1 }'`

# get the new whitelist file
curl -X GET -s \
        --output ${whitelist_file} \
        http://andeddu.local/minecraft/whitelist.json
# get the new ops file
curl -X GET -s \
        --output ${opslist_file} \
        http://andeddu.local/minecraft/ops.json

# get the new md5 of the whitelist file
new_wl_md5=`md5sum ${whitelist_file} | awk '{ print $1 }'`
# get the new md5 of the ops file
new_ops_md5=`md5sum ${opslist_file} | awk '{ print $1 }'`

# if the md5s don't match, then we need to update the whitelist
if [ "${wl_md5}" != "${new_wl_md5}" ] || [ "${ops_md5}" != "${new_ops_md5}" ] ; then
  echo "Whitelist updated!"
  docker run -v ${data_dir}:/data itzg/rcon-cli --config /data/.rcon-cli.yaml whitelist reload
else
  echo "Whitelist unchanged."
fi

in the container i set up 2 simlinks on the filesystem:

ln -s /data/ops.json /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.20/ops.json
ln -s /data/whitelist.json /data/FeedTheBeast/SIMPLE-SERVER-FILES-0.3.20/whitelist.json

This makes the server version of the files always be the /data/ version, and the cronjob keeps the files updated with any changes that come from the url.

The data from the url is populated via a database, but how ever you wanted to populate it would work. You could save your files on a github gist, for example and have it pull from that.

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.