asxpio-services is to move from Debian with Docker to NixOS with Podman. This is the target system; nothing is switched over yet. One flake holds what was spread over cloud-init, Ansible roles and hand-made units: network and WireGuard, users and SSH restrictions, firewall, the weekly image prune, and the four container stacks (Paper and Fossils Minecraft, SillyTavern, the Forgejo runner), each as a systemd unit under Podman. The runner keeps running as a container and starts jobs through Podman's Docker-compatible socket. Secrets (WireGuard keys, RCON and CurseForge keys) are encrypted with sops for the admin's age key and the server's SSH host key, so the repository holds no plaintext secret and CI needs none of them. Containers that own data wait for /opt/.restored. On a freshly installed disk a game server would otherwise generate a new world exactly where the restore is about to land. Tried on a throwaway server (.#rehearsal): install with nixos-anywhere keeping a given host key, secret decryption, all stacks, a real Paper server stopping with a full save, what CI jobs need from the engine (short image names, the nix-store volume, service containers by name, a kaniko build, the socket inside a job), an update over SSH and a reboot. migration/ has the scripts that move the data through object storage, and a workflow builds the system on every push and switches the host on main. Assisted-by: Claude:fable-5-2
35 lines
1.4 KiB
Bash
35 lines
1.4 KiB
Bash
#!/bin/sh
|
|
# Mirrors whitelist, ops and ban lists from the Paper server into the
|
|
# Fossils server and tells it to reload them over RCON.
|
|
apk add --no-cache python3 >/dev/null
|
|
cat > /rcon.py <<'PY'
|
|
import socket, struct, sys, os
|
|
host, port, pw, cmd = os.environ["RCON_HOST"], 25575, os.environ["RCON_PASSWORD"], sys.argv[1]
|
|
def pkt(i, t, b): p = struct.pack("<ii", i, t) + b.encode() + b"\x00\x00"; return struct.pack("<i", len(p)) + p
|
|
def recv(s):
|
|
ln = struct.unpack("<i", s.recv(4))[0]; d = b""
|
|
while len(d) < ln: d += s.recv(ln - len(d))
|
|
return struct.unpack("<ii", d[:8])[0], d[8:-2].decode(errors="replace")
|
|
s = socket.create_connection((host, port), timeout=5)
|
|
s.send(pkt(1, 3, pw))
|
|
rid, _ = recv(s)
|
|
if rid == -1: print("auth failed"); sys.exit(1)
|
|
s.send(pkt(2, 2, cmd))
|
|
_, out = recv(s); print(out)
|
|
PY
|
|
echo "[wlsync] started, interval=${INTERVAL}s"
|
|
while true; do
|
|
for f in whitelist.json ops.json banned-players.json banned-ips.json; do
|
|
if [ -f /src/$f ] && ! cmp -s /src/$f /dst/$f 2>/dev/null; then
|
|
cp /src/$f /dst/$f
|
|
echo "[wlsync] copied $f"
|
|
case $f in
|
|
whitelist.json) CMD="whitelist reload" ;;
|
|
ops.json) CMD="reload" ;;
|
|
banned-players.json|banned-ips.json) CMD="kick @a Ban list updated" ;;
|
|
esac
|
|
python3 /rcon.py "$CMD" 2>&1 | sed 's/^/[wlsync] rcon: /' || echo "[wlsync] rcon failed"
|
|
fi
|
|
done
|
|
sleep $INTERVAL
|
|
done
|