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
2 changed files with 1981 additions and 0 deletions
60
nixos/migration/ops-data.sh
Executable file
60
nixos/migration/ops-data.sh
Executable file
|
|
@ -0,0 +1,60 @@
|
|||
#!/usr/bin/env bash
|
||||
# asxpio-ops: move the data of the Debian/Docker layout to where the
|
||||
# NixOS services keep it, then let them start.
|
||||
#
|
||||
# ops-data.sh <old root>
|
||||
#
|
||||
# <old root> is /old-root after an in-place conversion (the dumps then
|
||||
# come from the last thing done before it: `restic-backup run`, which
|
||||
# leaves nothing behind, so take them by hand into
|
||||
# <old root>/var/backups/restic-stage), 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: ops-data.sh <old root>}
|
||||
stage=$src/var/backups/restic-stage
|
||||
[ ! -e /var/lib/.data-in-place ] || { echo "services already have data (/var/lib/.data-in-place exists)" >&2; exit 1; }
|
||||
for f in "$stage/pg_dumpall.sql" "$stage/forgejo-gitea.db" "$src/opt/forgejo/data/git/repositories"; do
|
||||
[ -e "$f" ] || { echo "missing: $f" >&2; exit 1; }
|
||||
done
|
||||
|
||||
echo "== Forgejo"
|
||||
fj=/var/lib/forgejo
|
||||
install -d -o git -g git -m 750 $fj $fj/data $fj/custom
|
||||
mv "$src/opt/forgejo/data/git/repositories" $fj/repositories
|
||||
mv "$src/opt/forgejo/data/git/lfs" $fj/data/lfs
|
||||
for d in "$src"/opt/forgejo/data/gitea/data/*; do
|
||||
case "$(basename "$d")" in
|
||||
home | ssh | tmp | sessions | queues | indexers) ;; # rebuilt, or the container's own
|
||||
*) mv "$d" $fj/data/ ;;
|
||||
esac
|
||||
done
|
||||
[ ! -d "$src/opt/forgejo/data/gitea/public" ] || mv "$src/opt/forgejo/data/gitea/public" $fj/custom/public
|
||||
# The online copy taken by the backup hook, not the live file
|
||||
cp "$stage/forgejo-gitea.db" $fj/data/forgejo.db
|
||||
chown -R git:git $fj
|
||||
|
||||
echo "== Garage"
|
||||
install -d -m 700 /var/lib/garage
|
||||
mv "$src/var/lib/docker/volumes/storage_garage_meta/_data" /var/lib/garage/meta
|
||||
mv "$src/var/lib/docker/volumes/storage_garage_data/_data" /var/lib/garage/data
|
||||
|
||||
echo "== Starting"
|
||||
touch /var/lib/.data-in-place
|
||||
systemctl start postgresql.service
|
||||
|
||||
echo "== Postgres"
|
||||
# The dump recreates the roles with their old passwords; postgres-roles
|
||||
# then sets the ones from sops
|
||||
runuser -u postgres -- psql -q postgres < "$stage/pg_dumpall.sql" > /var/log/pg-restore.log 2>&1 || true
|
||||
echo "errors in /var/log/pg-restore.log: $(grep -c ERROR /var/log/pg-restore.log || true)"
|
||||
systemctl restart postgres-roles.service
|
||||
|
||||
systemctl start garage.service garage-bootstrap.service forgejo.service
|
||||
|
||||
echo "== Forgejo: hooks and SSH keys for the new paths"
|
||||
forgejo-admin regenerate hooks
|
||||
forgejo-admin regenerate keys
|
||||
|
||||
echo "== Done. Check: systemctl --failed; garage status; a git clone over SSH and HTTPS"
|
||||
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