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.
127 lines
5.2 KiB
Nix
127 lines
5.2 KiB
Nix
# `vmTests.<system>.container-deferred-start`: a service container whose daemon
|
|
# takes longer to start than the container's one-minute start limit, with and
|
|
# without the daemon named in `services.hyperhive.swarmContainer.startAfterReady`
|
|
# (../container-modules/swarm-container.nix). The daemon stands in for tuwunel:
|
|
# a `Type=notify` unit wanted by `multi-user.target` whose start, a pause of 90 s
|
|
# before it reports ready, is longer than the limit.
|
|
#
|
|
# What it pins:
|
|
# - `old`, the daemon in the boot as nixpkgs ships it: the container's start
|
|
# job fails with `start operation timed out`, which is what pr1ma's
|
|
# homeserver does at every attempt (the control);
|
|
# - `new`, the daemon named in `startAfterReady`: the container's start job
|
|
# ends inside the limit with the daemon still `activating`, the daemon is
|
|
# `active` once its pause is over, and the container's unit was never
|
|
# restarted;
|
|
# - a unit that depends on the daemon and retries (the shape of the homeserver's
|
|
# clients) fails while the daemon starts and succeeds once it is ready.
|
|
#
|
|
# The module-eval suite pins the same wiring on the real homeserver.
|
|
{ pkgs }:
|
|
let
|
|
# What each container's daemon waits before it reports ready: past the
|
|
# container's 60 s limit with the guest's own boot added.
|
|
pause = 90;
|
|
|
|
daemon = pkgs.writeShellScript "slow-daemon" ''
|
|
${pkgs.coreutils}/bin/sleep ${toString pause}
|
|
${pkgs.systemd}/bin/systemd-notify --ready
|
|
exec ${pkgs.coreutils}/bin/sleep infinity
|
|
'';
|
|
|
|
guest =
|
|
{ deferred }:
|
|
{
|
|
imports = [ ../container-modules/swarm-container.nix ];
|
|
system.stateVersion = "26.05";
|
|
services.hyperhive.swarmContainer = {
|
|
privateNetwork = false;
|
|
startAfterReady = pkgs.lib.optional deferred "slow";
|
|
};
|
|
|
|
systemd.services.slow = {
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
Type = "notify";
|
|
NotifyAccess = "all";
|
|
ExecStart = "${daemon}";
|
|
TimeoutStartSec = "30min";
|
|
};
|
|
};
|
|
|
|
# Retries until the daemon is up, the way the homeserver's clients do.
|
|
systemd.services.client = {
|
|
wantedBy = [ "multi-user.target" ];
|
|
serviceConfig = {
|
|
Type = "oneshot";
|
|
RemainAfterExit = true;
|
|
TimeoutStartSec = 20;
|
|
ExecStart = "${pkgs.systemd}/bin/systemctl is-active --quiet slow.service";
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
};
|
|
};
|
|
};
|
|
in
|
|
pkgs.testers.runNixOSTest {
|
|
name = "container-deferred-start";
|
|
|
|
# Without this the driver allows an hour, the runner's whole job limit.
|
|
globalTimeout = 900;
|
|
|
|
nodes.host =
|
|
{ ... }:
|
|
{
|
|
containers.old = {
|
|
autoStart = false;
|
|
config = guest { deferred = false; };
|
|
};
|
|
containers.new = {
|
|
autoStart = false;
|
|
config = guest { deferred = true; };
|
|
};
|
|
};
|
|
|
|
testScript = ''
|
|
host.start()
|
|
host.wait_for_unit("multi-user.target")
|
|
|
|
def inside(name: str, cmd: str) -> str:
|
|
return host.succeed(f"nixos-container run {name} -- {cmd}").strip()
|
|
|
|
with subtest("control: a daemon in the boot that outlasts the limit fails the container's start"):
|
|
host.fail("systemctl start container@old.service")
|
|
out = host.succeed("journalctl -u container@old.service --no-pager -o cat")
|
|
assert "start operation timed out" in out, out
|
|
assert "Failed with result 'timeout'" in out, out
|
|
# The failed start leaves nothing to reset: stopping unloads the unit.
|
|
host.succeed("systemctl stop container@old.service")
|
|
state = host.execute("systemctl is-active container@old.service")[1].strip()
|
|
assert state == "inactive", state
|
|
|
|
with subtest("a daemon named in startAfterReady: the container's start ends inside the limit"):
|
|
host.succeed("systemctl start container@new.service")
|
|
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")
|
|
# 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"
|
|
|
|
with subtest("the daemon finishes its start, and the dependant recovers"):
|
|
host.wait_until_succeeds("nixos-container run new -- systemctl is-active --quiet slow.service", timeout=300)
|
|
host.wait_until_succeeds("nixos-container run new -- systemctl is-active --quiet client.service", timeout=60)
|
|
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")
|
|
restarts = host.succeed("systemctl show -p NRestarts --value container@new.service").strip()
|
|
assert restarts == "0", restarts
|
|
host.succeed("systemctl stop container@new.service")
|
|
'';
|
|
}
|