start tuwunel after the container is up, under its own 30 min limit
This commit is contained in:
parent
7ae1b42fd9
commit
ba0f9c6264
1 changed files with 220 additions and 3 deletions
|
|
@ -18,7 +18,17 @@
|
|||
# a reason. It also adds the budgets of units ordered one after another by
|
||||
# `after`/`before`, and fails when the longest such chain reaches the limit (a
|
||||
# unit listed there adds 0 s) or the ordering has a cycle.
|
||||
{ config, lib, ... }:
|
||||
#
|
||||
# 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`.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.services.hyperhive.swarmContainer;
|
||||
in
|
||||
|
|
@ -35,6 +45,22 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
startAfterReady = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "tuwunel" ];
|
||||
description = ''
|
||||
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
|
||||
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
|
||||
service that is still starting.
|
||||
'';
|
||||
};
|
||||
|
||||
writesOwnResolvConf = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
|
|
@ -68,5 +94,26 @@ in
|
|||
(lib.mkIf cfg.writesOwnResolvConf {
|
||||
networking.resolvconf.enable = lib.mkForce false;
|
||||
})
|
||||
(lib.mkIf (cfg.startAfterReady != [ ]) {
|
||||
systemd.services =
|
||||
lib.genAttrs cfg.startAfterReady (_: {
|
||||
wantedBy = lib.mkForce [ ];
|
||||
})
|
||||
// {
|
||||
# Its own job ends at the enqueue, so the boot does not wait on the
|
||||
# services it starts.
|
||||
swarm-container-deferred-start = {
|
||||
description = "start the services that outlast the container's start limit";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
TimeoutStartSec = 20;
|
||||
ExecStart = "${pkgs.systemd}/bin/systemctl start --no-block ${
|
||||
lib.concatMapStringsSep " " (n: "${n}.service") cfg.startAfterReady
|
||||
}";
|
||||
};
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue