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
This commit is contained in:
Suneet Saldanha 2019-12-12 21:36:00 -08:00 committed by Jonathan Wei
parent 41f30e53a6
commit 3325da1718
8 changed files with 90 additions and 11 deletions

View File

@ -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

View File

@ -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

40
examples/bin/java-util Executable file
View File

@ -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
}

View File

@ -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} $@

View File

@ -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=$!

View File

@ -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`

View File

@ -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 \

View File

@ -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();
}