2020-04-24 23:36:52 +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 = {
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "journalbeat");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "journalbeat" { };
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
name = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "journalbeat";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Name of the beat";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
tags = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Tags to place on the shipped log messages";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "journalbeat";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Directory below `/var/lib/` to store journalbeat's
|
2020-04-24 23:36:52 +00:00
|
|
|
own logs and other data. This directory will be created automatically
|
|
|
|
using systemd's StateDirectory mechanism.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
2021-12-19 01:06:50 +00:00
|
|
|
default = "";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Any other configuration options you want to add";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
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" ];
|
2021-12-19 01:06:50 +00:00
|
|
|
wants = [ "elasticsearch.service" ];
|
|
|
|
after = [ "elasticsearch.service" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
preStart = ''
|
|
|
|
mkdir -p ${cfg.stateDir}/data
|
|
|
|
mkdir -p ${cfg.stateDir}/logs
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
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";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|