commit 635590d37a31584557785c7471dfce3bf248db2e
parent 17630f26782895c7b66ec132e0ee4894da2c0d69
Author: Daniel Barlow <dan@telent.net>
Date: Wed, 18 Sep 2024 22:14:34 +0100
implement log shipping config
to use this, you need config like for example
+ logging.shipping = {
+ enable = true;
+ service = longrun {
+ name = "ship-logs";
+ run = let path = lib.makeBinPath (with pkgs; [ s6 s6-networking s6 execline ]);
+ in ''
+ PATH=${path}:$PATH
+ s6-ipcserver -1 ${config.logging.shipping.socket} \
+ s6-tcpclient 10.0.2.2 19612 \
+ fdmove -c 1 7 cat
+ '';
+ };
+ };
but I think we can reduce the noise a bit if we use an s6-rc pipeline
with an s6-ipcserver on one side and and a (whatever the user wants)
on the other
Diffstat:
1 file changed, 37 insertions(+), 9 deletions(-)
diff --git a/modules/s6/default.nix b/modules/s6/default.nix
@@ -10,6 +10,7 @@ let
inherit (pkgs.pseudofile) dir symlink;
inherit (pkgs.liminix.services) oneshot bundle;
inherit (lib) mkIf mkEnableOption mkOption types;
+ cfg = config.logging;
s6-rc-db =
let
# In the default bundle we need to have all the services
@@ -110,10 +111,13 @@ let
#!${execline}/bin/execlineb -P
${execline}/bin/redirfd -w 1 /dev/null
${execline}/bin/redirfd -rnb 0 fifo
- ${if config.logshipper.enable then ''
- pipeline { ${pkgs.logshipper}/bin/logtee /run/uncaught-logs/shipping logshipper-socket-event }
- '' else ""}
- ${s6}/bin/s6-log -bpd3 -- t /run/uncaught-logs
+ ${if cfg.shipping.enable then ''
+ pipeline { ${s6}/bin/s6-log -bpd3 -- ${cfg.script} 1 }
+ pipeline { ${pkgs.logshipper}/bin/logtap ${cfg.shipping.socket} logshipper-socket-event }
+ ${s6}/bin/s6-log -- ${cfg.directory}
+ '' else ''
+ ${s6}/bin/s6-log -bpd3 -- ${cfg.script} ${cfg.directory}
+ ''}
'';
mode = "0755";
};
@@ -207,14 +211,38 @@ let
};
in {
options = {
- logshipper = {
- enable = mkEnableOption "log shipping";
- service = mkOption {
- description = "log shipper";
- type = pkgs.liminix.lib.types.service;
+ logging = {
+ shipping = {
+ enable = mkEnableOption "unix socket for log shipping";
+ socket = mkOption {
+ description = "socket pathname"; type = types.path;
+ default = "/run/.log-shipping.sock";
+ };
+ service = mkOption {
+ description = "log shipper service";
+ type = pkgs.liminix.lib.types.service;
+ };
+ };
+ script = mkOption {
+ description = "\"log script\" used by fallback s6-log process";
+ type = types.str;
+ default = "p${config.hostname} t";
+ };
+ directory = mkOption {
+ description = "default log directory";
+ default = "/run/log";
+ type = types.path;
};
};
};
+ imports = [
+ ( {config, pkgs, lib, ...}:
+ let cfg = config.logging;
+ in mkIf cfg.shipping.enable {
+ services.${cfg.shipping.service.name} = cfg.shipping.service;
+ }
+ )];
+
config = {
filesystem = dir {
etc = dir {