aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephane Gamard <stephane.gamard@searchbox.com>2014-07-21 10:09:06 +0200
committerStephane Gamard <stephane.gamard@searchbox.com>2014-07-21 10:15:52 +0200
commit881746f43a06fcfa043f94717d07c6288d9f9349 (patch)
tree02dd31999425ed98f964755a7d0c8645618cc725
parentdcad5e5686825dc8b37c343292be7a77bf03e16b (diff)
downloadsonarqube-881746f43a06fcfa043f94717d07c6288d9f9349.tar.gz
sonarqube-881746f43a06fcfa043f94717d07c6288d9f9349.zip
SONAR-5410 - Using relative path to SONAR_HOME for configuraiton
-rw-r--r--server/sonar-process/src/main/java/org/sonar/process/Process.java41
-rw-r--r--sonar-start/src/main/java/org/sonar/start/Env.java4
-rw-r--r--sonar-start/src/main/java/org/sonar/start/StartServer.java4
3 files changed, 20 insertions, 29 deletions
diff --git a/server/sonar-process/src/main/java/org/sonar/process/Process.java b/server/sonar-process/src/main/java/org/sonar/process/Process.java
index c511bf7f127..f97aef7b77a 100644
--- a/server/sonar-process/src/main/java/org/sonar/process/Process.java
+++ b/server/sonar-process/src/main/java/org/sonar/process/Process.java
@@ -63,6 +63,7 @@ public abstract class Process implements ProcessMXBean {
protected final Props props;
private Thread shutdownHook;
+ private volatile boolean JVM_SHUTDOWN = false;
private static final long MAX_ALLOWED_TIME = 3000L;
private ScheduledFuture<?> pingTask = null;
@@ -73,8 +74,7 @@ public abstract class Process implements ProcessMXBean {
LOGGER.debug("last check-in was {}ms ago.", time - lastPing);
if (time - lastPing > MAX_ALLOWED_TIME) {
LOGGER.warn("Did not get a check-in since {}ms. Initiate shutdown", time - lastPing);
- Runtime.getRuntime().removeShutdownHook(shutdownHook);
- shutdown();
+ terminate();
}
}
};
@@ -133,7 +133,14 @@ public abstract class Process implements ProcessMXBean {
shutdownHook = new Thread(new Runnable() {
@Override
public void run() {
- Process.this.shutdown();
+ LOGGER.trace("Process[{}]::ShutdownHook::run() START", name);
+ Process.this.JVM_SHUTDOWN = true;
+ Process.this.onTerminate();
+ if (Process.this.pingTask != null) {
+ Process.this.pingTask.cancel(true);
+ }
+ Process.this.monitor.shutdownNow();
+ LOGGER.trace("Process[{}]::ShutdownHook::run() END", name);
}
});
Runtime.getRuntime().addShutdownHook(shutdownHook);
@@ -171,39 +178,23 @@ public abstract class Process implements ProcessMXBean {
}
public final void terminate(boolean waitForTermination) {
- LOGGER.trace("Process[{}]::stop() START", name);
+ LOGGER.trace("Process[{}]::terminate() START", name);
Runtime.getRuntime().removeShutdownHook(shutdownHook);
- Thread terminating = new Thread(new Runnable() {
- @Override
- public void run() {
- shutdown();
- }
- });
- terminating.start();
+ shutdownHook.start();
if (waitForTermination) {
try {
- terminating.join();
+ shutdownHook.join();
} catch (InterruptedException e) {
- throw new IllegalStateException("Could not terminate process", e);
+ e.printStackTrace();
}
}
- LOGGER.trace("Process[{}]::stop() END", name);
+ LOGGER.trace("Process[{}]::terminate() END", name);
}
public final void terminate() {
terminate(false);
}
- private void shutdown(){
- LOGGER.trace("Process[{}]::shutdown() START", name);
- this.onTerminate();
- if (pingTask != null) {
- pingTask.cancel(true);
- }
- monitor.shutdownNow();
- LOGGER.trace("Process[{}]::shutdown() END", name);
- }
-
private void validateSonarHome(Props props) {
// check that we have a SONAR_HOME either in props or in env.
@@ -214,7 +205,7 @@ public abstract class Process implements ProcessMXBean {
// check that SONAR_HOME exists
File home = new File(sonarHome);
- if(!home.exists()) {
+ if (!home.exists()) {
throw new IllegalStateException(SONAR_HOME_DOES_NOT_EXIST);
}
diff --git a/sonar-start/src/main/java/org/sonar/start/Env.java b/sonar-start/src/main/java/org/sonar/start/Env.java
index af00390d98c..cd27752101a 100644
--- a/sonar-start/src/main/java/org/sonar/start/Env.java
+++ b/sonar-start/src/main/java/org/sonar/start/Env.java
@@ -27,14 +27,14 @@ import java.net.URISyntaxException;
class Env {
- private static final String CONF_DIRECTORY = "/conf";
+ private static final String CONF_DIRECTORY = "conf";
private final File confFile;
private final File homeDir;
public Env(String homeDir) throws URISyntaxException {
this.homeDir = new File(homeDir);
- this.confFile = new File(CONF_DIRECTORY+"/sonar.properties");
+ this.confFile = new File(homeDir, CONF_DIRECTORY + "/sonar.properties");
}
public File getConfFile() {
diff --git a/sonar-start/src/main/java/org/sonar/start/StartServer.java b/sonar-start/src/main/java/org/sonar/start/StartServer.java
index bbd99d32374..ff46c78eec1 100644
--- a/sonar-start/src/main/java/org/sonar/start/StartServer.java
+++ b/sonar-start/src/main/java/org/sonar/start/StartServer.java
@@ -160,8 +160,8 @@ public final class StartServer {
public static void main(String... args) throws InterruptedException, IOException, URISyntaxException {
- String home = System.getenv(SONAR_HOME);
- //String home = "/Volumes/data/sonar/sonarqube/sonar-start/target/sonarqube-4.5-SNAPSHOT";
+ //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)) {