Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove exitVM permissions #10963

Merged
merged 3 commits into from May 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
106 changes: 41 additions & 65 deletions src/main/java/org/elasticsearch/bootstrap/Bootstrap.java
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.jna.Kernel32Library;
import org.elasticsearch.common.jna.Natives;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.logging.log4j.LogConfigurator;
Expand All @@ -55,11 +56,33 @@
*/
public class Bootstrap {

private Node node;
private static volatile Bootstrap INSTANCE;

private static volatile Thread keepAliveThread;
private static volatile CountDownLatch keepAliveLatch;
private static Bootstrap bootstrap;
private Node node;
private final CountDownLatch keepAliveLatch = new CountDownLatch(1);
private final Thread keepAliveThread;

/** creates a new instance */
Bootstrap() {
keepAliveThread = new Thread(new Runnable() {
@Override
public void run() {
try {
keepAliveLatch.await();
} catch (InterruptedException e) {
// bail out
}
}
}, "elasticsearch[keepAlive/" + Version.CURRENT + "]");
keepAliveThread.setDaemon(false);
// keep this thread alive (non daemon thread) until we shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
keepAliveLatch.countDown();
}
});
}

/** initialize native resources */
public static void initializeNatives(boolean mlockAll, boolean ctrlHandler) {
Expand All @@ -77,7 +100,7 @@ public boolean handle(int code) {
ESLogger logger = Loggers.getLogger(Bootstrap.class);
logger.info("running graceful exit on windows");

System.exit(0);
Bootstrap.INSTANCE.stop();
return true;
}
return false;
Expand Down Expand Up @@ -148,47 +171,22 @@ private static Tuple<Settings, Environment> initialSettings() {
return InternalSettingsPreparer.prepareSettings(EMPTY_SETTINGS, true);
}

/**
* hook for JSVC
*/
public void init(String[] args) throws Exception {
Tuple<Settings, Environment> tuple = initialSettings();
Settings settings = tuple.v1();
Environment environment = tuple.v2();
setupLogging(settings, environment);
setup(true, settings, environment);
}

/**
* hook for JSVC
*/
public void start() {
private void start() {
node.start();
keepAliveThread.start();
}

/**
* hook for JSVC
*/
public void stop() {
destroy();
}


/**
* hook for JSVC
*/
public void destroy() {
node.close();
}

public static void close(String[] args) {
bootstrap.destroy();
keepAliveLatch.countDown();
private void stop() {
try {
Releasables.close(node);
} finally {
keepAliveLatch.countDown();
}
}

public static void main(String[] args) {
System.setProperty("es.logger.prefix", "");
bootstrap = new Bootstrap();
INSTANCE = new Bootstrap();
final String pidFile = System.getProperty("es.pidfile", System.getProperty("es-pidfile"));

if (pidFile != null) {
Expand Down Expand Up @@ -240,40 +238,18 @@ public static void main(String[] args) {
// fail if using broken version
JVMCheck.check();

keepAliveLatch = new CountDownLatch(1);
// keep this thread alive (non daemon thread) until we shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
keepAliveLatch.countDown();
}
});

bootstrap.setup(true, settings, environment);
INSTANCE.setup(true, settings, environment);

stage = "Startup";
bootstrap.start();
INSTANCE.start();

if (!foreground) {
closeSysError();
}

keepAliveThread = new Thread(new Runnable() {
@Override
public void run() {
try {
keepAliveLatch.await();
} catch (InterruptedException e) {
// bail out
}
}
}, "elasticsearch[keepAlive/" + Version.CURRENT + "]");
keepAliveThread.setDaemon(false);
keepAliveThread.start();
} catch (Throwable e) {
ESLogger logger = Loggers.getLogger(Bootstrap.class);
if (bootstrap.node != null) {
logger = Loggers.getLogger(Bootstrap.class, bootstrap.node.settings().get("name"));
if (INSTANCE.node != null) {
logger = Loggers.getLogger(Bootstrap.class, INSTANCE.node.settings().get("name"));
}
String errorMessage = buildErrorMessage(stage, e);
if (foreground) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java
Expand Up @@ -24,10 +24,6 @@
*/
public class Elasticsearch extends Bootstrap {

public static void close(String[] args) {
Bootstrap.close(args);
}

public static void main(String[] args) {
Bootstrap.main(args);
}
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/org/elasticsearch/bootstrap/ElasticsearchF.java
Expand Up @@ -25,10 +25,6 @@
*/
public class ElasticsearchF {

public static void close(String[] args) {
Bootstrap.close(args);
}

public static void main(String[] args) {
System.setProperty("es.foreground", "yes");
Bootstrap.main(args);
Expand Down
Expand Up @@ -63,9 +63,6 @@ grant {
// needed by ImmutableSettings
permission java.lang.RuntimePermission "getenv.*";

// needed by BootStrap, etc
permission java.lang.RuntimePermission "exitVM.*";

// needed by PluginManager
permission java.lang.RuntimePermission "setFactory";

Expand Down