From ab262689e978adaa15a983056b2573f1785bbb8e Mon Sep 17 00:00:00 2001 From: Olaf Targowski Date: Sat, 25 Nov 2023 21:24:52 +0100 Subject: [PATCH] [nix] Allow directing services' stdout to logfiles --- flake.lock | 32 +++++++++++++++++++++++++------- nix/module/worker.nix | 13 +++++++++++++ nix/module/workersd.nix | 14 +++++++++++++- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/flake.lock b/flake.lock index 5bb23b7..42c1c75 100644 --- a/flake.lock +++ b/flake.lock @@ -8,11 +8,11 @@ ] }, "locked": { - "lastModified": 1698517557, - "narHash": "sha256-Fi025V9wuNesFeM7HRi02HPnOeuVS2pi3rdDYafH1vY=", + "lastModified": 1700943598, + "narHash": "sha256-zTY0h/7Z3oMFIUSj3ZQ/h1dvruAGwEAQF/24TI7VSGA=", "owner": "Stowarzyszenie-Talent", "repo": "filetracker", - "rev": "d1e1ab24fe6d83095bb0dc4bcfa2babe1972db4c", + "rev": "aa5e2c2397f68e12ba966d5665ec9a08b552d3bd", "type": "github" }, "original": { @@ -22,12 +22,15 @@ } }, "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1676283394, - "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", "owner": "numtide", "repo": "flake-utils", - "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", "type": "github" }, "original": { @@ -38,7 +41,7 @@ }, "flake-utils_2": { "inputs": { - "systems": "systems" + "systems": "systems_2" }, "locked": { "lastModified": 1694529238, @@ -91,6 +94,21 @@ "repo": "default", "type": "github" } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } } }, "root": "root", diff --git a/nix/module/worker.nix b/nix/module/worker.nix index 476ddfc..d8d6182 100644 --- a/nix/module/worker.nix +++ b/nix/module/worker.nix @@ -55,6 +55,16 @@ description = "The amount of memory (in megabytes) this worker will use"; type = lib.types.ints.unsigned; }; + + separateStdoutFromJournal = lib.mkOption { + default = false; + description = '' + Redirect sioworker's stdout to a file in /var/log/sio2. + You have to ensure that directory exists and rotate the logs yourself, + unless you use talentsio, which does the former. + ''; + type = lib.types.bool; + }; }; config = @@ -100,6 +110,9 @@ CacheDirectory = "sioworker"; AmbientCapabilities = [ "CAP_PERFMON" ]; PIDFile = "/run/sioworker/sioworker.pid"; + # S*stemd is retarded and tries to open the stdout file first + #LogsDirectory = lib.mkIf cfg.separateStdoutFromJournal "sio2"; + StandardOutput = lib.mkIf cfg.separateStdoutFromJournal "append:/var/log/sio2/sioworker.log"; User = "sioworker"; Group = "sioworker"; diff --git a/nix/module/workersd.nix b/nix/module/workersd.nix index 05e2ad5..c828581 100644 --- a/nix/module/workersd.nix +++ b/nix/module/workersd.nix @@ -14,7 +14,6 @@ type = lib.types.ints.unsigned; }; - worker = lib.mkOption { default = { }; description = "The worker listen address and port"; @@ -48,6 +47,16 @@ }; }; }; + + separateStdoutFromJournal = lib.mkOption { + default = false; + description = '' + Redirect sioworkersd's stdout to a file in /var/log/sio2. + You have to ensure that directory exists and rotate the logs yourself, + unless you use talentsio, which does the former. + ''; + type = lib.types.bool; + }; }; config = @@ -91,6 +100,9 @@ RuntimeDirectory = "sioworkersd"; StateDirectory = "sioworkersd"; PIDFile = "/run/sioworkersd/sioworkersd.pid"; + # S*stemd is retarded and tries to open the stdout file first + #LogsDirectory = lib.mkIf cfg.separateStdoutFromJournal "sio2"; + StandardOutput = lib.mkIf cfg.separateStdoutFromJournal "append:/var/log/sio2/sioworkersd.log"; User = "sioworkersd"; Group = "sioworkersd";