]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-12786 Improve startup error message when the TCP port is already taken
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 14 Dec 2020 22:15:20 +0000 (16:15 -0600)
committersonartech <sonartech@sonarsource.com>
Tue, 5 Jan 2021 20:15:14 +0000 (20:15 +0000)
server/sonar-webserver/src/main/java/org/sonar/server/app/EmbeddedTomcat.java

index d0b0d4f74d0af623551364df9c0ede697bfa608c..e7bdc1d237f4887f199117cec57928cce98b2d8e 100644 (file)
  */
 package org.sonar.server.app;
 
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
 import com.google.common.base.Throwables;
 import java.io.File;
 import java.util.concurrent.CountDownLatch;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
+import org.slf4j.LoggerFactory;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.process.Props;
 
@@ -63,7 +66,11 @@ class EmbeddedTomcat {
     TomcatConnectors.configure(tomcat, props);
     webappContext = new TomcatContexts().configure(tomcat, props);
     try {
+      // let Tomcat temporarily log errors at start up - for example, port in use
+      Logger logger = (Logger) LoggerFactory.getLogger("org.apache.catalina.core.StandardService");
+      logger.setLevel(Level.ERROR);
       tomcat.start();
+      logger.setLevel(Level.OFF);
       new TomcatStartupLogs(Loggers.get(getClass())).log(tomcat);
     } catch (LifecycleException e) {
       Loggers.get(EmbeddedTomcat.class).error("Fail to start web server", e);