2014-08-24 17:43:45 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.zookeeper;
|
2017-07-24 22:27:38 +00:00
|
|
|
|
2014-08-24 17:43:45 +02:00
|
|
|
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 = {
|
2024-08-30 00:46:53 +02:00
|
|
|
enable = lib.mkEnableOption "Zookeeper";
|
2014-08-24 17:43:45 +02:00
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
port = lib.mkOption {
|
2014-08-24 17:43:45 +02:00
|
|
|
description = "Zookeeper Client port.";
|
|
|
|
default = 2181;
|
2024-08-30 00:46:53 +02:00
|
|
|
type = lib.types.port;
|
2014-08-24 17:43:45 +02:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
id = lib.mkOption {
|
2014-08-24 17:43:45 +02:00
|
|
|
description = "Zookeeper ID.";
|
|
|
|
default = 0;
|
2024-08-30 00:46:53 +02:00
|
|
|
type = lib.types.int;
|
2014-08-24 17:43:45 +02:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
purgeInterval = lib.mkOption {
|
2014-08-24 17:43:45 +02:00
|
|
|
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;
|
2024-08-30 00:46:53 +02:00
|
|
|
type = lib.types.int;
|
2014-08-24 17:43:45 +02:00
|
|
|
};
|
2017-07-24 22:27:38 +00:00
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
extraConf = lib.mkOption {
|
2014-08-24 17:43:45 +02:00
|
|
|
description = "Extra configuration for Zookeeper.";
|
2024-08-30 00:46:53 +02:00
|
|
|
type = lib.types.lines;
|
2014-08-24 17:43:45 +02:00
|
|
|
default = ''
|
|
|
|
initLimit=5
|
|
|
|
syncLimit=2
|
|
|
|
tickTime=2000
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
servers = lib.mkOption {
|
2014-08-24 17:43:45 +02:00
|
|
|
description = "All Zookeeper Servers.";
|
|
|
|
default = "";
|
2024-08-30 00:46:53 +02:00
|
|
|
type = lib.types.lines;
|
2014-08-24 17:43:45 +02:00
|
|
|
example = ''
|
|
|
|
server.0=host0:2888:3888
|
|
|
|
server.1=host1:2888:3888
|
|
|
|
server.2=host2:2888:3888
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
logging = lib.mkOption {
|
2014-08-24 17:43:45 +02:00
|
|
|
description = "Zookeeper logging configuration.";
|
|
|
|
default = ''
|
|
|
|
zookeeper.root.logger=INFO, CONSOLE
|
|
|
|
log4j.rootLogger=INFO, CONSOLE
|
2020-11-23 20:14:39 +01:00
|
|
|
log4j.logger.org.apache.zookeeper.audit.Log4jAuditLogger=INFO, CONSOLE
|
2014-08-24 17:43:45 +02:00
|
|
|
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
|
|
|
|
'';
|
2024-08-30 00:46:53 +02:00
|
|
|
type = lib.types.lines;
|
2014-08-24 17:43:45 +02:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
dataDir = lib.mkOption {
|
|
|
|
type = lib.types.path;
|
2014-08-24 17:43:45 +02:00
|
|
|
default = "/var/lib/zookeeper";
|
|
|
|
description = ''
|
|
|
|
Data directory for Zookeeper
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
extraCmdLineOptions = lib.mkOption {
|
2014-08-24 17:43:45 +02:00
|
|
|
description = "Extra command line options for the Zookeeper launcher.";
|
|
|
|
default = [
|
|
|
|
"-Dcom.sun.management.jmxremote"
|
|
|
|
"-Dcom.sun.management.jmxremote.local.only=true"
|
|
|
|
];
|
2024-08-30 00:46:53 +02:00
|
|
|
type = lib.types.listOf lib.types.str;
|
2014-08-24 17:43:45 +02:00
|
|
|
example = [
|
|
|
|
"-Djava.net.preferIPv4Stack=true"
|
|
|
|
"-Dcom.sun.management.jmxremote"
|
|
|
|
"-Dcom.sun.management.jmxremote.local.only=true"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
preferIPv4 = lib.mkOption {
|
|
|
|
type = lib.types.bool;
|
2014-08-24 17:43:45 +02:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Add the -Djava.net.preferIPv4Stack=true flag to the Zookeeper server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
package = lib.mkPackageOption pkgs "zookeeper" { };
|
2018-02-06 09:55:45 +01:00
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
jre = lib.mkOption {
|
2022-04-19 18:49:44 +08:00
|
|
|
description = "The JRE with which to run Zookeeper";
|
2022-04-26 18:44:33 +08:00
|
|
|
default = cfg.package.jre;
|
2024-08-30 00:46:53 +02:00
|
|
|
defaultText = lib.literalExpression "pkgs.zookeeper.jre";
|
|
|
|
example = lib.literalExpression "pkgs.jre";
|
|
|
|
type = lib.types.package;
|
2022-04-19 18:49:44 +08:00
|
|
|
};
|
2014-08-24 17:43:45 +02:00
|
|
|
};
|
|
|
|
|
2024-08-30 00:46:53 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2018-02-06 09:55:45 +01:00
|
|
|
environment.systemPackages = [ cfg.package ];
|
|
|
|
|
2019-02-24 07:37:29 -05:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d '${cfg.dataDir}' 0700 zookeeper - - -"
|
2019-09-03 11:57:57 -04:00
|
|
|
"Z '${cfg.dataDir}' 0700 zookeeper - - -"
|
2019-02-24 07:37:29 -05:00
|
|
|
];
|
|
|
|
|
2014-08-24 17:43:45 +02:00
|
|
|
systemd.services.zookeeper = {
|
|
|
|
description = "Zookeeper Daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2016-09-10 20:12:53 +02:00
|
|
|
after = [ "network.target" ];
|
2014-08-24 17:43:45 +02:00
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = ''
|
2022-04-19 18:49:44 +08:00
|
|
|
${cfg.jre}/bin/java \
|
2020-11-23 20:14:39 +01:00
|
|
|
-cp "${cfg.package}/lib/*:${configDir}" \
|
2024-08-30 00:46:53 +02:00
|
|
|
${lib.escapeShellArgs cfg.extraCmdLineOptions} \
|
2014-08-24 17:43:45 +02:00
|
|
|
-Dzookeeper.datadir.autocreate=false \
|
2024-08-30 00:46:53 +02:00
|
|
|
${lib.optionalString cfg.preferIPv4 "-Djava.net.preferIPv4Stack=true"} \
|
2014-08-24 17:43:45 +02:00
|
|
|
org.apache.zookeeper.server.quorum.QuorumPeerMain \
|
|
|
|
${configDir}/zoo.cfg
|
|
|
|
'';
|
|
|
|
User = "zookeeper";
|
|
|
|
};
|
|
|
|
preStart = ''
|
|
|
|
echo "${toString cfg.id}" > ${cfg.dataDir}/myid
|
2020-11-23 20:14:39 +01:00
|
|
|
mkdir -p ${cfg.dataDir}/version-2
|
2014-08-24 17:43:45 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-09-14 19:51:29 +02:00
|
|
|
users.users.zookeeper = {
|
2021-08-08 12:00:00 +00:00
|
|
|
isSystemUser = true;
|
|
|
|
group = "zookeeper";
|
2014-08-24 17:43:45 +02:00
|
|
|
description = "Zookeeper daemon user";
|
|
|
|
home = cfg.dataDir;
|
|
|
|
};
|
2021-08-08 12:00:00 +00:00
|
|
|
users.groups.zookeeper = { };
|
2014-08-24 17:43:45 +02:00
|
|
|
};
|
|
|
|
}
|