diff options
author | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-17 12:02:23 +0200 |
---|---|---|
committer | Stephane Gamard <stephane.gamard@searchbox.com> | 2014-07-18 11:27:59 +0200 |
commit | a71ca29b0cdce94b01f48e9b1a281f222c5edbe2 (patch) | |
tree | dd513e6744375fed9d311705c3559c9cb3a43441 | |
parent | d45f4535d2d3037ba297c2d54b0b77f459652c43 (diff) | |
download | sonarqube-a71ca29b0cdce94b01f48e9b1a281f222c5edbe2.tar.gz sonarqube-a71ca29b0cdce94b01f48e9b1a281f222c5edbe2.zip |
SONAR-5409 - Added explicit child shutdown on JVM shutdown (child does not have to wait for ping failure)
-rw-r--r-- | sonar-start/src/main/java/org/sonar/start/StartServer.java | 83 |
1 files changed, 47 insertions, 36 deletions
diff --git a/sonar-start/src/main/java/org/sonar/start/StartServer.java b/sonar-start/src/main/java/org/sonar/start/StartServer.java index fa8ea9ff658..e28cb51df99 100644 --- a/sonar-start/src/main/java/org/sonar/start/StartServer.java +++ b/sonar-start/src/main/java/org/sonar/start/StartServer.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap; import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.sonar.process.NetworkUtils; import org.sonar.process.ProcessWrapper; import java.io.File; @@ -38,20 +39,17 @@ public final class StartServer { private final static Logger LOGGER = LoggerFactory.getLogger(StartServer.class); - private final static String SONAR_HOME = "SONAR_HOME"; + public final static String SONAR_HOME = "SONAR_HOME"; private final Env env; private final String esPort; private final Map<String, String> properties; + private final Thread shutdownHook; private ExecutorService executor; private ProcessWrapper elasticsearch; private ProcessWrapper sonarqube; - public StartServer(Env env) throws IOException { - this(env, new String[]{}); - } - public StartServer(Env env, String... args) throws IOException { this.env = env; this.executor = Executors.newFixedThreadPool(2); @@ -61,50 +59,43 @@ public final class StartServer { if (Arrays.binarySearch(args, "--debug") > -1) { properties.put("esDebug", "true"); } - } - - public void shutdown() { - LOGGER.info("Shutting down sonar Node"); - } - - public void start() { - - // Start ES - //this.startES(NetworkUtils.freePort()); + shutdownHook = new Thread(new Runnable() { + @Override + public void run() { + StartServer.this.stop(); + } + }); - // Start SQ - this.startSQ(NetworkUtils.freePort()); + Runtime.getRuntime().addShutdownHook(shutdownHook); + } -// // And monitor the activity -// try { -// monitor.join(); -// } catch (InterruptedException e) { -// LOGGER.warn("Shutting down the node..."); -// } - // shutdown(); + public void stop() { + LOGGER.info("Shutting down all node services"); + Runtime.getRuntime().removeShutdownHook(shutdownHook); + if (elasticsearch != null) { + LOGGER.info("Shutting down ES service"); + elasticsearch.stop(); + } + if (sonarqube != null) { + LOGGER.info("Shutting down SQ service"); + sonarqube.stop(); + } } + public void start() { - private void startSQ(int port) { - sonarqube = new ProcessWrapper( - "org.sonar.application.StartServer", - ImmutableMap.of( - "SONAR_HOME", env.rootDir().getAbsolutePath(), - "test", "test"), - "SQ", port, - env.rootDir().getAbsolutePath() + "/lib/server/sonar-application-4.5-SNAPSHOT.jar"); - } + String workingDirectory = env.rootDir().getAbsolutePath(); - private void startES(int port) { + // Start ES elasticsearch = new ProcessWrapper( + env.rootDir().getAbsolutePath(), "org.sonar.search.ElasticSearch", ImmutableMap.of( - "SONAR_HOME", env.rootDir().getAbsolutePath(), "esDebug", properties.containsKey("esDebug") ? properties.get("esDebug") : "false", "esPort", esPort, "esHome", env.rootDir().getAbsolutePath()), - "ES", port, + "ES", env.rootDir().getAbsolutePath() + "/lib/search/sonar-search-4.5-SNAPSHOT.jar"); while (!elasticsearch.isReady()) { @@ -115,8 +106,28 @@ public final class StartServer { e.printStackTrace(); } } + + // Start SQ +// sonarqube = new ProcessWrapper( +// workingDirectory, +// "org.sonar.application.SonarServer", +// ImmutableMap.of( +// "SONAR_HOME", workingDirectory, +// "esPort", esPort, +// "test", "test"), +// "SQ", +// env.rootDir().getAbsolutePath() + "/lib/server/sonar-application-4.5-SNAPSHOT.jar"); + +// // And monitor the activity +// try { +// monitor.join(); +// } catch (InterruptedException e) { +// LOGGER.warn("Shutting down the node..."); +// } + // shutdown(); } + public static void main(String... args) throws InterruptedException, IOException, URISyntaxException { String home = System.getenv(SONAR_HOME); |