fix(matrix): queue tuwunel's start after the guest's boot is over
The deferred starter was a oneshot that ran `systemctl start --no-block tuwunel` inside the boot transaction. A --no-block start still queues a start job, so the guest's job queue stayed non-empty for as long as tuwunel's start took, and the container (Type=notify, --notify-ready=yes, one minute) never reported ready and was killed at its limit. The starter is now Type=simple, so its own start job ends at the fork. It waits for `systemctl is-system-running --wait` and only then queues the service. The VM test waits for the daemon to reach `activating` instead of asserting it the moment the container's start ends.
This commit is contained in:
parent
19640f3bf8
commit
3919de6358
4 changed files with 40 additions and 23 deletions
|
|
@ -39,8 +39,10 @@ Same shape as [`gateway.md::hive-forge container shape`](../../4-implementation/
|
||||||
the journal (`tuwunel-fallocate-probe:`) and leaves the default.
|
the journal (`tuwunel-fallocate-probe:`) and leaves the default.
|
||||||
- tuwunel starts after the container is up, not during its boot. The
|
- tuwunel starts after the container is up, not during its boot. The
|
||||||
container's start job (`container@hive-matrix.service`, one minute) ends when
|
container's start job (`container@hive-matrix.service`, one minute) ends when
|
||||||
the guest's boot does, and a oneshot in the guest starts tuwunel without
|
the guest's boot does, and a unit in the guest queues tuwunel's start once
|
||||||
waiting for it. tuwunel's own start, which replays the database's
|
the boot is over, without waiting for it. (Queued during the boot, the start
|
||||||
|
job would hold the container's start for as long as tuwunel's start takes.)
|
||||||
|
tuwunel's own start, which replays the database's
|
||||||
write-ahead log from the beginning at every open, has its own limit of 30
|
write-ahead log from the beginning at every open, has its own limit of 30
|
||||||
minutes, and extends it while it reports progress. While it starts, the
|
minutes, and extends it while it reports progress. While it starts, the
|
||||||
gateway answers for the homeserver with an error, and the swarm's matrix
|
gateway answers for the homeserver with an error, and the swarm's matrix
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
#
|
#
|
||||||
# A daemon whose own start can outlast that limit (a database open that replays
|
# A daemon whose own start can outlast that limit (a database open that replays
|
||||||
# a large log) is named in `startAfterReady`: it leaves the boot transaction, so
|
# a large log) is named in `startAfterReady`: it leaves the boot transaction, so
|
||||||
# the container is up without it, and a oneshot in the transaction starts it
|
# the container is up without it, and a unit that waits for the boot to end
|
||||||
# `--no-block`.
|
# starts it `--no-block`.
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
|
|
@ -53,7 +53,8 @@ in
|
||||||
Names of this container's services (without `.service`) that start
|
Names of this container's services (without `.service`) that start
|
||||||
after the container's boot instead of in it. Each stops being wanted
|
after the container's boot instead of in it. Each stops being wanted
|
||||||
by `multi-user.target`, and `swarm-container-deferred-start.service`,
|
by `multi-user.target`, and `swarm-container-deferred-start.service`,
|
||||||
which is, starts them with `systemctl start --no-block`. The host's
|
which is, starts them with `systemctl start --no-block` once the
|
||||||
|
guest's boot is over. The host's
|
||||||
start job for the container then ends when the guest's boot does,
|
start job for the container then ends when the guest's boot does,
|
||||||
whatever the service's own start takes. The service keeps its own
|
whatever the service's own start takes. The service keeps its own
|
||||||
`TimeoutStartSec`, and whatever depends on it has to cope with a
|
`TimeoutStartSec`, and whatever depends on it has to cope with a
|
||||||
|
|
@ -100,18 +101,23 @@ in
|
||||||
wantedBy = lib.mkForce [ ];
|
wantedBy = lib.mkForce [ ];
|
||||||
})
|
})
|
||||||
// {
|
// {
|
||||||
# Its own job ends at the enqueue, so the boot does not wait on the
|
# A `--no-block` start still queues the service's start job, and the
|
||||||
# services it starts.
|
# container's start ends when the guest's job queue is empty
|
||||||
|
# (nixos-containers.nix passes `--notify-ready=yes`, and the host
|
||||||
|
# unit is `Type=notify`). So the job is queued after the boot, not
|
||||||
|
# in it: this unit is `Type=simple`, whose own start job ends at the
|
||||||
|
# fork, and it waits for the manager to leave `starting` before it
|
||||||
|
# queues the services.
|
||||||
swarm-container-deferred-start = {
|
swarm-container-deferred-start = {
|
||||||
description = "start the services that outlast the container's start limit";
|
description = "start the services that outlast the container's start limit, once its boot is over";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
serviceConfig = {
|
path = [ pkgs.systemd ];
|
||||||
Type = "oneshot";
|
serviceConfig.Type = "simple";
|
||||||
TimeoutStartSec = 20;
|
script = ''
|
||||||
ExecStart = "${pkgs.systemd}/bin/systemctl start --no-block ${
|
# `degraded` (a unit of the boot failed) exits 1 and is still over.
|
||||||
lib.concatMapStringsSep " " (n: "${n}.service") cfg.startAfterReady
|
systemctl is-system-running --wait >/dev/null || true
|
||||||
}";
|
systemctl start --no-block ${lib.concatMapStringsSep " " (n: "${n}.service") cfg.startAfterReady}
|
||||||
};
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -990,9 +990,14 @@ let
|
||||||
# the beginning every time) can outlast the container's one-minute limit,
|
# the beginning every time) can outlast the container's one-minute limit,
|
||||||
# and a start killed on it makes no progress. So tuwunel is out of the
|
# and a start killed on it makes no progress. So tuwunel is out of the
|
||||||
# guest's boot: not wanted by `multi-user.target`, started `--no-block` by
|
# guest's boot: not wanted by `multi-user.target`, started `--no-block` by
|
||||||
# a oneshot that is, with a limit of its own. The sync and the render stay
|
# a unit that is, with a limit of its own. A `--no-block` start still
|
||||||
# in the boot wait, the presence arms of the walk that finds tuwunel
|
# queues a job and the container's start ends when the guest's queue is
|
||||||
# absent from it.
|
# empty (a oneshot starter, which queued it during the boot, held the
|
||||||
|
# container's start for the daemon's 90 s in the nightly VM test), so the
|
||||||
|
# starter is `Type=simple`, holds no job, and queues the daemon only after
|
||||||
|
# `is-system-running --wait` says the boot is over. The sync and the
|
||||||
|
# render stay in the boot wait, the presence arms of the walk that finds
|
||||||
|
# tuwunel absent from it.
|
||||||
name = "the homeserver starts after the container is up, under a limit of its own, and the container's boot does not wait on it";
|
name = "the homeserver starts after the container is up, under a limit of its own, and the container's boot does not wait on it";
|
||||||
ok =
|
ok =
|
||||||
let
|
let
|
||||||
|
|
@ -1006,9 +1011,9 @@ let
|
||||||
&& unit.wantedBy == [ ]
|
&& unit.wantedBy == [ ]
|
||||||
&& bootWait.spanSeconds unit.serviceConfig.TimeoutStartSec == 1800
|
&& bootWait.spanSeconds unit.serviceConfig.TimeoutStartSec == 1800
|
||||||
&& starter.wantedBy == [ "multi-user.target" ]
|
&& starter.wantedBy == [ "multi-user.target" ]
|
||||||
&& starter.serviceConfig.Type == "oneshot"
|
&& starter.serviceConfig.Type == "simple"
|
||||||
&& starter.serviceConfig.TimeoutStartSec == 20
|
&& !(bootWait.holdsJob starter)
|
||||||
&& lib.hasSuffix "/bin/systemctl start --no-block tuwunel.service" starter.serviceConfig.ExecStart
|
&& lib.hasInfix "systemctl is-system-running --wait >/dev/null || true\nsystemctl start --no-block tuwunel.service" starter.script
|
||||||
&& !(lib.elem "tuwunel.service" booted)
|
&& !(lib.elem "tuwunel.service" booted)
|
||||||
&& lib.elem "swarm-container-deferred-start.service" booted
|
&& lib.elem "swarm-container-deferred-start.service" booted
|
||||||
&& lib.elem "swarm-matrix-appservice-sync.service" booted
|
&& lib.elem "swarm-matrix-appservice-sync.service" booted
|
||||||
|
|
|
||||||
|
|
@ -104,8 +104,12 @@ pkgs.testers.runNixOSTest {
|
||||||
out = host.succeed("journalctl -u container@new.service --no-pager -o cat")
|
out = host.succeed("journalctl -u container@new.service --no-pager -o cat")
|
||||||
assert "start operation timed out" not in out, out
|
assert "start operation timed out" not in out, out
|
||||||
host.succeed("systemctl is-active container@new.service")
|
host.succeed("systemctl is-active container@new.service")
|
||||||
state = inside("new", "systemctl show -p ActiveState --value slow.service")
|
# The guest queues the daemon's start job once its boot is over, which is
|
||||||
assert state == "activating", state
|
# just after the container's start ends.
|
||||||
|
host.wait_until_succeeds(
|
||||||
|
"test \"$(nixos-container run new -- systemctl show -p ActiveState --value slow.service)\" = activating",
|
||||||
|
timeout=60,
|
||||||
|
)
|
||||||
|
|
||||||
with subtest("the dependant fails while the daemon starts"):
|
with subtest("the dependant fails while the daemon starts"):
|
||||||
assert inside("new", "systemctl show -p ActiveState --value client.service") != "active"
|
assert inside("new", "systemctl show -p ActiveState --value client.service") != "active"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue