From bfe5863aae84dc467e19fc58ed494422c5bb6e13 Mon Sep 17 00:00:00 2001 From: Stephane Gamard Date: Mon, 25 Aug 2014 14:35:35 +0200 Subject: [PATCH] SONAR-5483 - Fails to start if no master available in cluster (mainly do to wrong coordinates in properties) --- fork.sh | 4 ++-- .../src/main/java/org/sonar/process/MonitoredProcess.java | 7 ++++++- .../src/main/java/org/sonar/search/SearchServer.java | 8 +++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/fork.sh b/fork.sh index 1b904826697..7e8e17f02c3 100755 --- a/fork.sh +++ b/fork.sh @@ -1,6 +1,6 @@ #!/bin/sh -mvn clean install -DskipTests -pl :sonar-server,:sonar-search -amd +mvn clean install -DskipTests -pl :sonar-server,:sonar-search,:sonar-process -amd if [[ "$OSTYPE" == "darwin"* ]]; then OS='macosx-universal-64' @@ -18,7 +18,7 @@ touch logs/application.log touch logs/search.log touch logs/sonar.log -tmux new-session "tmux split-window -v 'tail -f logs/sonar.log'; tmux split-window -h 'tail -f logs/search.log'; java -jar lib/sonar-application*.jar -Dsonar.node.name=forky" +tmux new-session "tmux split-window -v 'tail -f logs/sonar.log'; tmux split-window -h 'tail -f logs/search.log'; java -jar lib/sonar-application*.jar -Dsonar.node.name=forky -Dsonar.cluster.master=10.0.1.1:2222" #tmux new-session "tmux split-window -h 'tail -f logs/search.log'; java -jar lib/sonar-application*.jar" #tmux new-session "tmux split-window -v 'tail -f logs/sonar.log'; tmux split-window -h 'tail -f logs/search.log'; tail -f logs/application.log" diff --git a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java index 3491bd31a0c..23cb5dfe3a0 100644 --- a/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java +++ b/server/process/sonar-process/src/main/java/org/sonar/process/MonitoredProcess.java @@ -91,7 +91,12 @@ public abstract class MonitoredProcess implements ProcessMXBean { } LOGGER.debug("Process[{}] starting", name); scheduleAutokill(this.isMonitored); - doStart(); + try { + doStart(); + } catch (Exception e) { + LOGGER.error("Could not start process: {}", e); + this.terminate(); + } LOGGER.debug("Process[{}] started", name); } diff --git a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java index 9995ba789d0..fd65e302837 100644 --- a/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java +++ b/server/sonar-search/src/main/java/org/sonar/search/SearchServer.java @@ -119,12 +119,14 @@ public class SearchServer extends MonitoredProcess { .put("path.logs", esLogDir().getAbsolutePath()); if (!nodes.isEmpty()) { + LoggerFactory.getLogger(SearchServer.class).info("Joining ES cluster with masters: {}", nodes); esSettings.put("discovery.zen.ping.unicast.hosts", StringUtils.join(nodes, ",")); - + esSettings.put("node.master", false); // Enforce a N/2+1 number of masters in cluster - esSettings.put("discovery.zen.minimum_master_nodes", - (int) Math.floor(nodes.size() / 2.0) + 1); + esSettings.put("discovery.zen.minimum_master_nodes", 1); + // Change master pool requirement when in distributed mode + // esSettings.put("discovery.zen.minimum_master_nodes", (int) Math.floor(nodes.size() / 2.0) + 1); } // Set cluster coordinates -- 2.39.5