From c4074e8dbc9e184e92315d9c7913e7f4d45f49e0 Mon Sep 17 00:00:00 2001 From: The_miro Date: Thu, 6 Aug 2026 00:42:42 +0200 Subject: [PATCH] Repair prior state on redeploy instead of tripping over it A redeploy onto a host where earlier runs failed partway had no way to recover: the obsolete minecraft.socket stayed, a hand-made `systemctl edit` drop-in kept overriding ExecStart, units sat in a failed state, and a stale FIFO lingered. mc-service-setup.sh now clears that up front: stops both services, removes the socket unit, moves any minecraft.service.d / packwiz-http.service.d drop-in aside with a timestamp (moved, not deleted, in case one was deliberate), removes stale FIFOs at both the old and current paths, resets failed state and reloads. It also gives the pack and the generated guides back to the admin user, undoing the blanket chown an earlier version applied on every run. START_SERVER now defaults to yes, so unpacking the zip and running install.sh ends with a running server. Co-Authored-By: Claude Opus 5 --- deploy.conf.example | 2 +- mc-service-setup.sh | 49 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/deploy.conf.example b/deploy.conf.example index d7616eb..4e19ce8 100644 --- a/deploy.conf.example +++ b/deploy.conf.example @@ -30,5 +30,5 @@ XMS="10G" ACCEPT_EULA="no" # --- optional --------------------------------------------------------------- -START_SERVER="no" # yes to start Minecraft at the end +START_SERVER="yes" # no to leave Minecraft stopped CAP_ZFS_ARC="2147483648" # bytes; empty to leave ARC alone diff --git a/mc-service-setup.sh b/mc-service-setup.sh index 203c2f3..3baa8af 100755 --- a/mc-service-setup.sh +++ b/mc-service-setup.sh @@ -62,6 +62,39 @@ done || die "-H wants a port between 1 and 65535, got: $HTTP_PORT" [ "$HTTP_PORT" != "$PORT" ] || die "the HTTP port and the Minecraft port cannot both be $PORT" +# --------------------------------------------------------------- cleanup ---- + +# Re-running has to repair whatever an earlier, partly-applied run left behind, +# not trip over it. Everything here is safe when there is nothing to clean. +info "clearing previous service state" + +systemctl stop minecraft.service packwiz-http.service >/dev/null 2>&1 || true + +# The old socket unit could never work: SELinux denies init_t read/write on a +# var_run_t fifo_file, so systemd could not open the FIFO. +if [ -e "$UNIT_DIR/minecraft.socket" ]; then + info "removing obsolete minecraft.socket" + systemctl disable --now minecraft.socket >/dev/null 2>&1 || true + rm -f "$UNIT_DIR/minecraft.socket" +fi + +# Drop-ins override the unit we are about to write and win silently — including +# any hand-made `systemctl edit` workaround. Move them aside rather than delete, +# in case one was deliberate. +for d in "$UNIT_DIR/minecraft.service.d" "$UNIT_DIR/packwiz-http.service.d"; do + if [ -d "$d" ]; then + bak="$d.bak.$(date +%Y%m%d%H%M%S)" + warn "moving override drop-in aside: $d -> $bak" + mv "$d" "$bak" + fi +done + +# FIFO from the old socket-unit layout, and any left by a killed run. +rm -f /run/minecraft-console /run/minecraft/console + +systemctl reset-failed minecraft.service minecraft.socket packwiz-http.service >/dev/null 2>&1 || true +systemctl daemon-reload + # ----------------------------------------------------------------- share ---- [ -d "$SHARE" ] || die "$SHARE does not exist" @@ -110,6 +143,13 @@ if [ -n "$ADMIN" ]; then chown "$ADMIN":"$MCUSER" "$SHARE" chmod 2775 "$SHARE" install -d -o "$ADMIN" -g "$MCUSER" -m 2775 "$SHARE/packs" + + # An earlier version chowned the whole share on every run, which took the + # pack and the generated guides away from the author. Give them back. + chown -R "$ADMIN":"$MCUSER" "$SHARE/packs" 2>/dev/null || true + for f in "$SHARE"/setup-*-packwiz.html; do + [ -e "$f" ] && chown "$ADMIN":"$MCUSER" "$f" 2>/dev/null || true + done warn "$ADMIN's new group membership needs a fresh login to take effect in existing shells — 'newgrp $MCUSER' works for the current one." fi @@ -287,15 +327,6 @@ fi # ----------------------------------------------------------------- units ---- -# A previous version shipped a minecraft.socket that had systemd itself open -# the FIFO. SELinux denies init_t read/write on a var_run_t fifo_file, so that -# never worked; remove it if it is still around. -if [ -e "$UNIT_DIR/minecraft.socket" ]; then - info "removing obsolete minecraft.socket" - systemctl disable --now minecraft.socket >/dev/null 2>&1 || true - rm -f "$UNIT_DIR/minecraft.socket" -fi - info "writing $UNIT_DIR/minecraft.service" cat > "$UNIT_DIR/minecraft.service" <