nixos: containers come back after a reboot; ops-data.sh fixes
All checks were successful
nixos / nixos (push) Successful in 44s
All checks were successful
nixos / nixos (push) Successful in 44s
Found by rehearsing the ops conversion on a fresh test server with last night's backup: - After a reboot the app containers stayed stopped. Docker restarted them; Podman does so only through podman-restart.service, which it ships but does not enable. Enable it; on ops it waits for the app networks, Postgres and Garage. - ops-data.sh: a fresh NixOS has no /opt, so moving the app directories failed; and NixOS creates an empty /var/lib/forgejo/repositories at boot, so the repositories were moved into it, one level too deep. Every part now creates its target, replaces what is empty and skips what already moved, so an interrupted run can be resumed. - `forgejo admin regenerate hooks` is gone in Forgejo 17, which gives git its own hooks on every push; a push to a restored repository works with the old hook files in place. Drop the call. - The rehearsal ops host does not push XMPP certificates: there is no services host behind 10.10.0.20 on the test network. Assisted-by: Claude:opus-5-5
This commit is contained in:
parent
f49dd72172
commit
2ca56d595c
4 changed files with 49 additions and 9 deletions
|
|
@ -21,6 +21,21 @@ in
|
|||
# at start only
|
||||
systemd.services.podman.restartTriggers = [ hosts ];
|
||||
|
||||
# After a reboot the apps come back once their networks, database and
|
||||
# object store are there
|
||||
systemd.services.podman-restart = {
|
||||
after = [
|
||||
"podman-network-traefik.service"
|
||||
"podman-network-storage.service"
|
||||
"postgresql.service"
|
||||
"garage.service"
|
||||
];
|
||||
wants = [
|
||||
"podman-network-traefik.service"
|
||||
"podman-network-storage.service"
|
||||
];
|
||||
};
|
||||
|
||||
# `docker compose up --build` (vhpbot-prod builds on the host) starts
|
||||
# BuildKit in a privileged container
|
||||
asxpio.security.containers."buildx_buildkit_.*" = [ "privileged" ];
|
||||
|
|
|
|||
|
|
@ -32,6 +32,9 @@
|
|||
asxpio.alertEmail = "nobody@example.invalid";
|
||||
services.grafana.settings.smtp.enabled = lib.mkForce false;
|
||||
systemd.timers.crawler-alert.enable = false;
|
||||
# No services host behind 10.10.0.20 on the test network
|
||||
systemd.paths.xmpp-cert-sync.enable = false;
|
||||
systemd.timers.xmpp-cert-sync.enable = false;
|
||||
systemd.timers.crawler-weekly.enable = false;
|
||||
services.loki.configuration = {
|
||||
# No Object Storage keys here: everything on local disk
|
||||
|
|
|
|||
|
|
@ -15,30 +15,40 @@ 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
|
||||
for f in "$stage/pg_dumpall.sql" "$stage/forgejo-gitea.db"; do
|
||||
[ -e "$f" ] || { echo "missing: $f" >&2; exit 1; }
|
||||
done
|
||||
# Each part moves what is still under <old root> and skips what already
|
||||
# moved, so an interrupted run can simply be started again.
|
||||
|
||||
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
|
||||
if [ -d "$src/opt/forgejo/data/git/repositories" ]; then
|
||||
rm -rf $fj/repositories
|
||||
mv "$src/opt/forgejo/data/git/repositories" $fj/repositories
|
||||
fi
|
||||
[ ! -d "$src/opt/forgejo/data/git/lfs" ] || { rm -rf $fj/data/lfs; mv "$src/opt/forgejo/data/git/lfs" $fj/data/lfs; }
|
||||
[ -d $fj/repositories ] || { echo "missing: Forgejo repositories" >&2; exit 1; }
|
||||
for d in "$src"/opt/forgejo/data/gitea/data/*; do
|
||||
[ -e "$d" ] || continue
|
||||
case "$(basename "$d")" in
|
||||
home | ssh | tmp | sessions | queues | indexers) ;; # rebuilt, or the container's own
|
||||
*) mv "$d" $fj/data/ ;;
|
||||
*) rm -rf "$fj/data/$(basename "$d")"; mv "$d" $fj/data/ ;;
|
||||
esac
|
||||
done
|
||||
[ ! -d "$src/opt/forgejo/data/gitea/public" ] || mv "$src/opt/forgejo/data/gitea/public" $fj/custom/public
|
||||
[ ! -d "$src/opt/forgejo/data/gitea/public" ] || { rm -rf $fj/custom/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
|
||||
for part in meta data; do
|
||||
v="$src/var/lib/docker/volumes/storage_garage_$part/_data"
|
||||
[ ! -d "$v" ] || { rm -rf /var/lib/garage/$part; mv "$v" /var/lib/garage/$part; }
|
||||
[ -d /var/lib/garage/$part ] || { echo "missing: Garage $part" >&2; exit 1; }
|
||||
done
|
||||
|
||||
echo "== Traefik"
|
||||
install -d -o traefik -g traefik -m 700 /var/lib/traefik
|
||||
|
|
@ -65,6 +75,7 @@ if [ -f "$vols/monitoring_grafana-data/_data/grafana.db" ]; then
|
|||
fi
|
||||
|
||||
echo "== App stacks (compose file and .env each; CI deploys them later)"
|
||||
install -d -m 755 /opt
|
||||
for app in asxpio datacenterbingo blog czsk vhpbot-prod vhpbot-dev; do
|
||||
[ -d "$src/opt/$app" ] || continue
|
||||
rm -rf "/opt/$app"; mv "$src/opt/$app" "/opt/$app"
|
||||
|
|
@ -85,8 +96,9 @@ systemctl restart postgres-roles.service
|
|||
|
||||
systemctl start garage.service garage-bootstrap.service forgejo.service traefik.service
|
||||
|
||||
echo "== Forgejo: hooks and SSH keys for the new paths"
|
||||
forgejo-admin regenerate hooks
|
||||
echo "== Forgejo: SSH keys file for the new paths"
|
||||
# The repositories' own hook files still name the container's binary;
|
||||
# Forgejo 17 gives git its own hooks on every push, so they are unused.
|
||||
forgejo-admin regenerate keys
|
||||
|
||||
echo "== App stacks: images again (Docker's image store does not carry over)"
|
||||
|
|
|
|||
|
|
@ -21,6 +21,16 @@
|
|||
};
|
||||
virtualisation.oci-containers.backend = "podman";
|
||||
|
||||
# Containers started outside systemd (compose stacks, `docker run`) come
|
||||
# back after a reboot only through this unit, which Podman ships but
|
||||
# does not enable: the Docker daemon used to do it. It starts every
|
||||
# container whose restart policy says so (always, unless-stopped).
|
||||
systemd.services.podman-restart = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network-online.target" ];
|
||||
wants = [ "network-online.target" ];
|
||||
};
|
||||
|
||||
environment.systemPackages = [ pkgs.docker-client ];
|
||||
# `podman` talks to the same system Podman too, for every admin without
|
||||
# sudo (they are in group podman, which owns the socket); otherwise it
|
||||
|
|
|
|||
Loading…
Reference in a new issue