at 23.11-pre 2.4 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.journalbeat; 7 8 journalbeatYml = pkgs.writeText "journalbeat.yml" '' 9 name: ${cfg.name} 10 tags: ${builtins.toJSON cfg.tags} 11 12 ${cfg.extraConfig} 13 ''; 14 15in 16{ 17 options = { 18 19 services.journalbeat = { 20 21 enable = mkEnableOption (lib.mdDoc "journalbeat"); 22 23 package = mkOption { 24 type = types.package; 25 default = pkgs.journalbeat; 26 defaultText = literalExpression "pkgs.journalbeat"; 27 description = lib.mdDoc '' 28 The journalbeat package to use 29 ''; 30 }; 31 32 name = mkOption { 33 type = types.str; 34 default = "journalbeat"; 35 description = lib.mdDoc "Name of the beat"; 36 }; 37 38 tags = mkOption { 39 type = types.listOf types.str; 40 default = []; 41 description = lib.mdDoc "Tags to place on the shipped log messages"; 42 }; 43 44 stateDir = mkOption { 45 type = types.str; 46 default = "journalbeat"; 47 description = lib.mdDoc '' 48 Directory below `/var/lib/` to store journalbeat's 49 own logs and other data. This directory will be created automatically 50 using systemd's StateDirectory mechanism. 51 ''; 52 }; 53 54 extraConfig = mkOption { 55 type = types.lines; 56 default = ""; 57 description = lib.mdDoc "Any other configuration options you want to add"; 58 }; 59 60 }; 61 }; 62 63 config = mkIf cfg.enable { 64 65 assertions = [ 66 { 67 assertion = !hasPrefix "/" cfg.stateDir; 68 message = 69 "The option services.journalbeat.stateDir shouldn't be an absolute directory." + 70 " It should be a directory relative to /var/lib/."; 71 } 72 ]; 73 74 systemd.services.journalbeat = { 75 description = "Journalbeat log shipper"; 76 wantedBy = [ "multi-user.target" ]; 77 wants = [ "elasticsearch.service" ]; 78 after = [ "elasticsearch.service" ]; 79 preStart = '' 80 mkdir -p ${cfg.stateDir}/data 81 mkdir -p ${cfg.stateDir}/logs 82 ''; 83 serviceConfig = { 84 StateDirectory = cfg.stateDir; 85 ExecStart = '' 86 ${cfg.package}/bin/journalbeat \ 87 -c ${journalbeatYml} \ 88 -path.data /var/lib/${cfg.stateDir}/data \ 89 -path.logs /var/lib/${cfg.stateDir}/logs''; 90 Restart = "always"; 91 }; 92 }; 93 }; 94}