at 15.09-beta 2.2 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.opentsdb; 7 8 configFile = pkgs.writeText "opentsdb.conf" '' 9 tsd.core.auto_create_metrics = true 10 tsd.http.request.enable_chunked = true 11 ''; 12 13in { 14 15 ###### interface 16 17 options = { 18 19 services.opentsdb = { 20 21 enable = mkOption { 22 type = types.bool; 23 default = false; 24 description = '' 25 Whether to run OpenTSDB. 26 ''; 27 }; 28 29 package = mkOption { 30 type = types.package; 31 default = pkgs.opentsdb; 32 example = literalExample "pkgs.opentsdb"; 33 description = '' 34 OpenTSDB package to use. 35 ''; 36 }; 37 38 user = mkOption { 39 type = types.string; 40 default = "opentsdb"; 41 description = '' 42 User account under which OpenTSDB runs. 43 ''; 44 }; 45 46 group = mkOption { 47 type = types.string; 48 default = "opentsdb"; 49 description = '' 50 Group account under which OpenTSDB runs. 51 ''; 52 }; 53 54 port = mkOption { 55 type = types.int; 56 default = 4242; 57 description = '' 58 Which port OpenTSDB listens on. 59 ''; 60 }; 61 62 }; 63 64 }; 65 66 ###### implementation 67 68 config = mkIf config.services.opentsdb.enable { 69 70 systemd.services.opentsdb = { 71 description = "OpenTSDB Server"; 72 wantedBy = [ "multi-user.target" ]; 73 requires = [ "hbase.service" ]; 74 75 environment.JAVA_HOME = "${pkgs.jre}"; 76 path = [ pkgs.gnuplot ]; 77 78 preStart = 79 '' 80 COMPRESSION=NONE HBASE_HOME=${config.services.hbase.package} ${cfg.package}/share/opentsdb/tools/create_table.sh 81 ''; 82 83 serviceConfig = { 84 PermissionsStartOnly = true; 85 User = cfg.user; 86 Group = cfg.group; 87 ExecStart = "${cfg.package}/bin/tsdb tsd --staticroot=${cfg.package}/share/opentsdb/static --cachedir=/tmp/opentsdb --port=${toString cfg.port} --config=${configFile}"; 88 }; 89 }; 90 91 users.extraUsers.opentsdb = { 92 description = "OpenTSDB Server user"; 93 group = "opentsdb"; 94 uid = config.ids.uids.opentsdb; 95 }; 96 97 users.extraGroups.opentsdb.gid = config.ids.gids.opentsdb; 98 99 }; 100}