blob: 827a050be1144107986a73276f574ce411b77726 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.zookeeper;
zookeeperConfig = ''
dataDir=${cfg.dataDir}
clientPort=${toString cfg.port}
autopurge.purgeInterval=${toString cfg.purgeInterval}
${cfg.extraConf}
${cfg.servers}
'';
configDir = pkgs.buildEnv {
name = "zookeeper-conf";
paths = [
(pkgs.writeTextDir "zoo.cfg" zookeeperConfig)
(pkgs.writeTextDir "log4j.properties" cfg.logging)
];
};
in {
options.services.zookeeper = {
enable = mkOption {
description = "Whether to enable Zookeeper.";
default = false;
type = types.bool;
};
port = mkOption {
description = "Zookeeper Client port.";
default = 2181;
type = types.int;
};
id = mkOption {
description = "Zookeeper ID.";
default = 0;
type = types.int;
};
purgeInterval = mkOption {
description = ''
The time interval in hours for which the purge task has to be triggered. Set to a positive integer (1 and above) to enable the auto purging.
'';
default = 1;
type = types.int;
};
extraConf = mkOption {
description = "Extra configuration for Zookeeper.";
type = types.lines;
default = ''
initLimit=5
syncLimit=2
tickTime=2000
'';
};
servers = mkOption {
description = "All Zookeeper Servers.";
default = "";
type = types.lines;
example = ''
server.0=host0:2888:3888
server.1=host1:2888:3888
server.2=host2:2888:3888
'';
};
logging = mkOption {
description = "Zookeeper logging configuration.";
default = ''
zookeeper.root.logger=INFO, CONSOLE
log4j.rootLogger=INFO, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=[myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
'';
type = types.lines;
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/zookeeper";
description = ''
Data directory for Zookeeper
'';
};
extraCmdLineOptions = mkOption {
description = "Extra command line options for the Zookeeper launcher.";
default = [ "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
type = types.listOf types.string;
example = [ "-Djava.net.preferIPv4Stack=true" "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
};
preferIPv4 = mkOption {
type = types.bool;
default = true;
description = ''
Add the -Djava.net.preferIPv4Stack=true flag to the Zookeeper server.
'';
};
};
config = mkIf cfg.enable {
systemd.services.zookeeper = {
description = "Zookeeper Daemon";
wantedBy = [ "multi-user.target" ];
after = [ "network-interfaces.target" ];
environment = { ZOOCFGDIR = configDir; };
serviceConfig = {
ExecStart = ''
${pkgs.jre}/bin/java \
-cp "${pkgs.zookeeper}/lib/*:${pkgs.zookeeper}/${pkgs.zookeeper.name}.jar:${configDir}" \
${toString cfg.extraCmdLineOptions} \
-Dzookeeper.datadir.autocreate=false \
${optionalString cfg.preferIPv4 "-Djava.net.preferIPv4Stack=true"} \
org.apache.zookeeper.server.quorum.QuorumPeerMain \
${configDir}/zoo.cfg
'';
User = "zookeeper";
PermissionsStartOnly = true;
};
preStart = ''
mkdir -m 0700 -p ${cfg.dataDir}
if [ "$(id -u)" = 0 ]; then chown zookeeper ${cfg.dataDir}; fi
echo "${toString cfg.id}" > ${cfg.dataDir}/myid
'';
};
users.extraUsers = singleton {
name = "zookeeper";
uid = config.ids.uids.zookeeper;
description = "Zookeeper daemon user";
home = cfg.dataDir;
};
};
}
|