From 004ef58f300296c7ee678d1fb34e7617f2938fc2 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Fri, 26 Jul 2024 13:03:00 -0400 Subject: [PATCH] fix: wait for the /nix/store before launching daemons --- nix/base-system/modules/darwin-monitor.nix | 64 ++++++++++++---------- nix/base-system/modules/vector.nix | 31 ++++++----- nix/packages/darwin-launcher.nix | 6 ++ 3 files changed, 57 insertions(+), 44 deletions(-) create mode 100644 nix/packages/darwin-launcher.nix diff --git a/nix/base-system/modules/darwin-monitor.nix b/nix/base-system/modules/darwin-monitor.nix index 5cc896d..f373400 100644 --- a/nix/base-system/modules/darwin-monitor.nix +++ b/nix/base-system/modules/darwin-monitor.nix @@ -1,5 +1,24 @@ { pkgs, lib, config, ...}: with lib; +let + mkLauncher = import ../../packages/darwin-launcher.nix { inherit pkgs; }; + durnitispOutPath = config.services.durnitisp.stdoutPath; + durnitispErrPath = config.services.durnitisp.stderrPath; + durnitispPidPath = config.services.durnitisp.pidPath; + + durnitispLauncher = mkLauncher '' + exec ${pkgs.clio}/bin/clio \ + --out-path=${durnitispOutPath} \ + --err-path=${durnitispErrPath} \ + --pid-file=${durnitispPidPath} \ + --paranoid \ + -- \ + ${pkgs.durnitisp}/bin/durnitisp \ + --listenHost=${config.services.durnitisp.listen} \ + --stunHosts=stun.ekiga.net:3478,stun.schlund.de:3478,stun.voipbuster.com:3478,stun.voipstunt.com:3478,stun.xten.com:3478" \ + --pingHosts=google.com,prod.actual.battle.net" + ''; +in { options.services.node-exporter = { @@ -134,10 +153,6 @@ with lib; heraclesErrPath = config.services.heracles.stderrPath; heraclesPidPath = config.services.heracles.pidPath; - durnitispOutPath = config.services.durnitisp.stdoutPath; - durnitispErrPath = config.services.durnitisp.stderrPath; - durnitispPidPath = config.services.durnitisp.pidPath; - prometheusOutPath = config.services.prometheus.stdoutPath; prometheusErrPath = config.services.prometheus.stderrPath; prometheusPidPath = config.services.prometheus.pidPath; @@ -186,24 +201,10 @@ with lib; launchd.daemons.durnitisp = mkIf config.services.durnitisp.enable { serviceConfig = { ProgramArguments = [ - "${pkgs.clio}/bin/clio" - "--out-path=${durnitispOutPath}" - "--err-path=${durnitispErrPath}" - "--pid-file=${durnitispPidPath}" - "--paranoid" - "--" - "${pkgs.durnitisp}/bin/durnitisp" - "--listenHost=${config.services.durnitisp.listen}" - "--stunHosts=stun.ekiga.net:3478,stun.schlund.de:3478,stun.voipbuster.com:3478,stun.voipstunt.com:3478,stun.xten.com:3478" - "--pingHosts=google.com,prod.actual.battle.net" + "${durnitispLauncher}" ]; #StandardErrorPath = "/var/log/clio.durnitisp.err"; #StandardOutPath = "/var/log/clio.durnitisp.out"; - KeepAlive = { - PathState = { - "/nix/store" = true; - }; - }; RunAtLoad = true; }; }; @@ -211,16 +212,21 @@ with lib; launchd.user.agents.prometheus = mkIf config.services.prometheus.enable { serviceConfig = { ProgramArguments = [ - "${pkgs.clio}/bin/clio" - "--out-path=${prometheusOutPath}" - "--err-path=${prometheusErrPath}" - "--pid-file=${prometheusPidPath}" - "--paranoid" - "--" - "${pkgs.prometheus}/bin/prometheus" - "--web.listen-address=${config.services.prometheus.listen}" - "--config.file=/etc/${config.environment.etc."prometheus.yaml".target}" - "--storage.tsdb.path=${config.services.prometheus.dataPath}/data" + "/bin/sh" + "-c" + '' + /bin/wait4path ${pkgs.clio}/bin/clio && \ + exec ${pkgs.clio}/bin/clio \ + --out-path=${prometheusOutPath} \ + --err-path=${prometheusErrPath} \ + --pid-file=${prometheusPidPath} \ + --paranoid \ + -- \ + ${pkgs.prometheus}/bin/prometheus \ + --web.listen-address=${config.services.prometheus.listen} \ + --config.file=/etc/${config.environment.etc."prometheus.yaml".target} \ + --storage.tsdb.path=${config.services.prometheus.dataPath}/data \ + '' ]; WorkingDirectory = config.services.prometheus.dataPath; WatchPaths = [ diff --git a/nix/base-system/modules/vector.nix b/nix/base-system/modules/vector.nix index c6e3db1..d107538 100644 --- a/nix/base-system/modules/vector.nix +++ b/nix/base-system/modules/vector.nix @@ -1,5 +1,20 @@ {pkgs, lib, config, ...}: with lib; +let + mkLauncher = import ../../packages/darwin-launcher.nix { inherit pkgs; }; + vectorLauncher = mkLauncher '' + exec ${pkgs.clio}/bin/clio \ + --out-path=${config.services.vector.stdoutPath} \ + --err-path=${config.services.vector.stdoutPath} \ + --pid-file=${config.services.vector.pidPath} \ + --paranoid \ + -- \ + ${pkgs.vector}/bin/vector \ + --verbose \ + --watch-config \ + --config=/etc/${config.environment.etc."vector.yaml".target} + ''; +in { options.services.vector = { enable = mkEnableOption "Enable the vector agent"; @@ -29,25 +44,11 @@ with lib; launchd.daemons.vector = mkIf config.services.vector.enable { serviceConfig = { ProgramArguments = [ - "${pkgs.clio}/bin/clio" - "--out-path=${config.services.vector.stdoutPath}" - "--err-path=${config.services.vector.stdoutPath}" - "--pid-file=${config.services.vector.pidPath}" - "--paranoid" - "--" - "${pkgs.vector}/bin/vector" - "--verbose" - "--watch-config" - "--config=/etc/${config.environment.etc."vector.yaml".target}" + "${vectorLauncher}" ]; WatchPaths= [ "/etc/${config.environment.etc."vector.yaml".target}" ]; - KeepAlive = { - PathState = { - "/nix/store" = true; - }; - }; RunAtLoad = true; }; }; diff --git a/nix/packages/darwin-launcher.nix b/nix/packages/darwin-launcher.nix new file mode 100644 index 0000000..5606326 --- /dev/null +++ b/nix/packages/darwin-launcher.nix @@ -0,0 +1,6 @@ +{ pkgs }: +with pkgs; +contents: writeShellScript "launcher.sh" '' + /bin/wait4path /nix/store && \ + ${contents} +''