]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-5410 - Updated shutdown
authorStephane Gamard <stephane.gamard@searchbox.com>
Fri, 11 Jul 2014 13:39:42 +0000 (15:39 +0200)
committerStephane Gamard <stephane.gamard@searchbox.com>
Tue, 15 Jul 2014 20:54:53 +0000 (22:54 +0200)
server/sonar-process/src/main/java/org/sonar/process/MonitorService.java
server/sonar-process/src/main/java/org/sonar/process/Process.java
server/sonar-process/src/main/java/org/sonar/process/ProcessWrapper.java
sonar-start/src/main/java/org/sonar/start/StartServer.java

index 0517ca3d28a759318f6331564842f9f29f053237..b4f0a07e3101aeb466bc86bf3030b7954d72c104 100644 (file)
@@ -65,7 +65,7 @@ public class MonitorService extends Thread {
         ; // To not do anything.
       }
       if (!checkAllProcessPing(time)) {
-        break;
+        Thread.currentThread().interrupt();
       }
     }
   }
index 6b239014b6d06e04c77b0cc6d4d5b8c7d3ff5985..667776f86e9bff6d18bfc608d68fa03665a16e31 100644 (file)
@@ -40,7 +40,7 @@ public abstract class Process implements Runnable {
   private final static Logger LOGGER = LoggerFactory.getLogger(Process.class);
 
   protected Long heartBeatInterval = 1000L;
-  protected final Thread monitor;
+  protected Thread monitor;
 
   final String name;
   final Integer port;
@@ -82,17 +82,20 @@ public abstract class Process implements Runnable {
   public abstract void onStop();
 
   public final void start() {
+    LOGGER.info("Process[{}]::start", name);
     onStart();
   }
 
   public final void shutdown() {
+    LOGGER.info("Process[{}]::shutdown", name);
     this.monitor.interrupt();
+    this.monitor = null;
     this.onStop();
   }
 
   @Override
   public void run() {
-    LOGGER.debug("Setting up heartbeat on port '{}'", port);
+    LOGGER.info("Process[{}]::heartbeat({}) START", name, port);
     try {
       byte[] data = name.getBytes();
       DatagramPacket pack =
@@ -111,5 +114,6 @@ public abstract class Process implements Runnable {
     } catch (IOException e) {
       throw new IllegalStateException("Heartbeat Thread for " + name + " could not communicate to socket", e);
     }
+    LOGGER.warn("Process[{}]::heartbeat OVER", name);
   }
 }
\ No newline at end of file
index 74b6ad438504e1755e5c22ae0257de2cad2958d1..aa7dfe3fccf9cd118740c06e3eeef1a3c30e5631 100644 (file)
@@ -76,7 +76,14 @@ public class ProcessWrapper extends Thread {
   public void shutdown() {
     LOGGER.info("Shutting down '{}'", this.getName());
     this.interrupt();
-    this.process.destroy();
+//    try {
+//      process.destroy();
+//    } catch (InterruptedException e) {
+//      //TODO do kill only in last resort...
+//      process.destroy();
+//    } finally {
+      process = null;
+//    }
   }
 
   private class StreamGobbler extends Thread {
index 918c1142ae695d2aa7e3dd6e1eaca6fb93f34a78..25123e4752f1cf3d6971312c5f3a68091d58ac2e 100644 (file)
@@ -44,11 +44,11 @@ public final class StartServer {
   private final static String SONAR_HOME = "SONAR_HOME";
 
   private final Env env;
-  private final ExecutorService executor;
-  private final MonitorService monitor;
   private final String esPort;
   private final Map<String, String> properties;
 
+  private ExecutorService executor;
+  private MonitorService monitor;
   private ProcessWrapper elasticsearch;
   private ProcessWrapper sonarqube;
 
@@ -70,27 +70,44 @@ public final class StartServer {
     Runtime.getRuntime().addShutdownHook(new Thread() {
       @Override
       public void run() {
-        LOGGER.info("Shutting down sonar Node");
-        if (elasticsearch != null) {
-          elasticsearch.shutdown();
-        }
-        if (sonarqube != null) {
-          sonarqube.shutdown();
-        }
-        executor.shutdown();
-        try {
-          executor.awaitTermination(10L, TimeUnit.SECONDS);
-        } catch (InterruptedException e) {
-          LOGGER.warn("Executing terminated", e);
-        }
+        shutdown();
       }
     });
+
+    monitor.start();
   }
 
   private DatagramSocket systemAvailableSocket() throws IOException {
     return new DatagramSocket(0);
   }
 
+  public void shutdown() {
+    LOGGER.info("Shutting down sonar Node");
+    if (monitor != null) {
+      monitor.interrupt();
+      monitor = null;
+    }
+    if (elasticsearch != null) {
+      elasticsearch.shutdown();
+      elasticsearch = null;
+    }
+
+    if (sonarqube != null) {
+      sonarqube.shutdown();
+      sonarqube = null;
+    }
+
+    if (executor != null) {
+      executor.shutdown();
+      try {
+        executor.awaitTermination(10L, TimeUnit.SECONDS);
+      } catch (InterruptedException e) {
+        LOGGER.warn("Executing terminated", e);
+      }
+      executor = null;
+    }
+  }
+
   public void start() {
 
     // Start ES
@@ -100,12 +117,12 @@ public final class StartServer {
     this.startSQ();
 
     // And monitor the activity
-    monitor.run();
-    LOGGER.warn("Shutting down the node...");
-
-    // If monitor is finished, we're done. Cleanup
-    executor.shutdownNow();
-
+    try {
+      monitor.join();
+    } catch (InterruptedException e) {
+      LOGGER.warn("Shutting down the node...");
+    }
+    shutdown();
   }
 
   private void registerProcess(ProcessWrapper process) {
@@ -145,7 +162,8 @@ public final class StartServer {
 
   public static void main(String... args) throws InterruptedException, IOException, URISyntaxException {
 
-    String home = System.getenv(SONAR_HOME);
+    //String home = System.getenv(SONAR_HOME);
+    String home = "/Volumes/data/sonar/sonarqube/sonar-start/target/sonarqube-4.5-SNAPSHOT";
 
     //Check if we have a SONAR_HOME
     if (StringUtils.isEmpty(home)) {