hive-matrix: turn off tuwunel's log preallocation on btrfs and zfs
Refs #6885
This commit is contained in:
parent
82710f4fa8
commit
7c7c94d184
3 changed files with 58 additions and 0 deletions
|
|
@ -31,6 +31,11 @@ Same shape as [`gateway.md::hive-forge container shape`](../../4-implementation/
|
||||||
`/var/lib/nixos-containers/hive-matrix/var/lib/matrix-tuwunel/`
|
`/var/lib/nixos-containers/hive-matrix/var/lib/matrix-tuwunel/`
|
||||||
survives container restart / host reboot. To wipe, destroy the
|
survives container restart / host reboot. To wipe, destroy the
|
||||||
container.
|
container.
|
||||||
|
- At each start tuwunel's unit checks which filesystem holds its database.
|
||||||
|
On btrfs or ZFS it sets `rocksdb_allow_fallocate = false` (through
|
||||||
|
`TUWUNEL_ROCKSDB_ALLOW_FALLOCATE`), because RocksDB's preallocated
|
||||||
|
write-ahead logs pin far more disk than they hold there. On any other
|
||||||
|
filesystem tuwunel's default stays.
|
||||||
|
|
||||||
## Identity vs API listener: `serverName` vs `gatewayHost`
|
## Identity vs API listener: `serverName` vs `gatewayHost`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -158,6 +158,25 @@ let
|
||||||
# the database directory under /var/lib.
|
# the database directory under /var/lib.
|
||||||
stateName = "tuwunel";
|
stateName = "tuwunel";
|
||||||
|
|
||||||
|
# tuwunel's `rocksdb_allow_fallocate` is off only where its database sits on
|
||||||
|
# a filesystem that cannot honour RocksDB's log preallocation. A swarm's
|
||||||
|
# filesystem is not known at evaluation, so the unit's `ExecStartPre` reads
|
||||||
|
# it at each start, from the same superblock magics tuwunel itself tests for
|
||||||
|
# its warning (btrfs `9123683e`, ZFS `2fc12fc1`), and writes the override
|
||||||
|
# to an environment file. tuwunel applies `TUWUNEL_*` variables over its
|
||||||
|
# config file. Anywhere else, or if `stat` fails, the file is empty and the
|
||||||
|
# default (`true`) stands.
|
||||||
|
tuwunelRuntimeDir = "/run/tuwunel";
|
||||||
|
fallocateEnvFile = "${tuwunelRuntimeDir}/fallocate.env";
|
||||||
|
fallocateProbe = pkgs.writeShellScript "tuwunel-fallocate-probe" ''
|
||||||
|
set -u
|
||||||
|
: > ${fallocateEnvFile}
|
||||||
|
magic=$(${pkgs.coreutils}/bin/stat -f -c %t /var/lib/${stateName}) || exit 0
|
||||||
|
case "$magic" in
|
||||||
|
9123683e | 2fc12fc1) echo TUWUNEL_ROCKSDB_ALLOW_FALLOCATE=false > ${fallocateEnvFile} ;;
|
||||||
|
esac
|
||||||
|
'';
|
||||||
|
|
||||||
# ── the swarm's own appservice ──────────────────────────────────────
|
# ── the swarm's own appservice ──────────────────────────────────────
|
||||||
#
|
#
|
||||||
# The homeserver's one appservice registration, and the swarm's identity on
|
# The homeserver's one appservice registration, and the swarm's identity on
|
||||||
|
|
@ -1098,6 +1117,12 @@ in
|
||||||
# Upstream's `ProtectSystem = "strict"` leaves `/run` read-only.
|
# Upstream's `ProtectSystem = "strict"` leaves `/run` read-only.
|
||||||
systemd.services.tuwunel.serviceConfig.ReadWritePaths = [ socketDir ];
|
systemd.services.tuwunel.serviceConfig.ReadWritePaths = [ socketDir ];
|
||||||
|
|
||||||
|
# The `RuntimeDirectory` is upstream's. The file is read before each
|
||||||
|
# command of the unit runs, so `ExecStartPre` writes what `ExecStart`
|
||||||
|
# sees; the `-` keeps a missing file from failing the start.
|
||||||
|
systemd.services.tuwunel.serviceConfig.ExecStartPre = [ fallocateProbe ];
|
||||||
|
systemd.services.tuwunel.serviceConfig.EnvironmentFile = [ "-${fallocateEnvFile}" ];
|
||||||
|
|
||||||
# Keeps DynamicUser=true + PrivateUsers=true intact — no
|
# Keeps DynamicUser=true + PrivateUsers=true intact — no
|
||||||
# host-side chown :tuwunel / GID-pin gymnastics needed.
|
# host-side chown :tuwunel / GID-pin gymnastics needed.
|
||||||
# See `man systemd.exec` → LoadCredential.
|
# See `man systemd.exec` → LoadCredential.
|
||||||
|
|
|
||||||
|
|
@ -945,6 +945,34 @@ let
|
||||||
&& unit.serviceConfig.Group == "gateway-nginx"
|
&& unit.serviceConfig.Group == "gateway-nginx"
|
||||||
&& lib.elem dir unit.serviceConfig.ReadWritePaths;
|
&& lib.elem dir unit.serviceConfig.ReadWritePaths;
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
# tuwunel preallocates its logs unless told otherwise, which is only right
|
||||||
|
# off btrfs and ZFS. The setting is decided when the unit starts: the
|
||||||
|
# settings carry no `rocksdb_allow_fallocate`, a probe runs before
|
||||||
|
# `ExecStart` and writes the override to a file the unit reads. The
|
||||||
|
# container keeps the default start limit: a slow database open is not
|
||||||
|
# answered with a longer one. `allow_registration` and `unix_socket_perms`
|
||||||
|
# are the presence arms: settings read through the same path.
|
||||||
|
name = "the homeserver turns log preallocation off at start, by a probe of its filesystem, and keeps the default start limit";
|
||||||
|
ok =
|
||||||
|
let
|
||||||
|
host = serviceContainersWithCi;
|
||||||
|
c = host.containers.hive-matrix;
|
||||||
|
global = c.config.services.matrix-tuwunel.settings.global;
|
||||||
|
unit = c.config.systemd.services.tuwunel;
|
||||||
|
probe = lib.head unit.serviceConfig.ExecStartPre;
|
||||||
|
in
|
||||||
|
global ? allow_registration
|
||||||
|
&& global ? unix_socket_perms
|
||||||
|
&& !(global ? rocksdb_allow_fallocate)
|
||||||
|
&& lib.length unit.serviceConfig.ExecStartPre == 1
|
||||||
|
&& unit.serviceConfig.EnvironmentFile == [ "-/run/tuwunel/fallocate.env" ]
|
||||||
|
&& unit.serviceConfig.RuntimeDirectory == "tuwunel"
|
||||||
|
&& lib.hasInfix "stat -f -c %t /var/lib/tuwunel" probe.text
|
||||||
|
&& lib.hasInfix "9123683e | 2fc12fc1) echo TUWUNEL_ROCKSDB_ALLOW_FALLOCATE=false > /run/tuwunel/fallocate.env" probe.text
|
||||||
|
&& c.timeoutStartSec == "1min"
|
||||||
|
&& startLimitOf "hive-matrix" == 60;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
# On the bridge by DHCP, with all three listeners on sockets: nothing
|
# On the bridge by DHCP, with all three listeners on sockets: nothing
|
||||||
# the bridge can dial. Every vhost location that forwards goes through
|
# the bridge can dial. Every vhost location that forwards goes through
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue