nixos: describe both servers as NixOS systems
Start of the move from Ansible to NixOS. Services run as native NixOS services where nixpkgs has a module and as Podman containers otherwise; there is no Docker. Shared: users with their Debian UIDs, SSH with the Ansible role's crypto settings, nftables firewall, WireGuard (ops is the hub), sops-nix secrets per host, the restic backup script with its schedule and retention, mail on unit failure. asxpio-services: Xray, SillyTavern, Minecraft (Paper) and the ACME forwarder natively; XMPP stays in containers because the server is a custom build. asxpio-ops: Postgres, Garage and Forgejo natively. Roles, buckets, keys and grants move here from the storage repo's init scripts. Services that own data wait for /var/lib/.data-in-place, so an install never creates empty state where a restore is about to land. migration/*-data.sh move the Debian-era data into the new layout. hosts/rehearsal turns the two hosts into a test pair with its own keys and dummy secrets. Everything here ran there, Postgres, Garage, Forgejo, Minecraft and SillyTavern on a restored copy of production data. Three differences from the containers showed up and are handled: Garage rejects a 0440 credential file, Geyser needs libcrypto and netlink, SillyTavern ignores the module's listen flags. Production is untouched: both servers still run Debian under Ansible. Assisted-by: Claude:fable-5-2
This commit is contained in:
parent
c51522d371
commit
be68c5adef
1 changed files with 1981 additions and 0 deletions
60
nixos/migration/services-data.sh
Executable file
60
nixos/migration/services-data.sh
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
# asxpio-services: move the data of the Debian/Docker layout to where the
|
||||
# NixOS services keep it, then let them start.
|
||||
#
|
||||
# services-data.sh <old root>
|
||||
#
|
||||
# <old root> is /old-root after an in-place conversion, or the target of
|
||||
# a restic restore. Moves within one filesystem, so it is quick; run it
|
||||
# once, as root, on a host whose services are still waiting for
|
||||
# /var/lib/.data-in-place.
|
||||
set -euo pipefail
|
||||
|
||||
src=${1:?usage: services-data.sh <old root>}
|
||||
vols=$src/var/lib/docker/volumes
|
||||
[ ! -e /var/lib/.data-in-place ] || { echo "services already have data (/var/lib/.data-in-place exists)" >&2; exit 1; }
|
||||
for f in "$src/opt/minecraft/world" "$src/opt/sillytavern/data" "$src/opt/xmpp/state" "$vols/xmpp_database/_data"; do
|
||||
[ -e "$f" ] || { echo "missing: $f" >&2; exit 1; }
|
||||
done
|
||||
|
||||
echo "== Minecraft"
|
||||
rm -rf /var/lib/minecraft
|
||||
mv "$src/opt/minecraft" /var/lib/minecraft
|
||||
rm -f /var/lib/minecraft/docker-compose.yml
|
||||
chown -R minecraft:minecraft /var/lib/minecraft
|
||||
|
||||
echo "== SillyTavern"
|
||||
install -d -o sillytavern -g sillytavern -m 750 /var/lib/SillyTavern
|
||||
rm -rf /var/lib/SillyTavern/data
|
||||
mv "$src/opt/sillytavern/data" /var/lib/SillyTavern/data
|
||||
chown -R sillytavern:sillytavern /var/lib/SillyTavern
|
||||
|
||||
echo "== XMPP"
|
||||
install -d -m 755 /opt/xmpp
|
||||
rm -rf /opt/xmpp/state
|
||||
mv "$src/opt/xmpp/state" /opt/xmpp/state
|
||||
for v in xmpp_database xmpp_tackygram; do
|
||||
podman volume exists $v || podman volume create $v >/dev/null
|
||||
dst=$(podman volume inspect $v --format '{{.Mountpoint}}')
|
||||
rm -rf "$dst"
|
||||
mv "$vols/$v/_data" "$dst"
|
||||
done
|
||||
# The online copy taken by the backup hook, if this is a restore
|
||||
stage=$src/var/backups/restic-stage/ejabberd.sqlite
|
||||
db=$(podman volume inspect xmpp_database --format '{{.Mountpoint}}')/ejabberd.sqlite
|
||||
if [ -f "$stage" ]; then
|
||||
cp "$stage" "$db.new"
|
||||
chown --reference="$db" "$db.new"
|
||||
chmod --reference="$db" "$db.new"
|
||||
mv "$db.new" "$db"
|
||||
fi
|
||||
|
||||
echo "== Starting"
|
||||
touch /var/lib/.data-in-place
|
||||
systemctl start minecraft-server.service sillytavern.service
|
||||
for u in podman-xmpp-ejabberd podman-xmpp-apushd podman-xmpp-tackygram; do
|
||||
# Not enabled on a rehearsal host: it would be a second asxp.io
|
||||
if systemctl is-enabled -q $u.service 2>/dev/null; then systemctl start $u.service; else echo "left stopped: $u"; fi
|
||||
done
|
||||
|
||||
echo "== Done. Check: systemctl --failed; the Minecraft log reaches Done; SillyTavern on :8000; an XMPP login"
|
||||
Loading…
Reference in a new issue