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" <