diff options
author | Albert Peschar <albert@peschar.net> | 2017-05-17 14:46:16 +0200 |
---|---|---|
committer | Franz Pletz <fpletz@fnordicwalking.de> | 2017-05-31 02:06:29 +0200 |
commit | 47d038c21d9ba99230d0c2f36a8174e24128258e (patch) | |
tree | bb55d48014aa3d0f92eb332267dc045e3bf62e52 /nixos/modules/services/search | |
parent | 6a2932717585f58867fce4376434eaf54cf604b8 (diff) | |
download | nixlib-47d038c21d9ba99230d0c2f36a8174e24128258e.tar nixlib-47d038c21d9ba99230d0c2f36a8174e24128258e.tar.gz nixlib-47d038c21d9ba99230d0c2f36a8174e24128258e.tar.bz2 nixlib-47d038c21d9ba99230d0c2f36a8174e24128258e.tar.lz nixlib-47d038c21d9ba99230d0c2f36a8174e24128258e.tar.xz nixlib-47d038c21d9ba99230d0c2f36a8174e24128258e.tar.zst nixlib-47d038c21d9ba99230d0c2f36a8174e24128258e.zip |
elasticsearch: add 5.x package, service
Diffstat (limited to 'nixos/modules/services/search')
-rw-r--r-- | nixos/modules/services/search/elasticsearch.nix | 76 |
1 files changed, 58 insertions, 18 deletions
diff --git a/nixos/modules/services/search/elasticsearch.nix b/nixos/modules/services/search/elasticsearch.nix index 574f74d547a5..c76c86b0cadc 100644 --- a/nixos/modules/services/search/elasticsearch.nix +++ b/nixos/modules/services/search/elasticsearch.nix @@ -5,13 +5,22 @@ with lib; let cfg = config.services.elasticsearch; + es5 = builtins.compareVersions (builtins.parseDrvName cfg.package.name).version "5" >= 0; + esConfig = '' network.host: ${cfg.listenAddress} - network.port: ${toString cfg.port} - network.tcp.port: ${toString cfg.tcp_port} - # TODO: find a way to enable security manager - security.manager.enabled: false cluster.name: ${cfg.cluster_name} + + ${if es5 then '' + http.port: ${toString cfg.port} + transport.tcp.port: ${toString cfg.tcp_port} + '' else '' + network.port: ${toString cfg.port} + network.tcp.port: ${toString cfg.tcp_port} + # TODO: find a way to enable security manager + security.manager.enabled: false + ''} + ${cfg.extraConf} ''; @@ -19,13 +28,18 @@ let name = "elasticsearch-config"; paths = [ (pkgs.writeTextDir "elasticsearch.yml" esConfig) - (pkgs.writeTextDir "logging.yml" cfg.logging) + (if es5 then (pkgs.writeTextDir "log4j2.properties" cfg.logging) + else (pkgs.writeTextDir "logging.yml" cfg.logging)) ]; + # Elasticsearch 5.x won't start when the scripts directory does not exist + postBuild = if es5 then "${pkgs.coreutils}/bin/mkdir -p $out/scripts" else ""; }; esPlugins = pkgs.buildEnv { name = "elasticsearch-plugins"; paths = cfg.plugins; + # Elasticsearch 5.x won't start when the plugins directory does not exist + postBuild = if es5 then "${pkgs.coreutils}/bin/mkdir -p $out/plugins" else ""; }; in { @@ -85,18 +99,30 @@ in { logging = mkOption { description = "Elasticsearch logging configuration."; - default = '' - rootLogger: INFO, console - logger: - action: INFO - com.amazonaws: WARN - appender: - console: - type: console - layout: - type: consolePattern - conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" - ''; + default = + if es5 then '' + logger.action.name = org.elasticsearch.action + logger.action.level = info + + appender.console.type = Console + appender.console.name = console + appender.console.layout.type = PatternLayout + appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] %marker%m%n + + rootLogger.level = info + rootLogger.appenderRef.console.ref = console + '' else '' + rootLogger: INFO, console + logger: + action: INFO + com.amazonaws: WARN + appender: + console: + type: console + layout: + type: consolePattern + conversionPattern: "[%d{ISO8601}][%-5p][%-25c] %m%n" + ''; type = types.str; }; @@ -112,6 +138,12 @@ in { description = "Extra command line options for the elasticsearch launcher."; default = []; type = types.listOf types.str; + }; + + extraJavaOptions = mkOption { + description = "Extra command line options for Java."; + default = []; + type = types.listOf types.str; example = [ "-Djava.net.preferIPv4Stack=true" ]; }; @@ -133,13 +165,21 @@ in { path = [ pkgs.inetutils ]; environment = { ES_HOME = cfg.dataDir; + ES_JAVA_OPTS = toString ([ "-Des.path.conf=${configDir}" ] ++ cfg.extraJavaOptions); }; serviceConfig = { - ExecStart = "${cfg.package}/bin/elasticsearch -Des.path.conf=${configDir} ${toString cfg.extraCmdLineOptions}"; + ExecStart = "${cfg.package}/bin/elasticsearch ${toString cfg.extraCmdLineOptions}"; User = "elasticsearch"; PermissionsStartOnly = true; + LimitNOFILE = "1024000"; }; preStart = '' + # Only set vm.max_map_count if lower than ES required minimum + # This avoids conflict if configured via boot.kernel.sysctl + if [ `${pkgs.procps}/bin/sysctl -n vm.max_map_count` -lt 262144 ]; then + ${pkgs.procps}/bin/sysctl -w vm.max_map_count=262144 + fi + mkdir -m 0700 -p ${cfg.dataDir} # Install plugins |