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