s6: add some minimal logging
the root s6 call seems to be doing some logging, notably feedbackd; still don't know where the other logs are going
This commit is contained in:
parent
cbecdc4a95
commit
8bedc860ae
|
@ -1,20 +1,18 @@
|
||||||
{ lib, pkgs, ... }:
|
{ lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
|
logBase = "$HOME/.local/state/s6/logs";
|
||||||
normalizeName = name: lib.removeSuffix ".service" (lib.removeSuffix ".target" name);
|
normalizeName = name: lib.removeSuffix ".service" (lib.removeSuffix ".target" name);
|
||||||
|
|
||||||
# infers the service type from the arguments and dispatches appropriately
|
# infers the service type from the arguments and dispatches appropriately
|
||||||
genService = { name, run, depends }: if run != null then
|
genService = { name, run, depends }: let
|
||||||
genService' (normalizeName name) "longrun" depends [
|
name' = normalizeName name;
|
||||||
(pkgs.writeTextFile {
|
logDir = "${logBase}/${name'}";
|
||||||
name = "s6-${name}-run";
|
# N.B. s6-log will create the logDir. at least, if the parent dir exists (haven't tested without that)
|
||||||
destination = "/${normalizeName name}/run";
|
logger = genRun "${name'}/log" ''s6-log -- T "${logDir}"'';
|
||||||
executable = true;
|
in if run != null then
|
||||||
# TODO: consider using `makeWrapper`/`makeWrapperBin`?
|
genService' name' "longrun" depends [
|
||||||
text = ''
|
(genRun name' run)
|
||||||
#!/bin/sh
|
logger
|
||||||
exec ${run}
|
|
||||||
'';
|
|
||||||
})
|
|
||||||
]
|
]
|
||||||
else
|
else
|
||||||
# TODO: a bundle can totally have dependencies. i can't just map them *all* to contents.
|
# TODO: a bundle can totally have dependencies. i can't just map them *all* to contents.
|
||||||
|
@ -33,10 +31,10 @@ let
|
||||||
# '')
|
# '')
|
||||||
# ]
|
# ]
|
||||||
# )
|
# )
|
||||||
genService' (normalizeName name) "bundle" [] [
|
genService' name' "bundle" [] [
|
||||||
(pkgs.writeTextFile {
|
(pkgs.writeTextFile {
|
||||||
name = "s6-${name}-contents";
|
name = "s6-${name'}-contents";
|
||||||
destination = "/${normalizeName name}/contents";
|
destination = "/${name'}/contents";
|
||||||
text = lib.concatStringsSep "\n" (builtins.map normalizeName depends);
|
text = lib.concatStringsSep "\n" (builtins.map normalizeName depends);
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
@ -58,6 +56,17 @@ let
|
||||||
depends;
|
depends;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
genRun = serviceName: shellCommand: pkgs.writeTextFile {
|
||||||
|
name = "s6-${serviceName}-run";
|
||||||
|
destination = "/${serviceName}/run";
|
||||||
|
executable = true;
|
||||||
|
# TODO: consider using `makeWrapper`/`makeBinaryWrapper`?
|
||||||
|
text = ''
|
||||||
|
#!/bin/sh
|
||||||
|
exec ${shellCommand} 2>&1
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
# create a directory, containing N subdirectories:
|
# create a directory, containing N subdirectories:
|
||||||
# - svc-a/
|
# - svc-a/
|
||||||
# - type
|
# - type
|
||||||
|
@ -139,37 +148,37 @@ in
|
||||||
function startS6() {
|
function startS6() {
|
||||||
local S6_TARGET="''${1:-default}"
|
local S6_TARGET="''${1:-default}"
|
||||||
|
|
||||||
local COMPILED=$HOME/.config/s6/compiled
|
local COMPILED="$HOME/.config/s6/compiled"
|
||||||
local LIVE=$HOME/.config/s6/live
|
local LIVE="$HOME/.config/s6/live"
|
||||||
local SCANDIR=$HOME/.config/s6/scandir
|
local SCANDIR="$HOME/.config/s6/scandir"
|
||||||
|
|
||||||
rm -rf $SCANDIR
|
rm -rf "$SCANDIR"
|
||||||
mkdir $SCANDIR
|
mkdir "$SCANDIR"
|
||||||
s6-svscan $SCANDIR &
|
s6-svscan "$SCANDIR" &
|
||||||
local SVSCAN=$!
|
local SVSCAN=$!
|
||||||
|
|
||||||
# the scandir is just links back into the compiled dir,
|
# the scandir is just links back into the compiled dir,
|
||||||
# so the compiled dir therefore needs to be writable:
|
# so the compiled dir therefore needs to be writable:
|
||||||
rm -rf $COMPILED
|
rm -rf "$COMPILED"
|
||||||
cp --dereference -R $COMPILED-static $COMPILED
|
cp --dereference -R "$COMPILED-static" "$COMPILED"
|
||||||
chmod -R 0700 $COMPILED
|
chmod -R 0700 "$COMPILED"
|
||||||
|
|
||||||
s6-rc-init -c $COMPILED -l $LIVE -d $SCANDIR
|
s6-rc-init -c "$COMPILED" -l "$LIVE" -d "$SCANDIR"
|
||||||
|
|
||||||
# echo default: deps
|
|
||||||
# s6-rc-db -c $COMPILED contents default
|
|
||||||
# echo graphical-session: deps
|
|
||||||
# s6-rc-db -c $COMPILED contents graphical-session
|
|
||||||
|
|
||||||
if [ -n "$S6_TARGET" ]; then
|
if [ -n "$S6_TARGET" ]; then
|
||||||
s6-rc -l $LIVE start "$S6_TARGET"
|
s6-rc -l "$LIVE" start "$S6_TARGET"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "s6 initialized: Ctrl+C to stop"
|
echo 's6 initialized: Ctrl+C to stop'
|
||||||
wait $SVSCAN
|
wait "$SVSCAN"
|
||||||
|
}
|
||||||
|
function startS6WithLogging() {
|
||||||
|
# TODO: might not want to create log dir here: move to nix fs/persistence.
|
||||||
|
mkdir -p "${logBase}"
|
||||||
|
startS6 2>&1 | tee /dev/stderr | s6-log -- T "${logBase}"
|
||||||
}
|
}
|
||||||
|
|
||||||
primarySessionCommands+=('startS6 &')
|
primarySessionCommands+=('startS6WithLogging &')
|
||||||
'';
|
'';
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue
Block a user