Created
November 5, 2013 12:21
-
-
Save TomHoenderdos/7318253 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{config, pkgs, ...}: | |
with pkgs.lib; | |
let | |
cfg = config.services.zookeeper; | |
custompkgs = import <customnixpkgs> {}; | |
zookeeper = custompkgs.zookeeper; | |
zooCfg = pkgs.writeText "zoo.cfg" "${cfg.config}"; | |
in | |
{ | |
options = { | |
services.zookeeper = { | |
enable = mkOption { | |
default = false; | |
description = "Wether to enable Zookeeper or not"; | |
}; | |
logDir = mkOption { | |
description = "Where to keep Zookeeper log files."; | |
default = "/var/log/zookeeper"; | |
type = types.path; | |
}; | |
dataLogDir = mkOption { | |
description = "the directory where transaction log is stored. This parameter provides dedicated log device for ZooKeeper"; | |
default = "/var/lib/zookeeper"; | |
type = types.string; | |
}; | |
config = mkOption { | |
default = '' | |
# The number of milliseconds of each tick | |
tickTime=2000 | |
# The number of ticks that the initial | |
# synchronization phase can take | |
initLimit=10 | |
# The number of ticks that can pass between | |
# sending a request and getting an acknowledgement | |
syncLimit=5 | |
# the directory where the snapshot is stored. | |
# do not use /tmp for storage, /tmp here is just | |
# example sakes. | |
dataDir=/tmp/zookeeper/ | |
# the directory where transaction log is stored. | |
# this parameter provides dedicated log device for ZooKeeper | |
dataLogDir=${cfg.dataLogDir} | |
# the port at which the clients will connect | |
clientPort=2181 | |
# Be sure to read the maintenance section of the | |
# administrator guide before turning on autopurge. | |
# | |
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance | |
# | |
# The number of snapshots to retain in dataDir | |
#autopurge.snapRetainCount=3 | |
# Purge task interval in hours | |
# Set to "0" to disable auto purge feature | |
#autopurge.purgeInterval=1 | |
''; | |
type = types.string; | |
description = "Options to determine how Zookeeper works"; | |
}; | |
user = mkOption { | |
default = "zookeeper"; | |
description = "User account under which Zookeeper runs."; | |
}; | |
}; | |
}; | |
config = mkIf config.services.zookeeper.enable { | |
users.extraGroups = optionalAttrs (cfg.user == "zookeeper") (singleton | |
{ | |
name = "zookeeper"; | |
}); | |
users.extraUsers = optionalAttrs (cfg.user == "zookeeper") (singleton | |
{ name = "zookeeper"; | |
group = "zookeeper"; | |
isSystemUser = true; | |
description = "Zookeeper user"; | |
home = "/var/lib/zookeeper"; | |
createHome = true; | |
}); | |
systemd.services.zookeeper = { | |
description = "Zookeeper daemon"; | |
wantedBy = ["multi-user.target"]; | |
preStart = '' | |
mkdir -p ${cfg.logDir} | |
''; | |
serviceConfig = | |
{ WorkingDirectory = cfg.dataLogDir; | |
ExecStart = "${pkgs.jre}/bin/java -Dzookeeper.log.dir=${cfg.logDir} -cp ${zookeeper}/lib/*:${zookeeper}/zookeeper.jar:${zookeeper}/conf -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain ${zooCfg}"; | |
User = cfg.user; | |
PermissionsStartOnly = true; | |
Group = cfg.user; | |
Restart = "always"; | |
}; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment