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 // { extraPkgs // {
strace = prev.strace.override { libunwind = null; }; 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 = dnsmasq =
let d = prev.dnsmasq.overrideAttrs(o: { let d = prev.dnsmasq.overrideAttrs(o: {
preBuild = '' preBuild = ''

View file

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

View file

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

View file

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