package org.sonar.application.process;
import java.io.File;
-import java.nio.file.Path;
import java.util.Map;
import java.util.Optional;
import org.sonar.application.config.AppSettings;
File logDir = new File(settingsMap.get("path.logs"));
File confDir = new File(settingsMap.get("path.conf"));
- Path jvmOptionsFile = confDir.toPath().resolve("jvm.options");
EsCommand res = new EsCommand(ProcessId.ELASTICSEARCH)
.setWorkDir(executable.getParentFile().getParentFile())
.setExecutable(executable)
.setPort(Integer.valueOf(settingsMap.get("transport.tcp.port")))
.addJvmOption(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_OPTS))
.addJvmOption(settings.getProps().nonNullValue(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS))
- .setJvmOptionsFile(jvmOptionsFile)
- .setEnvVariable("ES_JVM_OPTIONS", jvmOptionsFile.toString())
.setEnvVariable("JAVA_HOME", System.getProperties().getProperty("java.home"));
settingsMap.forEach((key, value) -> res.addEsOption("-E" + key + "=" + value));
package org.sonar.application.process;
import java.io.File;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
private Properties log4j2Properties;
private List<String> esOptions = new ArrayList<>();
private List<String> jvmOptions = new ArrayList<>();
- private Path jvmOptionsFile;
public EsCommand(ProcessId id) {
super(id);
return this;
}
- public Path getJvmOptionsFile() {
- return jvmOptionsFile;
- }
-
- public EsCommand setJvmOptionsFile(Path jvmOptionsFile) {
- this.jvmOptionsFile = jvmOptionsFile;
- return this;
- }
}
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
-import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
import java.util.function.Supplier;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
try {
IOUtils.copy(getClass().getResourceAsStream("elasticsearch.yml"), new FileOutputStream(new File(confDir, "elasticsearch.yml")));
- IOUtils.copy(getClass().getResourceAsStream("jvm.options"), new FileOutputStream(new File(confDir, "jvm.options")));
+ writeJvmOptions(esCommand, new File(confDir, "jvm.options"));
esCommand.getLog4j2Properties().store(new FileOutputStream(new File(confDir, "log4j2.properties")), "log42 properties file for ES bundled in SonarQube");
} catch (IOException e) {
throw new IllegalStateException("Failed to write ES configuration files", e);
commands.add(esCommand.getExecutable().getAbsolutePath());
commands.addAll(esCommand.getEsOptions());
- writeJvmOptions(esCommand);
-
return create(esCommand, commands);
}
- private static void writeJvmOptions(EsCommand esCommand) {
- Path jvmOptionsFile = esCommand.getJvmOptionsFile();
+ private static void writeJvmOptions(EsCommand esCommand, File jvmOptionsFile) {
String jvmOptions = esCommand.getJvmOptions()
.stream()
.collect(Collectors.joining("\n"));
String jvmOptionsContent = ELASTICSEARCH_JVM_OPTIONS_HEADER + jvmOptions;
try {
- Files.write(jvmOptionsFile, jvmOptionsContent.getBytes(Charset.forName("UTF-8")));
+ Files.write(jvmOptionsFile.toPath(), jvmOptionsContent.getBytes(Charset.forName("UTF-8")));
} catch (IOException e) {
throw new IllegalStateException("Cannot write Elasticsearch jvm options file", e);
}
+++ /dev/null
-## JVM configuration
-
-################################################################
-## IMPORTANT: JVM heap size
-################################################################
-##
-## You should always set the min and max JVM heap
-## size to the same value. For example, to set
-## the heap to 4 GB, set:
-##
-## -Xms4g
-## -Xmx4g
-##
-## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
-## for more information
-##
-################################################################
-
-# Xms represents the initial size of total heap space
-# Xmx represents the maximum size of total heap space
-
--Xms2g
--Xmx2g
-
-################################################################
-## Expert settings
-################################################################
-##
-## All settings below this section are considered
-## expert settings. Don't tamper with them unless
-## you understand what you are doing
-##
-################################################################
-
-## GC configuration
--XX:+UseConcMarkSweepGC
--XX:CMSInitiatingOccupancyFraction=75
--XX:+UseCMSInitiatingOccupancyOnly
-
-## optimizations
-
-# disable calls to System#gc
--XX:+DisableExplicitGC
-
-# pre-touch memory pages used by the JVM during initialization
--XX:+AlwaysPreTouch
-
-## basic
-
-# force the server VM
--server
-
-# set to headless, just in case
--Djava.awt.headless=true
-
-# ensure UTF-8 encoding by default (e.g. filenames)
--Dfile.encoding=UTF-8
-
-# use our provided JNA always versus the system one
--Djna.nosys=true
-
-# use old-style file permissions on JDK9
--Djdk.io.permissionsUseCanonicalPath=true
-
-# flags to keep Netty from being unsafe
--Dio.netty.noUnsafe=true
--Dio.netty.noKeySetOptimization=true
-
-# log4j 2
--Dlog4j.shutdownHookEnabled=false
--Dlog4j2.disable.jmx=true
--Dlog4j.skipJansi=true
-
-## heap dumps
-
-# generate a heap dump when an allocation from the Java heap fails
-# heap dumps are created in the working directory of the JVM
--XX:+HeapDumpOnOutOfMemoryError
-
-# specify an alternative path for heap dumps
-# ensure the directory exists and has sufficient space
-#-XX:HeapDumpPath=${heap.dump.path}
-
-## GC logging
-
-#-XX:+PrintGCDetails
-#-XX:+PrintGCTimeStamps
-#-XX:+PrintGCDateStamps
-#-XX:+PrintClassHistogram
-#-XX:+PrintTenuringDistribution
-#-XX:+PrintGCApplicationStoppedTime
-
-# log GC status to a file with time stamps
-# ensure the directory exists
-#-Xloggc:${loggc}
-
-# Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON.
-# If documents were already indexed with unquoted fields in a previous version
-# of Elasticsearch, some operations may throw errors.
-#
-# WARNING: This option will be removed in Elasticsearch 6.0.0 and is provided
-# only for migration purposes.
-#-Delasticsearch.json.allow_unquoted_field_names=true