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
This commit is contained in:
Daniel Barlow 2024-09-18 22:14:34 +01:00
parent 17630f2678
commit 635590d37a
1 changed files with 37 additions and 9 deletions

View File

@ -10,6 +10,7 @@ let
inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.pseudofile) dir symlink;
inherit (pkgs.liminix.services) oneshot bundle; inherit (pkgs.liminix.services) oneshot bundle;
inherit (lib) mkIf mkEnableOption mkOption types; inherit (lib) mkIf mkEnableOption mkOption types;
cfg = config.logging;
s6-rc-db = s6-rc-db =
let let
# In the default bundle we need to have all the services # In the default bundle we need to have all the services
@ -110,10 +111,13 @@ let
#!${execline}/bin/execlineb -P #!${execline}/bin/execlineb -P
${execline}/bin/redirfd -w 1 /dev/null ${execline}/bin/redirfd -w 1 /dev/null
${execline}/bin/redirfd -rnb 0 fifo ${execline}/bin/redirfd -rnb 0 fifo
${if config.logshipper.enable then '' ${if cfg.shipping.enable then ''
pipeline { ${pkgs.logshipper}/bin/logtee /run/uncaught-logs/shipping logshipper-socket-event } pipeline { ${s6}/bin/s6-log -bpd3 -- ${cfg.script} 1 }
'' else ""} pipeline { ${pkgs.logshipper}/bin/logtap ${cfg.shipping.socket} logshipper-socket-event }
${s6}/bin/s6-log -bpd3 -- t /run/uncaught-logs ${s6}/bin/s6-log -- ${cfg.directory}
'' else ''
${s6}/bin/s6-log -bpd3 -- ${cfg.script} ${cfg.directory}
''}
''; '';
mode = "0755"; mode = "0755";
}; };
@ -207,14 +211,38 @@ let
}; };
in { in {
options = { options = {
logshipper = { logging = {
enable = mkEnableOption "log shipping"; shipping = {
service = mkOption { enable = mkEnableOption "unix socket for log shipping";
description = "log shipper"; socket = mkOption {
type = pkgs.liminix.lib.types.service; 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 = { config = {
filesystem = dir { filesystem = dir {
etc = dir { etc = dir {