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