|
@@ -36,6 +36,7 @@ import org.elasticsearch.node.NodeValidationException;
|
|
|
import java.io.IOException;
|
|
|
import java.nio.file.Path;
|
|
|
import java.security.Permission;
|
|
|
+import java.security.Security;
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Locale;
|
|
|
|
|
@@ -72,13 +73,19 @@ class Elasticsearch extends EnvironmentAwareCommand {
|
|
|
* Main entry point for starting elasticsearch
|
|
|
*/
|
|
|
public static void main(final String[] args) throws Exception {
|
|
|
- // we want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on the
|
|
|
- // presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy)
|
|
|
+ overrideDnsCachePolicyProperties();
|
|
|
+ /*
|
|
|
+ * We want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on the
|
|
|
+ * presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy). This
|
|
|
+ * forces such policies to take effect immediately.
|
|
|
+ */
|
|
|
System.setSecurityManager(new SecurityManager() {
|
|
|
+
|
|
|
@Override
|
|
|
public void checkPermission(Permission perm) {
|
|
|
// grant all permissions so that we can later set the security manager to the one that we want
|
|
|
}
|
|
|
+
|
|
|
});
|
|
|
LogConfigurator.registerErrorListener();
|
|
|
final Elasticsearch elasticsearch = new Elasticsearch();
|
|
@@ -88,6 +95,22 @@ class Elasticsearch extends EnvironmentAwareCommand {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void overrideDnsCachePolicyProperties() {
|
|
|
+ for (final String property : new String[] {"networkaddress.cache.ttl", "networkaddress.cache.negative.ttl" }) {
|
|
|
+ final String overrideProperty = "es." + property;
|
|
|
+ final String overrideValue = System.getProperty(overrideProperty);
|
|
|
+ if (overrideValue != null) {
|
|
|
+ try {
|
|
|
+ // round-trip the property to an integer and back to a string to ensure that it parses properly
|
|
|
+ Security.setProperty(property, Integer.toString(Integer.valueOf(overrideValue)));
|
|
|
+ } catch (final NumberFormatException e) {
|
|
|
+ throw new IllegalArgumentException(
|
|
|
+ "failed to parse [" + overrideProperty + "] with value [" + overrideValue + "]", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
static int main(final String[] args, final Elasticsearch elasticsearch, final Terminal terminal) throws Exception {
|
|
|
return elasticsearch.main(args, terminal);
|
|
|
}
|