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.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";
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";
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 {