summaryrefslogtreecommitdiffstats
path: root/nixos/modules
diff options
context:
space:
mode:
authorBas van Dijk <v.dijk.bas@gmail.com>2019-05-10 18:44:44 +0200
committerGitHub <noreply@github.com>2019-05-10 18:44:44 +0200
commit4b7aea9e8cd17bbabaea70400b50af4e8140c696 (patch)
treeb72b9eff0d643484316c6b87d3bc3ac0e3e14707 /nixos/modules
parent38c093e3760897e92f826f69eec21c91d38a05fc (diff)
parent477c552c7d70135819e8b3c04860336abeb7e811 (diff)
Merge pull request #61237 from basvandijk/journalbeat-fixes
NixOS: support journalbeat >= 6
Diffstat (limited to 'nixos/modules')
-rw-r--r--nixos/modules/services/logging/journalbeat.nix43
1 files changed, 37 insertions, 6 deletions
diff --git a/nixos/modules/services/logging/journalbeat.nix b/nixos/modules/services/logging/journalbeat.nix
index 8186a3b02c37..89f53b1b2454 100644
--- a/nixos/modules/services/logging/journalbeat.nix
+++ b/nixos/modules/services/logging/journalbeat.nix
@@ -5,11 +5,13 @@ with lib;
let
cfg = config.services.journalbeat;
+ lt6 = builtins.compareVersions cfg.package.version "6" < 0;
+
journalbeatYml = pkgs.writeText "journalbeat.yml" ''
name: ${cfg.name}
tags: ${builtins.toJSON cfg.tags}
- journalbeat.cursor_state_file: ${cfg.stateDir}/cursor-state
+ ${optionalString lt6 "journalbeat.cursor_state_file: /var/lib/${cfg.stateDir}/cursor-state"}
${cfg.extraConfig}
'';
@@ -22,6 +24,16 @@ in
enable = mkEnableOption "journalbeat";
+ package = mkOption {
+ type = types.package;
+ default = pkgs.journalbeat;
+ defaultText = "pkgs.journalbeat";
+ example = literalExample "pkgs.journalbeat7";
+ description = ''
+ The journalbeat package to use
+ '';
+ };
+
name = mkOption {
type = types.str;
default = "journalbeat";
@@ -36,13 +48,17 @@ in
stateDir = mkOption {
type = types.str;
- default = "/var/lib/journalbeat";
- description = "The state directory. Journalbeat's own logs and other data are stored here.";
+ default = "journalbeat";
+ description = ''
+ Directory below <literal>/var/lib/</literal> to store journalbeat's
+ own logs and other data. This directory will be created automatically
+ using systemd's StateDirectory mechanism.
+ '';
};
extraConfig = mkOption {
type = types.lines;
- default = ''
+ default = optionalString lt6 ''
journalbeat:
seek_position: cursor
cursor_seek_fallback: tail
@@ -61,7 +77,16 @@ in
config = mkIf cfg.enable {
- systemd.services.journalbeat = with pkgs; {
+ assertions = [
+ {
+ assertion = !hasPrefix "/" cfg.stateDir;
+ message =
+ "The option services.journalbeat.stateDir shouldn't be an absolute directory." +
+ " It should be a directory relative to /var/lib/.";
+ }
+ ];
+
+ systemd.services.journalbeat = {
description = "Journalbeat log shipper";
wantedBy = [ "multi-user.target" ];
preStart = ''
@@ -69,7 +94,13 @@ in
mkdir -p ${cfg.stateDir}/logs
'';
serviceConfig = {
- ExecStart = "${pkgs.journalbeat}/bin/journalbeat -c ${journalbeatYml} -path.data ${cfg.stateDir}/data -path.logs ${cfg.stateDir}/logs";
+ StateDirectory = cfg.stateDir;
+ ExecStart = ''
+ ${cfg.package}/bin/journalbeat \
+ -c ${journalbeatYml} \
+ -path.data /var/lib/${cfg.stateDir}/data \
+ -path.logs /var/lib/${cfg.stateDir}/logs'';
+ Restart = "always";
};
};
};