diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-01-08 18:01:57 +0100 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-01-13 13:42:43 +0100 |
commit | 5db076096966170cde636fa2c41d7777abca193e (patch) | |
tree | 650eb1d38a41d78f76f363ef3a748b785107d3ec /sonar-application/src/main/java/org/sonar/application/App.java | |
parent | 255e54d582d02ab72d1b33f440656fb2d5ae9f8c (diff) | |
download | sonarqube-5db076096966170cde636fa2c41d7777abca193e.tar.gz sonarqube-5db076096966170cde636fa2c41d7777abca193e.zip |
SONAR-7168 fix stop during restart not working
lifeCycle transition from RESTARTING to STOPPING should actually _not_ be allowed because it can occur when restarting child processes (the WatcherThreads detects that stop and tries to shutdown all other processes), this fixes the issue by adding a HARD_STOPPING state, representing a not gracefull stop, to which transition from RESTARTING is allowed
adds class AllProcessesCommands which implements access to sharedMemory for any process and is now used as the underlying implementation of DefaultProcessCommands. This class allows using a single IO to access sharedMemory from App
Diffstat (limited to 'sonar-application/src/main/java/org/sonar/application/App.java')
-rw-r--r-- | sonar-application/src/main/java/org/sonar/application/App.java | 37 |
1 files changed, 11 insertions, 26 deletions
diff --git a/sonar-application/src/main/java/org/sonar/application/App.java b/sonar-application/src/main/java/org/sonar/application/App.java index db78e1bf0c8..f704fcc41a7 100644 --- a/sonar-application/src/main/java/org/sonar/application/App.java +++ b/sonar-application/src/main/java/org/sonar/application/App.java @@ -19,35 +19,28 @@ */ package org.sonar.application; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; -import org.sonar.process.DefaultProcessCommands; import org.sonar.process.MinimumViableSystem; -import org.sonar.process.ProcessCommands; import org.sonar.process.ProcessProperties; import org.sonar.process.Props; -import org.sonar.process.StopWatcher; import org.sonar.process.Stoppable; import org.sonar.process.monitor.JavaCommand; import org.sonar.process.monitor.Monitor; -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Properties; - /** * Entry-point of process that starts and monitors elasticsearch and web servers */ public class App implements Stoppable { - private static final int APP_PROCESS_NUMBER = 0; - private final Monitor monitor; - private StopWatcher stopWatcher = null; - public App() { - this(Monitor.create()); + public App(File tempDir) { + this(Monitor.create(tempDir)); } App(Monitor monitor) { @@ -56,10 +49,7 @@ public class App implements Stoppable { public void start(Props props) { if (props.valueAsBoolean(ProcessProperties.ENABLE_STOP_COMMAND, false)) { - File tempDir = props.nonNullValueAsFile(ProcessProperties.PATH_TEMP); - ProcessCommands commands = new DefaultProcessCommands(tempDir, APP_PROCESS_NUMBER); - stopWatcher = new StopWatcher(commands, this); - stopWatcher.start(); + monitor.watchForHardStop(); } monitor.start(createCommands(props)); monitor.awaitTermination(); @@ -68,14 +58,12 @@ public class App implements Stoppable { private List<JavaCommand> createCommands(Props props) { List<JavaCommand> commands = new ArrayList<>(); File homeDir = props.nonNullValueAsFile(ProcessProperties.PATH_HOME); - File tempDir = props.nonNullValueAsFile(ProcessProperties.PATH_TEMP); JavaCommand elasticsearch = new JavaCommand("search"); elasticsearch .setWorkDir(homeDir) .addJavaOptions("-Djava.awt.headless=true") .addJavaOptions(props.nonNullValue(ProcessProperties.SEARCH_JAVA_OPTS)) .addJavaOptions(props.nonNullValue(ProcessProperties.SEARCH_JAVA_ADDITIONAL_OPTS)) - .setTempDir(tempDir.getAbsoluteFile()) .setClassName("org.sonar.search.SearchServer") .setArguments(props.rawProperties()) .addClasspath("./lib/common/*") @@ -89,7 +77,6 @@ public class App implements Stoppable { .addJavaOptions(ProcessProperties.WEB_ENFORCED_JVM_ARGS) .addJavaOptions(props.nonNullValue(ProcessProperties.WEB_JAVA_OPTS)) .addJavaOptions(props.nonNullValue(ProcessProperties.WEB_JAVA_ADDITIONAL_OPTS)) - .setTempDir(tempDir.getAbsoluteFile()) // required for logback tomcat valve .setEnvVariable(ProcessProperties.PATH_LOGS, props.nonNullValue(ProcessProperties.PATH_LOGS)) .setClassName("org.sonar.server.app.WebServer") @@ -118,16 +105,14 @@ public class App implements Stoppable { AppLogging logging = new AppLogging(); logging.configure(props); - App app = new App(); + File tempDir = props.nonNullValueAsFile(ProcessProperties.PATH_TEMP); + App app = new App(tempDir); app.start(props); } - StopWatcher getStopWatcher() { - return stopWatcher; - } - @Override public void stopAsync() { - monitor.stopAsync(); + monitor.stop(); } + } |