You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by jo...@apache.org on 2019/12/13 05:36:14 UTC
[incubator-druid] branch master updated: Allow startup scripts to
specify java home (#9021)
This is an automated email from the ASF dual-hosted git repository.
jonwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-druid.git
The following commit(s) were added to refs/heads/master by this push:
new 3325da1 Allow startup scripts to specify java home (#9021)
3325da1 is described below
commit 3325da17189ae308350b83f7faf165925ccb6f94
Author: Suneet Saldanha <44...@users.noreply.github.com>
AuthorDate: Thu Dec 12 21:36:00 2019 -0800
Allow startup scripts to specify java home (#9021)
* Allow startup scripts to specify java home
The startup scripts now look for java in 3 locations. The order is from
most related to druid to least, ie
${DRUID_JAVA_HOME}
${JAVA_HOME}
${PATH}
* Update fn names and clean up code
* final round of fixes
* fix spellcheck
---
docs/tutorials/cluster.md | 2 ++
docs/tutorials/index.md | 2 ++
examples/bin/java-util | 40 ++++++++++++++++++++++++++++++++++++++++
examples/bin/jconsole.sh | 9 ++++++++-
examples/bin/node.sh | 10 +++++++---
examples/bin/run-druid | 12 ++++++++----
examples/bin/run-zk | 9 +++++++--
examples/bin/verify-java | 17 ++++++++++++++++-
8 files changed, 90 insertions(+), 11 deletions(-)
diff --git a/docs/tutorials/cluster.md b/docs/tutorials/cluster.md
index 46a165e..b795227 100644
--- a/docs/tutorials/cluster.md
+++ b/docs/tutorials/cluster.md
@@ -135,6 +135,8 @@ We recommend running your favorite Linux distribution. You will also need:
* **Java 8**
> **Warning:** Java 8 is required to run Druid. While Druid will start with a higher version of Java it will not function correctly.
+>
+> If needed, you can specify where to find Java using the environment variables `DRUID_JAVA_HOME` or `JAVA_HOME`. For more details run the verify-java script.
Your OS package manager should be able to help for both Java. If your Ubuntu-based OS
does not have a recent enough version of Java, WebUpd8 offers [packages for those
diff --git a/docs/tutorials/index.md b/docs/tutorials/index.md
index ffd510d..3d12fcc 100644
--- a/docs/tutorials/index.md
+++ b/docs/tutorials/index.md
@@ -39,6 +39,8 @@ You will need:
* Linux, Mac OS X, or other Unix-like OS (Windows is not supported)
> **Warning:** Java 8 is required to run Druid. While Druid will start with a higher version of Java it will not function correctly.
+>
+> If needed, you can specify where to find Java using the environment variables `DRUID_JAVA_HOME` or `JAVA_HOME`. For more details run the verify-java script.
### Hardware
diff --git a/examples/bin/java-util b/examples/bin/java-util
new file mode 100755
index 0000000..84c8bd2
--- /dev/null
+++ b/examples/bin/java-util
@@ -0,0 +1,40 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+#######################################
+# A utility script to search for java. The order in which we look for java
+# goes from most specific to least specific, i.e.
+# ${DRUID_JAVA_HOME}
+# ${JAVA_HOME}
+# ${PATH}
+# Arguments:
+# None
+# Returns:
+# The bin folder of java if it exists, otherwise an empty string
+#######################################
+get_java_bin_dir() {
+ if [ ! -z "${DRUID_JAVA_HOME-}" ]; then
+ printf "$DRUID_JAVA_HOME/bin"
+ elif [ ! -z "${JAVA_HOME-}" ]; then
+ printf "$JAVA_HOME/bin"
+ elif [ ! -z "$(command -v java)" ]; then
+ # Strip /java from the location of where java is installed
+ JAVA_ON_PATH="$(command -v java)"
+ echo -n "${JAVA_ON_PATH%/java}"
+ else
+ printf ""
+ fi
+}
diff --git a/examples/bin/jconsole.sh b/examples/bin/jconsole.sh
index 4c71368..f3420ad 100755
--- a/examples/bin/jconsole.sh
+++ b/examples/bin/jconsole.sh
@@ -43,4 +43,11 @@ if [ ! -e ${LOG4J_GUI_PATH} ]; then
fi
wait
-jconsole -pluginpath ${LOG4J_API_PATH}:${LOG4J_CORE_PATH}:${LOG4J_GUI_PATH} $@
+WHEREAMI="$(dirname "$0")"
+WHEREAMI="$(cd "$WHEREAMI" && pwd)"
+JAVA_BIN_DIR="$(source "$WHEREAMI"/java-util && get_java_bin_dir)"
+if [ -z "$JAVA_BIN_DIR" ]; then
+ >&2 echo "Could not find java - please run $WHEREAMI/verify-java to confirm it is installed."
+ exit 1
+fi
+"$JAVA_BIN_DIR"/jconsole -pluginpath ${LOG4J_API_PATH}:${LOG4J_CORE_PATH}:${LOG4J_GUI_PATH} $@
diff --git a/examples/bin/node.sh b/examples/bin/node.sh
index 5ad9748..991375e 100644
--- a/examples/bin/node.sh
+++ b/examples/bin/node.sh
@@ -39,6 +39,9 @@ LIB_DIR="${DRUID_LIB_DIR:=lib}"
CONF_DIR="${DRUID_CONF_DIR:=conf/druid}"
LOG_DIR="${DRUID_LOG_DIR:=log}"
PID_DIR="${DRUID_PID_DIR:=var/druid/pids}"
+WHEREAMI="$(dirname "$0")"
+WHEREAMI="$(cd "$WHEREAMI" && pwd)"
+JAVA_BIN_DIR="$(source "$WHEREAMI"/java-util && get_java_bin_dir)"
pid=$PID_DIR/$nodeType.pid
@@ -55,10 +58,11 @@ case $command in
if [ ! -d "$PID_DIR" ]; then mkdir -p $PID_DIR; fi
if [ ! -d "$LOG_DIR" ]; then mkdir -p $LOG_DIR; fi
- JAVA=java
- if [ "$JAVA_HOME" != "" ]; then
- JAVA=$JAVA_HOME/bin/java
+ if [ -z "$JAVA_BIN_DIR" ]; then
+ echo "Could not find java - please run $WHEREAMI/verify-java to confirm it is installed."
+ exit 1
fi
+ JAVA="$JAVA_BIN_DIR/java"
nohup $JAVA `cat $CONF_DIR/$nodeType/jvm.config | xargs` -cp $CONF_DIR/_common:$CONF_DIR/$nodeType:$LIB_DIR/*:$HADOOP_CONF_DIR org.apache.druid.cli.Main server $nodeType >> $LOG_DIR/$nodeType.log 2>&1 &
nodeType_PID=$!
diff --git a/examples/bin/run-druid b/examples/bin/run-druid
index 4db0a2f..003824e 100755
--- a/examples/bin/run-druid
+++ b/examples/bin/run-druid
@@ -17,9 +17,9 @@
# specific language governing permissions and limitations
# under the License.
-if [ "$#" -gt 2 ]
+if [ "$#" -gt 2 ] || [ "$#" -eq 0 ]
then
- echo "usage: $0 <service> [conf-dir]" >&2
+ >&2 echo "usage: $0 <service> [conf-dir]"
exit 1
fi
@@ -36,8 +36,12 @@ fi
CONFDIR="$(cd "$CONFDIR" && pwd)"
WHEREAMI="$(cd "$WHEREAMI" && pwd)"
-
+JAVA_BIN="$(source "$WHEREAMI"/java-util && get_java_bin_dir)"
+if [ -z "$JAVA_BIN" ]; then
+ >&2 echo "Could not find java - please run $WHEREAMI/verify-java to confirm it is installed."
+ exit 1
+fi
cd "$WHEREAMI/.."
-exec java `cat "$CONFDIR"/"$WHATAMI"/jvm.config | xargs` \
+exec "$JAVA_BIN"/java `cat "$CONFDIR"/"$WHATAMI"/jvm.config | xargs` \
-cp "$CONFDIR"/"$WHATAMI":"$CONFDIR"/_common:"$CONFDIR"/_common/hadoop-xml:"$CONFDIR"/../_common:"$CONFDIR"/../_common/hadoop-xml:"$WHEREAMI/../lib/*" \
`cat "$CONFDIR"/$WHATAMI/main.config | xargs`
diff --git a/examples/bin/run-zk b/examples/bin/run-zk
index c6345d9..4fd30f6 100755
--- a/examples/bin/run-zk
+++ b/examples/bin/run-zk
@@ -19,7 +19,7 @@
if [ "$#" -gt 1 ]
then
- echo "usage: $0 [conf-dir]" >&2
+ >&2 echo "usage: $0 [conf-dir]"
exit 1
fi
@@ -35,9 +35,14 @@ fi
CONFDIR="$(cd "$CONFDIR" && pwd)/zk"
WHEREAMI="$(cd "$WHEREAMI" && pwd)"
+JAVA_BIN="$(source "$WHEREAMI"/java-util && get_java_bin_dir)"
+if [ -z "$JAVA_BIN" ]; then
+ >&2 echo "Could not find java - please run $WHEREAMI/verify-java to confirm it is installed."
+ exit 1
+fi
cd "$WHEREAMI/.."
-exec java `cat "$CONFDIR"/jvm.config | xargs` \
+exec "$JAVA_BIN"/java `cat "$CONFDIR"/jvm.config | xargs` \
-cp "$WHEREAMI/../lib/*:$CONFDIR" \
-Dzookeeper.jmx.log4j.disable=true \
org.apache.zookeeper.server.quorum.QuorumPeerMain \
diff --git a/examples/bin/verify-java b/examples/bin/verify-java
index e0ead88..c8dcd19 100755
--- a/examples/bin/verify-java
+++ b/examples/bin/verify-java
@@ -19,6 +19,7 @@
use strict;
use warnings;
+use File::Basename;
sub fail_check {
my ($current_version) = @_;
@@ -35,6 +36,12 @@ environment variable:
export DRUID_SKIP_JAVA_CHECK=1
Otherwise, install Java 8 and try again.
+
+This script searches for Java 8 in 3 locations in the following
+order
+ * DRUID_JAVA_HOME
+ * JAVA_HOME
+ * java (installed on PATH)
EOT
exit 1;
}
@@ -44,7 +51,15 @@ if ($skip_var && $skip_var ne "0" && $skip_var ne "false" && $skip_var ne "f") {
exit 0;
}
-my $java_version = qx[java -version 2>&1];
+my $cwd = dirname(__FILE__);
+my $java_bin_dir = `source $cwd/java-util && get_java_bin_dir 2>&1`;
+
+# If we could not find java
+if ($java_bin_dir eq "") {
+ fail_check()
+}
+my $java_exec = "${java_bin_dir}/java";
+my $java_version = qx[$java_exec -version 2>&1];
if ($?) {
fail_check();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org