Allow disabling of sigar via settings
Sigar can only be disabled by removing the binaries. This is tricky for our tests and might cause a lot of trouble if a user wants or needs to do it. This commit allows to disable sigar with a simple boolean flag in the settings. Closes #9582
This commit is contained in:
parent
19de7039a3
commit
ada98ba0c4
|
@ -38,6 +38,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.monitor.jvm.JvmInfo;
|
||||
import org.elasticsearch.monitor.process.JmxProcessProbe;
|
||||
import org.elasticsearch.monitor.sigar.SigarService;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.node.NodeBuilder;
|
||||
import org.elasticsearch.node.internal.InternalSettingsPreparer;
|
||||
|
@ -85,7 +86,8 @@ public class Bootstrap {
|
|||
}
|
||||
|
||||
/** initialize native resources */
|
||||
public static void initializeNatives(boolean mlockAll, boolean ctrlHandler) {
|
||||
public static void initializeNatives(boolean mlockAll, boolean ctrlHandler, boolean loadSigar) {
|
||||
final ESLogger logger = Loggers.getLogger(Bootstrap.class);
|
||||
// mlockall if requested
|
||||
if (mlockAll) {
|
||||
if (Constants.WINDOWS) {
|
||||
|
@ -98,7 +100,7 @@ public class Bootstrap {
|
|||
// check if the user is running as root, and bail
|
||||
if (Natives.definitelyRunningAsRoot()) {
|
||||
if (Boolean.parseBoolean(System.getProperty("es.insecure.allow.root"))) {
|
||||
Loggers.getLogger(Bootstrap.class).warn("running as ROOT user. this is a bad idea!");
|
||||
logger.warn("running as ROOT user. this is a bad idea!");
|
||||
} else {
|
||||
throw new RuntimeException("don't run elasticsearch as root.");
|
||||
}
|
||||
|
@ -110,9 +112,7 @@ public class Bootstrap {
|
|||
@Override
|
||||
public boolean handle(int code) {
|
||||
if (CTRL_CLOSE_EVENT == code) {
|
||||
ESLogger logger = Loggers.getLogger(Bootstrap.class);
|
||||
logger.info("running graceful exit on windows");
|
||||
|
||||
Bootstrap.INSTANCE.stop();
|
||||
return true;
|
||||
}
|
||||
|
@ -127,13 +127,17 @@ public class Bootstrap {
|
|||
} catch (Throwable ignored) {
|
||||
// we've already logged this.
|
||||
}
|
||||
|
||||
// initialize sigar explicitly
|
||||
try {
|
||||
Sigar.load();
|
||||
Loggers.getLogger(Bootstrap.class).trace("sigar libraries loaded successfully");
|
||||
} catch (Throwable t) {
|
||||
Loggers.getLogger(Bootstrap.class).trace("failed to load sigar libraries", t);
|
||||
|
||||
if (loadSigar) {
|
||||
// initialize sigar explicitly
|
||||
try {
|
||||
Sigar.load();
|
||||
logger.trace("sigar libraries loaded successfully");
|
||||
} catch (Throwable t) {
|
||||
logger.trace("failed to load sigar libraries", t);
|
||||
}
|
||||
} else {
|
||||
logger.trace("sigar not loaded, disabled via settings");
|
||||
}
|
||||
|
||||
// init lucene random seed. it will use /dev/urandom where available:
|
||||
|
@ -142,7 +146,8 @@ public class Bootstrap {
|
|||
|
||||
private void setup(boolean addShutdownHook, Settings settings, Environment environment) throws Exception {
|
||||
initializeNatives(settings.getAsBoolean("bootstrap.mlockall", false),
|
||||
settings.getAsBoolean("bootstrap.ctrlhandler", true));
|
||||
settings.getAsBoolean("bootstrap.ctrlhandler", true),
|
||||
settings.getAsBoolean("bootstrap.sigar", true));
|
||||
|
||||
if (addShutdownHook) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread() {
|
||||
|
|
|
@ -34,22 +34,23 @@ public class SigarService extends AbstractComponent {
|
|||
@Inject
|
||||
public SigarService(Settings settings) {
|
||||
super(settings);
|
||||
|
||||
Sigar sigar = null;
|
||||
try {
|
||||
sigar = new Sigar();
|
||||
// call it to make sure the library was loaded
|
||||
sigar.getPid();
|
||||
logger.trace("sigar loaded successfully");
|
||||
} catch (Throwable t) {
|
||||
logger.trace("failed to load sigar", t);
|
||||
if (sigar != null) {
|
||||
try {
|
||||
sigar.close();
|
||||
} catch (Throwable t1) {
|
||||
// ignore
|
||||
} finally {
|
||||
sigar = null;
|
||||
if (settings.getAsBoolean("bootstrap.sigar", true)) {
|
||||
try {
|
||||
sigar = new Sigar();
|
||||
// call it to make sure the library was loaded
|
||||
sigar.getPid();
|
||||
logger.trace("sigar loaded successfully");
|
||||
} catch (Throwable t) {
|
||||
logger.trace("failed to load sigar", t);
|
||||
if (sigar != null) {
|
||||
try {
|
||||
sigar.close();
|
||||
} catch (Throwable t1) {
|
||||
// ignore
|
||||
} finally {
|
||||
sigar = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ public class BootstrapForTesting {
|
|||
|
||||
static {
|
||||
// just like bootstrap, initialize natives, then SM
|
||||
Bootstrap.initializeNatives(true, true);
|
||||
Bootstrap.initializeNatives(true, true, true);
|
||||
|
||||
// make sure java.io.tmpdir exists always (in case code uses it in a static initializer)
|
||||
Path javaTmpDir = PathUtils.get(Objects.requireNonNull(System.getProperty("java.io.tmpdir"),
|
||||
|
|
|
@ -90,6 +90,7 @@ import org.elasticsearch.indices.breaker.CircuitBreakerService;
|
|||
import org.elasticsearch.indices.breaker.HierarchyCircuitBreakerService;
|
||||
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
|
||||
import org.elasticsearch.indices.recovery.RecoverySettings;
|
||||
import org.elasticsearch.monitor.sigar.SigarService;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.node.service.NodeService;
|
||||
import org.elasticsearch.plugins.PluginsService;
|
||||
|
@ -277,6 +278,7 @@ public final class InternalTestCluster extends TestCluster {
|
|||
builder.put("path.data", dataPath.toString());
|
||||
}
|
||||
}
|
||||
builder.put("bootstrap.sigar", rarely());
|
||||
builder.put("path.home", baseDir);
|
||||
builder.put("path.repo", baseDir.resolve("repos"));
|
||||
builder.put("transport.tcp.port", BASE_PORT + "-" + (BASE_PORT+100));
|
||||
|
|
Loading…
Reference in New Issue