2017-01-03 13:12:36 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.journalbeat;
|
|
|
|
|
|
|
|
journalbeatYml = pkgs.writeText "journalbeat.yml" ''
|
|
|
|
name: ${cfg.name}
|
|
|
|
tags: ${builtins.toJSON cfg.tags}
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.journalbeat = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "journalbeat";
|
|
|
|
|
2019-05-10 14:41:41 +01:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.journalbeat;
|
2021-10-03 17:06:03 +01:00
|
|
|
defaultText = literalExpression "pkgs.journalbeat";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
2019-05-10 14:41:41 +01:00
|
|
|
The journalbeat package to use
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-03 13:12:36 +00:00
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "journalbeat";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Name of the beat";
|
2017-01-03 13:12:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Tags to place on the shipped log messages";
|
2017-01-03 13:12:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.str;
|
2019-05-10 14:41:41 +01:00
|
|
|
default = "journalbeat";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Directory below `/var/lib/` to store journalbeat's
|
2019-05-10 14:41:41 +01:00
|
|
|
own logs and other data. This directory will be created automatically
|
|
|
|
using systemd's StateDirectory mechanism.
|
|
|
|
'';
|
2017-01-03 13:12:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2021-11-25 20:58:45 +00:00
|
|
|
default = "";
|
2022-07-28 22:19:15 +01:00
|
|
|
description = lib.mdDoc "Any other configuration options you want to add";
|
2017-01-03 13:12:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2019-05-10 14:41:41 +01:00
|
|
|
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 = {
|
2017-01-03 13:12:36 +00:00
|
|
|
description = "Journalbeat log shipper";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2021-12-16 15:20:52 +00:00
|
|
|
wants = [ "elasticsearch.service" ];
|
|
|
|
after = [ "elasticsearch.service" ];
|
2017-01-03 13:12:36 +00:00
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${cfg.stateDir}/data
|
|
|
|
mkdir -p ${cfg.stateDir}/logs
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
2019-05-10 14:41:41 +01:00
|
|
|
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";
|
2017-01-03 13:12:36 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|