modules/users/s6-rc: add per-service logging
This commit is contained in:
parent
218072b2fe
commit
5c9c7f8073
|
@ -55,12 +55,38 @@ let
|
||||||
fsToDerivation = fs: fsItemToDerivation "/" { dir = fs; };
|
fsToDerivation = fs: fsItemToDerivation "/" { dir = fs; };
|
||||||
|
|
||||||
# infers the service type from the arguments and creates an attrset usable by `fsToDerivation`.
|
# infers the service type from the arguments and creates an attrset usable by `fsToDerivation`.
|
||||||
|
# also configures the service for logging, if applicable.
|
||||||
serviceToFs = { name, run, finish, depends }: let
|
serviceToFs = { name, run, finish, depends }: let
|
||||||
name' = normalizeName name;
|
name' = normalizeName name;
|
||||||
type = if run != null then "longrun" else "bundle";
|
type = if run != null then "longrun" else "bundle";
|
||||||
in {
|
logger = serviceToFs' {
|
||||||
|
name = "logger:${name'}";
|
||||||
|
consumerFor = name';
|
||||||
|
run = ''exec s6-log -- T p'${name'}:' "${logBase}/${name'}"'';
|
||||||
|
type = "longrun";
|
||||||
|
};
|
||||||
|
in (serviceToFs' {
|
||||||
|
inherit type run finish;
|
||||||
|
name = name';
|
||||||
|
# TODO: a bundle can have dependencies too!
|
||||||
|
depends = lib.optionals (type == "longrun") depends;
|
||||||
|
contents = maybe (type == "bundle") depends;
|
||||||
|
producerFor = maybe (type == "longrun") "logger:${name'}";
|
||||||
|
}) // (lib.optionalAttrs (type == "longrun") logger);
|
||||||
|
|
||||||
|
serviceToFs'= {
|
||||||
|
name,
|
||||||
|
type,
|
||||||
|
contents ? null,
|
||||||
|
run ? null,
|
||||||
|
depends ? [],
|
||||||
|
finish ? null,
|
||||||
|
producerFor ? null,
|
||||||
|
consumerFor ? null,
|
||||||
|
}: {
|
||||||
"${name}".dir = {
|
"${name}".dir = {
|
||||||
"type".text = type;
|
"type".text = type;
|
||||||
|
# TODO: finish and run should `exec` into their cli
|
||||||
"finish".executable = maybe (finish != null) ''
|
"finish".executable = maybe (finish != null) ''
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
${finish}
|
${finish}
|
||||||
|
@ -70,15 +96,16 @@ let
|
||||||
echo "starting: s6-${name}"
|
echo "starting: s6-${name}"
|
||||||
${run} 2>&1
|
${run} 2>&1
|
||||||
'';
|
'';
|
||||||
"contents".text = maybe (type == "bundle") (
|
"contents".text = maybe (contents != null) (
|
||||||
lib.concatStringsSep "\n" (builtins.map normalizeName depends)
|
lib.concatStringsSep "\n" (builtins.map normalizeName contents)
|
||||||
);
|
);
|
||||||
# TODO: a bundle can also have dependencies
|
# TODO: a bundle can also have dependencies
|
||||||
"dependencies.d".dir = lib.optionalAttrs (type == "longrun") (
|
"dependencies.d".dir = lib.genAttrs
|
||||||
lib.genAttrs
|
|
||||||
(builtins.map normalizeName depends)
|
(builtins.map normalizeName depends)
|
||||||
(dep: { text = ""; })
|
(dep: { text = ""; })
|
||||||
);
|
;
|
||||||
|
"consumer-for".text = maybe (consumerFor != null) consumerFor;
|
||||||
|
"producer-for".text = maybe (producerFor != null) producerFor;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user