public abstract class MonitoredProcess implements ProcessMXBean {
+ private final static Logger LOGGER = LoggerFactory.getLogger(MonitoredProcess.class);
+
public static final String NAME_PROPERTY = "pName";
private static final long AUTOKILL_TIMEOUT_MS = 30000L;
private static final long AUTOKILL_CHECK_DELAY_MS = 2000L;
private ScheduledExecutorService monitor;
private final boolean isMonitored;
- protected MonitoredProcess(Props props) throws Exception {
+ protected MonitoredProcess(Props props) {
this(props, false);
}
- protected MonitoredProcess(Props props, boolean monitor) throws Exception {
+ protected MonitoredProcess(Props props, boolean monitor) {
this.isMonitored = monitor;
this.props = props;
this.name = props.of(NAME_PROPERTY);
if (monitor != null) {
throw new IllegalStateException("Already started");
}
-
- Logger logger = LoggerFactory.getLogger(getClass());
- logger.debug("Process[{}] starting", name);
+ LOGGER.debug("Process[{}] starting", name);
scheduleAutokill(this.isMonitored);
doStart();
- logger.debug("Process[{}] started", name);
+ LOGGER.debug("Process[{}] started", name);
}
/**
@Override
public final void terminate() {
if (monitor != null) {
- Logger logger = LoggerFactory.getLogger(getClass());
- logger.debug("Process[{}] terminating", name);
+ LOGGER.debug("Process[{}] terminating", name);
monitor.shutdownNow();
monitor = null;
if (pingTask != null) {
try {
doTerminate();
} catch (Exception e) {
- LoggerFactory.getLogger(getClass()).error("Fail to terminate " + name, e);
+ LOGGER.error("Fail to terminate " + name, e);
// do not propagate exception
}
- logger.debug("Process[{}] terminated", name);
+ LOGGER.debug("Process[{}] terminated", name);
terminated = true;
}
}
private Node node;
- public SearchServer(Props props, boolean monitored, boolean blocking) throws Exception {
+ public SearchServer(final Props props, boolean monitored, boolean blocking) {
super(props, monitored);
+
this.isBlocking = blocking;
new MinimumViableSystem().check();
- if (StringUtils.isNotEmpty(props.of(ES_CLUSTER_INET, null))) {
- Collections.addAll(nodes, props.of(ES_CLUSTER_INET).split(","));
+ String ESNodesInets = props.of(ES_CLUSTER_INET);
+ if (StringUtils.isNotEmpty(ESNodesInets)) {
+ Collections.addAll(nodes, ESNodesInets.split(","));
}
}
import org.sonar.process.Props;
import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.Properties;
/**
private ProcessWrapper server;
private boolean success = false;
- public App() throws Exception {
+ public App() {
JmxUtils.registerMBean(this, "SonarQube");
ProcessUtils.addSelfShutdownHook(this);
}
File homeDir = props.fileOf("sonar.path.home");
File tempDir = props.fileOf("sonar.path.temp");
- elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME)
+ elasticsearch = new ProcessWrapper(JmxUtils.SEARCH_SERVER_NAME);
+ elasticsearch
.setWorkDir(homeDir)
.setJmxPort(props.intOf(DefaultSettings.SEARCH_JMX_PORT))
.addJavaOpts(props.of(DefaultSettings.SEARCH_JAVA_OPTS))
.setJmxPort(props.intOf(DefaultSettings.WEB_JMX_PORT))
.addJavaOpts(props.of(DefaultSettings.WEB_JAVA_OPTS))
.setTempDirectory(tempDir.getAbsoluteFile())
- // required for logback tomcat valve
+ // required for logback tomcat valve
.setLogDir(props.fileOf("sonar.path.logs"))
.setClassName("org.sonar.server.app.WebServer")
.addProperties(props.rawProperties())
return success;
}
- public static void main(String[] args) throws Exception {
+ public static void main(String[] args) {
+
new MinimumViableSystem().check();
CommandLineParser cli = new CommandLineParser();
Properties rawProperties = cli.parseArguments(args);
- Props props = new PropsBuilder(rawProperties, new JdbcSettings()).build();
- new ProcessLogging().configure(props, "/org/sonar/application/logback.xml");
- App app = new App();
+ Props props = null;
- // start and wait for shutdown command
- app.start(props);
+ try {
+ props = new PropsBuilder(rawProperties, new JdbcSettings()).build();
+ new ProcessLogging().configure(props, "/org/sonar/application/logback.xml");
+ } catch (IOException e) {
+ throw new IllegalStateException(e.getMessage());
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException(e.getMessage());
+ }
- LoggerFactory.getLogger(App.class).info("stopped");
- System.exit(app.isSuccess() ? 0 : 1);
+ App app = new App();
+
+ try {
+ // start and wait for shutdown command
+ 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);
+ }
}
}
/**
* Build properties from command-line arguments and system properties
*/
- Properties parseArguments(String[] args) throws Exception {
+ Properties parseArguments(String[] args) {
Properties props = argumentsToProperties(args);
// complete with only the system properties that start with "sonar."
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.Properties;
class PropsBuilder {
this.homeDir = homeDir;
}
- PropsBuilder(Properties rawProperties, JdbcSettings jdbcSettings) throws Exception {
+ PropsBuilder(Properties rawProperties, JdbcSettings jdbcSettings) throws URISyntaxException {
this(rawProperties, jdbcSettings, detectHomeDir());
}
* Load optional conf/sonar.properties, interpolates environment variables and
* initializes file system
*/
- Props build() throws Exception {
+ Props build() throws IOException {
Properties p = loadPropertiesFile(homeDir);
p.putAll(rawProperties);
p.setProperty("sonar.path.home", homeDir.getAbsolutePath());
return props;
}
- static File detectHomeDir() throws Exception {
+ static File detectHomeDir() throws URISyntaxException {
File appJar = new File(PropsBuilder.class.getProtectionDomain().getCodeSource().getLocation().toURI());
return appJar.getParentFile().getParentFile();
}