diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix index 99a33f68735..92ab241deaa 100644 --- a/nixos/modules/misc/ids.nix +++ b/nixos/modules/misc/ids.nix @@ -147,6 +147,7 @@ riemann = 137; riemanndash = 138; radvd = 139; + zookeeper = 140; # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399! diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index 59c69f060b9..e2f2921b870 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -164,6 +164,7 @@ ./services/misc/siproxd.nix ./services/misc/svnserve.nix ./services/misc/synergy.nix + ./services/misc/zookeeper.nix ./services/monitoring/apcupsd.nix ./services/monitoring/dd-agent.nix ./services/monitoring/graphite.nix diff --git a/nixos/modules/services/misc/zookeeper.nix b/nixos/modules/services/misc/zookeeper.nix new file mode 100755 index 00000000000..47675b8876c --- /dev/null +++ b/nixos/modules/services/misc/zookeeper.nix @@ -0,0 +1,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.uniq 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; + }; + }; +} diff --git a/pkgs/servers/zookeeper/default.nix b/pkgs/servers/zookeeper/default.nix new file mode 100755 index 00000000000..307993a958a --- /dev/null +++ b/pkgs/servers/zookeeper/default.nix @@ -0,0 +1,36 @@ +{ stdenv, fetchurl, jre, makeWrapper, bash }: + +stdenv.mkDerivation rec { + name = "zookeeper-3.4.6"; + + src = fetchurl { + url = "mirror://apache/zookeeper/${name}/${name}.tar.gz"; + sha256 = "01b3938547cd620dc4c93efe07c0360411f4a66962a70500b163b59014046994"; + }; + + buildInputs = [ makeWrapper jre ]; + + phases = ["unpackPhase" "installPhase"]; + + installPhase = '' + mkdir -p $out + cp -R conf docs lib ${name}.jar $out + mkdir -p $out/bin + cp -R bin/{zkCli,zkCleanup,zkEnv}.sh $out/bin + for i in $out/bin/{zkCli,zkCleanup}.sh; do + wrapProgram $i \ + --set JAVA_HOME "${jre}" \ + --prefix PATH : "${bash}/bin" + done + chmod -x $out/bin/zkEnv.sh + ''; + + meta = with stdenv.lib; { + homepage = "http://zookeeper.apache.org"; + description = "Apache Zookeeper"; + license = licenses.asl20; + maintainers = [ maintainers.nathan-gs ]; + platforms = platforms.unix; + }; + +} diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 9b6da45fe5d..fe27dd2c970 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -7086,6 +7086,8 @@ let xinetd = callPackage ../servers/xinetd { }; + zookeeper = callPackage ../servers/zookeeper { }; + xquartz = callPackage ../servers/x11/xquartz { }; quartz-wm = callPackage ../servers/x11/quartz-wm { stdenv = clangStdenv; };