1 { config, lib, pkgs, ... }:
3 cfg = config.services.zookeeper;
7 clientPort=${toString cfg.port}
8 autopurge.purgeInterval=${toString cfg.purgeInterval}
13 configDir = pkgs.buildEnv {
14 name = "zookeeper-conf";
16 (pkgs.writeTextDir "zoo.cfg" zookeeperConfig)
17 (pkgs.writeTextDir "log4j.properties" cfg.logging)
23 options.services.zookeeper = {
24 enable = lib.mkEnableOption "Zookeeper";
27 description = "Zookeeper Client port.";
29 type = lib.types.port;
33 description = "Zookeeper ID.";
38 purgeInterval = lib.mkOption {
40 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.
46 extraConf = lib.mkOption {
47 description = "Extra configuration for Zookeeper.";
48 type = lib.types.lines;
56 servers = lib.mkOption {
57 description = "All Zookeeper Servers.";
59 type = lib.types.lines;
61 server.0=host0:2888:3888
62 server.1=host1:2888:3888
63 server.2=host2:2888:3888
67 logging = lib.mkOption {
68 description = "Zookeeper logging configuration.";
70 zookeeper.root.logger=INFO, CONSOLE
71 log4j.rootLogger=INFO, CONSOLE
72 log4j.logger.org.apache.zookeeper.audit.Log4jAuditLogger=INFO, CONSOLE
73 log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
74 log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
75 log4j.appender.CONSOLE.layout.ConversionPattern=[myid:%X{myid}] - %-5p [%t:%C{1}@%L] - %m%n
77 type = lib.types.lines;
80 dataDir = lib.mkOption {
81 type = lib.types.path;
82 default = "/var/lib/zookeeper";
84 Data directory for Zookeeper
88 extraCmdLineOptions = lib.mkOption {
89 description = "Extra command line options for the Zookeeper launcher.";
90 default = [ "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
91 type = lib.types.listOf lib.types.str;
92 example = [ "-Djava.net.preferIPv4Stack=true" "-Dcom.sun.management.jmxremote" "-Dcom.sun.management.jmxremote.local.only=true" ];
95 preferIPv4 = lib.mkOption {
96 type = lib.types.bool;
99 Add the -Djava.net.preferIPv4Stack=true flag to the Zookeeper server.
103 package = lib.mkPackageOption pkgs "zookeeper" { };
106 description = "The JRE with which to run Zookeeper";
107 default = cfg.package.jre;
108 defaultText = lib.literalExpression "pkgs.zookeeper.jre";
109 example = lib.literalExpression "pkgs.jre";
110 type = lib.types.package;
115 config = lib.mkIf cfg.enable {
116 environment.systemPackages = [cfg.package];
118 systemd.tmpfiles.rules = [
119 "d '${cfg.dataDir}' 0700 zookeeper - - -"
120 "Z '${cfg.dataDir}' 0700 zookeeper - - -"
123 systemd.services.zookeeper = {
124 description = "Zookeeper Daemon";
125 wantedBy = [ "multi-user.target" ];
126 after = [ "network.target" ];
129 ${cfg.jre}/bin/java \
130 -cp "${cfg.package}/lib/*:${configDir}" \
131 ${lib.escapeShellArgs cfg.extraCmdLineOptions} \
132 -Dzookeeper.datadir.autocreate=false \
133 ${lib.optionalString cfg.preferIPv4 "-Djava.net.preferIPv4Stack=true"} \
134 org.apache.zookeeper.server.quorum.QuorumPeerMain \
140 echo "${toString cfg.id}" > ${cfg.dataDir}/myid
141 mkdir -p ${cfg.dataDir}/version-2
145 users.users.zookeeper = {
148 description = "Zookeeper daemon user";
151 users.groups.zookeeper = {};