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
3 changed files with 40 additions and 23 deletions
|
|
@ -21,8 +21,8 @@
|
|||
#
|
||||
# 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
|
||||
# the container is up without it, and a oneshot in the transaction starts it
|
||||
# `--no-block`.
|
||||
# the container is up without it, and a unit that waits for the boot to end
|
||||
# starts it `--no-block`.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
|
|
@ -53,7 +53,8 @@ in
|
|||
Names of this container's services (without `.service`) that start
|
||||
after the container's boot instead of in it. Each stops being wanted
|
||||
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,
|
||||
whatever the service's own start takes. The service keeps its own
|
||||
`TimeoutStartSec`, and whatever depends on it has to cope with a
|
||||
|
|
@ -100,18 +101,23 @@ in
|
|||
wantedBy = lib.mkForce [ ];
|
||||
})
|
||||
// {
|
||||
# Its own job ends at the enqueue, so the boot does not wait on the
|
||||
# services it starts.
|
||||
# A `--no-block` start still queues the service's start job, and the
|
||||
# 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 = {
|
||||
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" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
TimeoutStartSec = 20;
|
||||
ExecStart = "${pkgs.systemd}/bin/systemctl start --no-block ${
|
||||
lib.concatMapStringsSep " " (n: "${n}.service") cfg.startAfterReady
|
||||
}";
|
||||
};
|
||||
path = [ pkgs.systemd ];
|
||||
serviceConfig.Type = "simple";
|
||||
script = ''
|
||||
# `degraded` (a unit of the boot failed) exits 1 and is still over.
|
||||
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,
|
||||
# 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
|
||||
# a oneshot that is, with a limit of its own. The sync and the render stay
|
||||
# in the boot wait, the presence arms of the walk that finds tuwunel
|
||||
# absent from it.
|
||||
# a unit that is, with a limit of its own. A `--no-block` start still
|
||||
# queues a job and the container's start ends when the guest's queue is
|
||||
# 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";
|
||||
ok =
|
||||
let
|
||||
|
|
@ -1006,9 +1011,9 @@ let
|
|||
&& unit.wantedBy == [ ]
|
||||
&& bootWait.spanSeconds unit.serviceConfig.TimeoutStartSec == 1800
|
||||
&& starter.wantedBy == [ "multi-user.target" ]
|
||||
&& starter.serviceConfig.Type == "oneshot"
|
||||
&& starter.serviceConfig.TimeoutStartSec == 20
|
||||
&& lib.hasSuffix "/bin/systemctl start --no-block tuwunel.service" starter.serviceConfig.ExecStart
|
||||
&& starter.serviceConfig.Type == "simple"
|
||||
&& !(bootWait.holdsJob starter)
|
||||
&& 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 "swarm-container-deferred-start.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")
|
||||
assert "start operation timed out" not in out, out
|
||||
host.succeed("systemctl is-active container@new.service")
|
||||
state = inside("new", "systemctl show -p ActiveState --value slow.service")
|
||||
assert state == "activating", state
|
||||
# The guest queues the daemon's start job once its boot is over, which is
|
||||
# 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"):
|
||||
assert inside("new", "systemctl show -p ActiveState --value client.service") != "active"
|
||||
|
|
|
|||
Loading…
Reference in a new issue