diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-12 15:56:49 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-09-12 15:56:49 +0200 |
commit | e5aea553f53345a490c3d7a0dd89e80358f19e5c (patch) | |
tree | b001f21abcb475377a533b1f7e16d2bfa9675dfc /sonar-application | |
parent | 0ccbeceffbac2071eccca12f807dde9b2934e3eb (diff) | |
parent | 3166381a9020db85e45bfef8ebea9f841736af69 (diff) | |
download | sonarqube-e5aea553f53345a490c3d7a0dd89e80358f19e5c.tar.gz sonarqube-e5aea553f53345a490c3d7a0dd89e80358f19e5c.zip |
Merge remote-tracking branch 'origin/branch-4.5'
Conflicts:
server/process/pom.xml
server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java
server/sonar-process-monitor/pom.xml
server/sonar-process/pom.xml
Diffstat (limited to 'sonar-application')
-rw-r--r-- | sonar-application/pom.xml | 12 | ||||
-rw-r--r-- | sonar-application/src/main/java/org/sonar/application/App.java | 166 |
2 files changed, 67 insertions, 111 deletions
diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index 8e7f1f90012..94495baba59 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -1,6 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -25,6 +24,11 @@ <artifactId>sonar-process</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.codehaus.sonar</groupId> + <artifactId>sonar-process-monitor</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>com.google.code.findbugs</groupId> @@ -237,8 +241,8 @@ <phase>package</phase> <configuration> <target> - <checksum file="${project.build.directory}/sonarqube-${project.version}.zip" algorithm="md5"/> - <checksum file="${project.build.directory}/sonarqube-${project.version}.zip" algorithm="sha"/> + <checksum file="${project.build.directory}/sonarqube-${project.version}.zip" algorithm="md5" /> + <checksum file="${project.build.directory}/sonarqube-${project.version}.zip" algorithm="sha" /> </target> </configuration> <goals> 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 76ac6a16605..600828ec1db 100644 --- a/sonar-application/src/main/java/org/sonar/application/App.java +++ b/sonar-application/src/main/java/org/sonar/application/App.java @@ -21,19 +21,18 @@ package org.sonar.application; import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.sonar.process.JmxUtils; import org.sonar.process.MinimumViableSystem; -import org.sonar.process.Monitor; import org.sonar.process.ProcessLogging; import org.sonar.process.ProcessMXBean; -import org.sonar.process.ProcessUtils; -import org.sonar.process.ProcessWrapper; import org.sonar.process.Props; -import org.sonar.search.SearchServer; +import org.sonar.process.State; +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; /** @@ -41,135 +40,88 @@ import java.util.Properties; */ public class App implements ProcessMXBean { - private Monitor monitor = new Monitor(); - private ProcessWrapper elasticsearch; - private ProcessWrapper server; - private boolean success = false; + private final Monitor monitor; public App() { - JmxUtils.registerMBean(this, "SonarQube"); - ProcessUtils.addSelfShutdownHook(this); + this(Monitor.create()); } - public void start(Props props) throws InterruptedException { - try { - Logger logger = LoggerFactory.getLogger(getClass()); + App(Monitor monitor) { + this.monitor = monitor; + JmxUtils.registerMBean(this, "SonarQube"); + } - monitor.start(); + public void start(Props props) { + monitor.start(createCommands(props)); + monitor.awaitTermination(); + } - File homeDir = props.nonNullValueAsFile("sonar.path.home"); - File tempDir = props.nonNullValueAsFile("sonar.path.temp"); - elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME); - elasticsearch + List<JavaCommand> createCommands(Props props) { + List<JavaCommand> commands = new ArrayList<JavaCommand>(); + File homeDir = props.nonNullValueAsFile("sonar.path.home"); + File tempDir = props.nonNullValueAsFile("sonar.path.temp"); + JavaCommand elasticsearch = new JavaCommand(JmxUtils.SEARCH_SERVER_NAME); + elasticsearch + .setWorkDir(homeDir) + .setJmxPort(props.valueAsInt(DefaultSettings.SEARCH_JMX_PORT)) + .addJavaOptions(props.value(DefaultSettings.SEARCH_JAVA_OPTS)) + .setTempDir(tempDir.getAbsoluteFile()) + .setClassName("org.sonar.search.SearchServer") + .setArguments(props.rawProperties()) + .addClasspath("./lib/common/*") + .addClasspath("./lib/search/*"); + commands.add(elasticsearch); + + // do not yet start SQ in cluster mode. See SONAR-5483 & SONAR-5391 + if (StringUtils.isEmpty(props.value(DefaultSettings.CLUSTER_MASTER))) { + JavaCommand webServer = new JavaCommand(JmxUtils.WEB_SERVER_NAME) .setWorkDir(homeDir) - .setJmxPort(props.valueAsInt(DefaultSettings.SEARCH_JMX_PORT)) - .addJavaOpts(props.value(DefaultSettings.SEARCH_JAVA_OPTS)) - .setTempDirectory(tempDir.getAbsoluteFile()) - .setClassName("org.sonar.search.SearchServer") - .addProperties(props.rawProperties()) + .setJmxPort(props.valueAsInt(DefaultSettings.WEB_JMX_PORT)) + .addJavaOptions(props.nonNullValue(DefaultSettings.WEB_JAVA_OPTS)) + .setTempDir(tempDir.getAbsoluteFile()) + // required for logback tomcat valve + .setEnvVariable("sonar.path.logs", props.nonNullValue("sonar.path.logs")) + .setClassName("org.sonar.server.app.WebServer") + .setArguments(props.rawProperties()) .addClasspath("./lib/common/*") - .addClasspath("./lib/search/*"); - if (elasticsearch.execute()) { - monitor.monitor(elasticsearch); - if (elasticsearch.waitForReady()) { - logger.info("search server is up"); - - // do not yet start SQ in cluster mode. See SONAR-5483 & SONAR-5391 - if (StringUtils.isEmpty(props.value(DefaultSettings.CLUSTER_MASTER))) { - server = new ProcessWrapper(JmxUtils.WEB_SERVER_NAME) - .setWorkDir(homeDir) - .setJmxPort(props.valueAsInt(DefaultSettings.WEB_JMX_PORT)) - .addJavaOpts(props.nonNullValue(DefaultSettings.WEB_JAVA_OPTS)) - .setTempDirectory(tempDir.getAbsoluteFile()) - // required for logback tomcat valve - .setLogDir(props.nonNullValueAsFile("sonar.path.logs")) - .setClassName("org.sonar.server.app.WebServer") - .addProperties(props.rawProperties()) - .addClasspath("./lib/common/*") - .addClasspath("./lib/server/*"); - String driverPath = props.value(JdbcSettings.PROPERTY_DRIVER_PATH); - if (driverPath != null) { - server.addClasspath(driverPath); - } - if (server.execute()) { - monitor.monitor(server); - if (server.waitForReady()) { - success = true; - logger.info("web server is up"); - } - } - } else { - success = true; - } - } + .addClasspath("./lib/server/*"); + String driverPath = props.value(JdbcSettings.PROPERTY_DRIVER_PATH); + if (driverPath != null) { + webServer.addClasspath(driverPath); } - } finally { - monitor.join(); - terminate(); + commands.add(webServer); } + return commands; } - static String starPath(File homeDir, String relativePath) { - File dir = new File(homeDir, relativePath); - return FilenameUtils.concat(dir.getAbsolutePath(), "*"); + @Override + public void terminate() { + monitor.stop(); } @Override public boolean isReady() { - return monitor.isAlive(); + return monitor.getState() == State.STARTED; } @Override - public long ping() { - return System.currentTimeMillis(); - } + public void ping() { - @Override - public void terminate() { - if (monitor != null && monitor.isAlive()) { - monitor.terminate(); - monitor = null; - } - if (server != null) { - server.terminate(); - server = null; - } - if (elasticsearch != null) { - elasticsearch.terminate(); - elasticsearch = null; - } } - private boolean isSuccess() { - return success; + static String starPath(File homeDir, String relativePath) { + File dir = new File(homeDir, relativePath); + return FilenameUtils.concat(dir.getAbsolutePath(), "*"); } - public static void main(String[] args) { + public static void main(String[] args) throws Exception { new MinimumViableSystem().check(); CommandLineParser cli = new CommandLineParser(); Properties rawProperties = cli.parseArguments(args); - Props props; - - try { - props = new PropsBuilder(rawProperties, new JdbcSettings()).build(); - new ProcessLogging().configure(props, "/org/sonar/application/logback.xml"); - } catch (Exception e) { - throw new IllegalStateException(e); - } + Props props = new PropsBuilder(rawProperties, new JdbcSettings()).build(); + new ProcessLogging().configure(props, "/org/sonar/application/logback.xml"); App app = new App(); - ProcessUtils.addSelfShutdownHook(app); - try { - // start and wait for shutdown command - if (props.contains(SearchServer.ES_CLUSTER_INET)) { - LoggerFactory.getLogger(App.class).info("SonarQube slave configured to join SonarQube master : {}", props.value(SearchServer.ES_CLUSTER_INET)); - } - app.start(props); - } catch (InterruptedException e) { - LoggerFactory.getLogger(App.class).info("interrupted"); - } finally { - LoggerFactory.getLogger(App.class).info("stopped"); - System.exit(app.isSuccess() ? 0 : 1); - } + app.start(props); } } |