1 { config, lib, pkgs, ... }:
6 cfg = config.services.zookeeper;
10 clientPort=${toString cfg.port}
11 autopurge.purgeInterval=${toString cfg.purgeInterval}
16 configDir = pkgs.buildEnv {
17 name = "zookeeper-conf";
19 (pkgs.writeTextDir "zoo.cfg" zookeeperConfig)
20 (pkgs.writeTextDir "log4j.properties" cfg.logging)
26 options.services.zookeeper = {
27 enable = mkEnableOption "Zookeeper";
30 description = "Zookeeper Client port.";
36 description = "Zookeeper ID.";
41 purgeInterval = mkOption {
43 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.
49 extraConf = mkOption {
50 description = "Extra configuration for Zookeeper.";
60 description = "All Zookeeper Servers.";
64 server.0=host0:2888:3888
65 server.1=host1:2888:3888
66 server.2=host2:2888:3888
71 description = "Zookeeper logging configuration.";
73 zookeeper.root.logger=INFO, CONSOLE
74 log4j.rootLogger=INFO, CONSOLE
75 log4j.logger.org.apache.zookeeper.audit.Log4jAuditLogger=INFO, CONSOLE
76 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
77 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
78 log4j.appender.CONSOLE.layout.ConversionPattern=[myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
85 default = "/var/lib/zookeeper";
87 Data directory for Zookeeper
91 extraCmdLineOptions = mkOption {
92 description = "Extra command line options for the Zookeeper launcher.";
93 default = [ "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
94 type = types.listOf types.str;
95 example = [ "-Djava.net.preferIPv4Stack=true" "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
98 preferIPv4 = mkOption {
102 Add the -Djava.net.preferIPv4Stack=true flag to the Zookeeper server.
106 package = mkPackageOption pkgs "zookeeper" { };
109 description = "The JRE with which to run Zookeeper";
110 default = cfg.package.jre;
111 defaultText = literalExpression "pkgs.zookeeper.jre";
112 example = literalExpression "pkgs.jre";
113 type = types.package;
118 config = mkIf cfg.enable {
119 environment.systemPackages = [cfg.package];
121 systemd.tmpfiles.rules = [
122 "d '${cfg.dataDir}' 0700 zookeeper - - -"
123 "Z '${cfg.dataDir}' 0700 zookeeper - - -"
126 systemd.services.zookeeper = {
127 description = "Zookeeper Daemon";
128 wantedBy = [ "multi-user.target" ];
129 after = [ "network.target" ];
132 ${cfg.jre}/bin/java \
133 -cp "${cfg.package}/lib/*:${configDir}" \
134 ${escapeShellArgs cfg.extraCmdLineOptions} \
135 -Dzookeeper.datadir.autocreate=false \
136 ${optionalString cfg.preferIPv4 "-Djava.net.preferIPv4Stack=true"} \
137 org.apache.zookeeper.server.quorum.QuorumPeerMain \
143 echo "${toString cfg.id}" > ${cfg.dataDir}/myid
144 mkdir -p ${cfg.dataDir}/version-2
148 users.users.zookeeper = {
151 description = "Zookeeper daemon user";
154 users.groups.zookeeper = {};