Files
deploy_home/ansible/roles/podman/templates/zomboid/world-reset.sh.j2
T
Bastian de BylandClaude Opus 5 1c467b1a76 fix: stop the world wipe taking the world settings with it
A wipe was quietly turning a Sophie world into an Apocalypse one. 139 sandbox
values had reverted -- loot rates from 0.35 back to 0.9, ranged weapons and ammo
to 2.0, CharacterFreePoints from 0 to 60 -- and ten of Sophie's mod-added
options had vanished entirely.

The reset script was not deleting the settings. PZ reads
Server/<name>_SandboxVars.lua only when it creates a world, and then writes the
running world's settings back over that same file. The file is an output, not an
input. So once any world came up with defaults, the server stamped those defaults
into the file, and every wipe afterwards regenerated from them -- inheriting the
corruption rather than causing it, and with no way back out on its own. The same
shape as the admin-password deadlock.

The intended settings now live in config-template/, which the server has no
reason to touch, and a wipe restores Server/<name>_{SandboxVars,spawnregions,
spawnpoints}.lua from there before restarting. That is also the file to hand-edit
when changing the world: edit the template, wipe, and the new world has the edits.

Verified by wiping: 139 differences before, 0 after. The server still rewrites
the live file on boot -- 996 keys become 1061 as it adds newer options -- but
every Sophie value survives that now.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-26 22:55:06 -04:00

81 lines
3.0 KiB
Django/Jinja

#!/bin/bash
# Zomboid World Reset Script
# Triggered by systemd path unit when discord bot requests reset
set -e
LOGFILE="{{ podman_home }}/.local/share/volumes/zomboid/logs/world-reset.log"
TRIGGER_FILE="{{ podman_home }}/.local/share/volumes/gregtime/data/zomboid-reset.trigger"
SERVER_NAME="{{ zomboid_server_name }}"
SAVES_PATH="{{ podman_home }}/.local/share/volumes/zomboid/data/Saves/Multiplayer/${SERVER_NAME}"
DB_PATH="{{ podman_home }}/.local/share/volumes/zomboid/data/db/${SERVER_NAME}.db"
log() {
local msg="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
echo "$msg"
# stdout is already captured by the journal; the file is a convenience.
# Never let it be fatal -- an unwritable log used to abort the whole wipe
# on the very first line, under set -e.
echo "$msg" >> "$LOGFILE" 2>/dev/null || true
}
# Ensure XDG_RUNTIME_DIR is set for systemctl --user
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
log "World reset triggered"
# Read requester info from trigger file if available
# Note: Must use podman unshare because file is owned by container's UID (232071)
if podman unshare test -f "$TRIGGER_FILE"; then
REQUESTER=$(podman unshare cat "$TRIGGER_FILE")
log "Requested by: $REQUESTER"
podman unshare rm -f "$TRIGGER_FILE"
fi
# Stop server
log "Stopping zomboid service..."
systemctl --user stop zomboid.service || true
sleep 5
# Delete world (using podman unshare to work within user namespace)
log "Deleting world saves at: $SAVES_PATH"
if [[ -d "$SAVES_PATH" ]]; then
podman unshare rm -rf "$SAVES_PATH"
log "World saves deleted"
else
log "No world saves found at $SAVES_PATH"
fi
# Delete player database
log "Deleting player database at: $DB_PATH"
if [[ -f "$DB_PATH" ]]; then
podman unshare rm -f "$DB_PATH"
log "Player database deleted"
else
log "No database found at $DB_PATH"
fi
# Restore the intended world settings before the server regenerates.
#
# Without this the wipe silently changes the game. PZ writes the running world's
# settings back over Server/<name>_SandboxVars.lua, so by the time we delete the
# save that file already describes the world we are throwing away -- and if that
# world had defaults, the replacement inherits them. Restoring from the canonical
# copy is what makes a wipe reset the world and keep the settings.
CONFIG_TEMPLATE="{{ podman_home }}/.local/share/volumes/zomboid/config-template"
SERVER_DIR="{{ podman_home }}/.local/share/volumes/zomboid/data/Server"
for f in SandboxVars spawnregions spawnpoints; do
if [[ -f "${CONFIG_TEMPLATE}/${f}.lua" ]]; then
podman unshare cp "${CONFIG_TEMPLATE}/${f}.lua" "${SERVER_DIR}/${SERVER_NAME}_${f}.lua"
log "Restored ${SERVER_NAME}_${f}.lua from canonical config"
else
log "WARNING: no canonical ${f}.lua; the new world will inherit whatever the server last wrote"
fi
done
# Start server
log "Starting zomboid service..."
systemctl --user start zomboid.service
log "World reset complete - new world will generate on first connection"