From 1f50667d366018cfa0ecef925f49261536bcec9d Mon Sep 17 00:00:00 2001 From: The_miro Date: Wed, 5 Aug 2026 22:31:23 +0200 Subject: [PATCH] Resolve NeoForge version automatically, default heap to 13G deploy.sh previously required -N and failed outright without it. It now passes -N latest by default, and mc-service-setup.sh resolves the newest stable build in the series matching the Minecraft version from the NeoForged maven (1.21.1 -> 21.1.x, 1.21 -> 21.0.x), excluding betas. Pin a version with -N to opt out. Heap defaults raised to 13G for both Xms and Xmx. README documents capping the ZFS ARC alongside it, since ARC defaults to half of RAM and would otherwise contend with a heap this size on the same box. Co-Authored-By: Claude Opus 5 --- README.md | 23 ++++++++++++++++++++++- deploy.sh | 6 +++--- mc-service-setup.sh | 39 ++++++++++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 13f0fe9..937f511 100644 --- a/README.md +++ b/README.md @@ -11,9 +11,13 @@ Everything lives on a ZFS dataset mounted at `/minecraft`. ```bash ./deploy.sh -n "Opengames" -a themiro \ -u https://games.abdelbaki.eu/mods \ - -N 21.1.72 --accept-eula + --accept-eula ``` +The NeoForge version is resolved automatically — the newest stable build in the +series matching your Minecraft version, from the NeoForged maven. Pin one with +`-N 21.1.248` if you'd rather not track latest. + Then: ```bash @@ -35,6 +39,23 @@ server address already filled in. | `mc-refresh-restart.sh` | you | Re-sync the pack after changing mods, then restart | | `build.sh` | you | Builds the release zip | +## Memory + +The heap defaults to 13 GB (`-X`/`-x` to change it). `-XX:+AlwaysPreTouch` means +the JVM commits the whole heap at startup rather than growing into it. + +On a ZFS host, cap the ARC before running a heap this large — ZFS defaults to +using up to half of RAM for cache, which will fight the JVM for the same pages: + +```bash +echo "options zfs zfs_arc_max=2147483648" | sudo tee /etc/modprobe.d/zfs.conf +sudo dracut --force && sudo reboot +``` + +That pins the ARC to 2 GB. On a 16 GB box, 13 GB heap + 2 GB ARC leaves ~1 GB +for everything else, which is tight — drop the heap to 10–11 GB if the host +does anything besides run the server. + ## Requirements - Fedora (or any systemd distro; `dnf` calls need swapping otherwise) diff --git a/deploy.sh b/deploy.sh index f338569..9a38d8f 100755 --- a/deploy.sh +++ b/deploy.sh @@ -13,8 +13,8 @@ set -euo pipefail -NAME=""; AUTHOR=""; BASEURL=""; NFVER=""; MCVER="1.21.1" -SHARE="/minecraft"; XMX="8G"; XMS="4G"; ACCEPT_EULA="" +NAME=""; AUTHOR=""; BASEURL=""; NFVER="latest"; MCVER="1.21.1" +SHARE="/minecraft"; XMX="13G"; XMS="13G"; ACCEPT_EULA="" HERE="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" die() { echo "error: $*" >&2; exit 1; } @@ -51,7 +51,7 @@ sudo -v || die "sudo is required" step "1/2 Minecraft systemd service" sudo "$HERE/mc-service-setup.sh" \ - -s "$SHARE" -A "$USER" -X "$XMX" -x "$XMS" \ + -s "$SHARE" -A "$USER" -X "$XMX" -x "$XMS" -m "$MCVER" \ ${NFVER:+-N "$NFVER"} ${ACCEPT_EULA} step "2/2 packwiz pack and player guides" diff --git a/mc-service-setup.sh b/mc-service-setup.sh index b0cfd39..125c5cd 100755 --- a/mc-service-setup.sh +++ b/mc-service-setup.sh @@ -18,9 +18,10 @@ set -euo pipefail SHARE="/minecraft" MCUSER="minecraft" -XMS="4G" -XMX="8G" -NFVER="" # set to install the NeoForge server +XMS="13G" +XMX="13G" +NFVER="" # version, or "latest" to resolve one; empty = don't install +MCVER="1.21.1" # only used to pick the matching NeoForge series ADMIN="" # human user who authors the pack on the share ACCEPT_EULA=0 UNIT_DIR="/etc/systemd/system" @@ -38,6 +39,7 @@ while [ $# -gt 0 ]; do -x|--xms) XMS="${2:-}"; shift 2 ;; -X|--xmx) XMX="${2:-}"; shift 2 ;; -N|--neoforge) NFVER="${2:-}"; shift 2 ;; + -m|--mc) MCVER="${2:-}"; shift 2 ;; -A|--admin) ADMIN="${2:-}"; shift 2 ;; --accept-eula) ACCEPT_EULA=1; shift ;; -h|--help) usage 0 ;; @@ -88,6 +90,37 @@ fi # -------------------------------------------------------------- neoforge ---- +# NeoForge versions are .., so 1.21.1 -> 21.1.x and +# 1.21 -> 21.0.x. Resolve the newest stable build in that series from the +# NeoForged maven; the [0-9]+$ anchor keeps betas out. +resolve_neoforge() { + local mc="$1" prefix rest meta + rest="${mc#1.}" + case "$rest" in + *.*) prefix="$rest" ;; + *) prefix="${rest}.0" ;; + esac + + meta="$(curl -fsSL --max-time 25 \ + https://maven.neoforged.net/releases/net/neoforged/neoforge/maven-metadata.xml 2>/dev/null)" \ + || return 1 + + printf '%s' "$meta" \ + | grep -oE '[^<]+' \ + | sed -e 's/<[^>]*>//g' \ + | grep -E "^${prefix//./\\.}\.[0-9]+$" \ + | sort -V | tail -1 +} + +if [ "$NFVER" = "latest" ]; then + info "resolving latest NeoForge for Minecraft $MCVER" + NFVER="$(resolve_neoforge "$MCVER" || true)" + [ -n "$NFVER" ] || die "could not resolve a NeoForge version for Minecraft $MCVER + Pick one manually from https://projects.neoforged.net/neoforged/neoforge + and pass it with -N ." + info "resolved NeoForge $NFVER" +fi + if [ -n "$NFVER" ]; then info "installing NeoForge $NFVER server into $SHARE" url="https://maven.neoforged.net/releases/net/neoforged/neoforge/${NFVER}/neoforge-${NFVER}-installer.jar"