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