fix: wait for the /nix/store before launching daemons

This commit is contained in:
Jeremy Wall 2024-07-26 13:03:00 -04:00
parent 2444ac46a0
commit 004ef58f30
3 changed files with 57 additions and 44 deletions

View File

@ -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 = [

View File

@ -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;
};
};

View File

@ -0,0 +1,6 @@
{ pkgs }:
with pkgs;
contents: writeShellScript "launcher.sh" ''
/bin/wait4path /nix/store && \
${contents}
''