add service name to log lines

This commit is contained in:
Daniel Barlow 2023-03-04 23:08:25 +00:00
parent 5427456c21
commit a8cb872859
4 changed files with 50 additions and 18 deletions

View file

@ -4,6 +4,16 @@ in
extraPkgs // {
strace = prev.strace.override { libunwind = null; };
s6 = prev.s6.overrideAttrs(o: {
patches =
(if o ? patches then o.patches else []) ++ [
(final.fetchpatch {
# add "p" directive in s6-log
url = "https://github.com/skarnet/s6/commit/ddc76841398dfd5e18b22943727ad74b880236d3.patch";
hash = "sha256-fBtUinBdp5GqoxgF6fcR44Tu8hakxs/rOShhuZOgokc=";
})];
});
dnsmasq =
let d = prev.dnsmasq.overrideAttrs(o: {
preBuild = ''

View file

@ -10,10 +10,11 @@ test -n "$contents" && for d in $contents; do
mkdir -p $out/${name}/contents.d
touch $out/${name}/contents.d/$d
done
test -n "$run" && (echo -e "$run" > $out/${name}/run)
test -n "${notification-fd}" && (echo ${notification-fd} > $out/${name}/notification-fd)
test -n "$up" && (echo -e "$up" > $out/${name}/up)
test -n "$down" && (echo -e "$down" > $out/${name}/down)
for i in run notification-fd up down consumer-for producer-for pipeline-name ; do
test -n "$(printenv $i)" && (echo "$(printenv $i)" > $out/${name}/$i)
done
( cd $out && ln -s /run/service-state/${name} ./.outputs )
for i in $out/${name}/{down,up,run} ; do test -f $i && chmod +x $i; done
true

View file

@ -1,6 +1,7 @@
{
stdenvNoCC
, s6-rc
, s6
, lib
, busybox
, callPackage
@ -12,6 +13,7 @@ let
output = service: name: "/run/service-state/${service.name}/${name}";
serviceScript = commands : ''
#!${busybox}/bin/sh
exec 2>&1
. ${serviceFns}
${commands}
'';
@ -23,17 +25,23 @@ let
, down ? null
, outputs ? []
, notification-fd ? null
, producer-for ? null
, consumer-for ? null
, pipeline-name ? null
, dependencies ? []
, contents ? []
} @ args: stdenvNoCC.mkDerivation {
# we use stdenvNoCC to avoid generating derivations with names
# like foo.service-mips-linux-musl
inherit name serviceType up down run notification-fd;
buildInputs = dependencies ++ contents;
dependencies = builtins.map (d: d.name) dependencies;
contents = builtins.map (d: d.name) contents;
builder = ./builder.sh;
};
, buildInputs ? []
} @ args:
stdenvNoCC.mkDerivation {
# we use stdenvNoCC to avoid generating derivations with names
# like foo.service-mips-linux-musl
inherit name serviceType up down run notification-fd
producer-for consumer-for pipeline-name;
buildInputs = buildInputs ++ dependencies ++ contents;
dependencies = builtins.map (d: d.name) dependencies;
contents = builtins.map (d: d.name) contents;
builder = ./builder.sh;
};
longrun = {
name
@ -41,10 +49,23 @@ let
, outputs ? []
, notification-fd ? null
, dependencies ? []
} @ args: service (args //{
serviceType = "longrun";
run = serviceScript run;
});
, ...
} @ args:
let logger = service {
serviceType = "longrun";
name = "${name}-log";
run = serviceScript "${s6}/bin/s6-log -d 10 -- p${name} 1";
notification-fd = 10;
consumer-for = name;
pipeline-name = "${name}-pipeline";
};
in service (args // {
buildInputs = [ logger ];
serviceType = "longrun";
run = serviceScript run;
producer-for = "${name}-log";
});
oneshot = {
name
, up

View file

@ -43,7 +43,7 @@ in rec {
imports = [
./modules/wlan.nix
./modules/tftpboot.nix
./modules/flashable.nix
# ./modules/flashable.nix
];
kernel = {