Skip to content

Commit

Permalink
refactor assigment of JAVA_HOME in init script
Browse files Browse the repository at this point in the history
Path by eevans; review by Brandon Williams for CASSANDRA-1407

git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@986939 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Eric Evans committed Aug 18, 2010
1 parent 9c278ff commit 4a7c7e1
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions debian/init
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,42 @@ JVM_MAX_MEM="1G"
JVM_START_MEM="128M"
JMX_PORT="8080"

# The first existing directory is used for JAVA_HOME
JDK_DIRS="/usr/lib/jvm/java-6-sun /usr/lib/jvm/java-6-openjdk"

# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done

# The first existing directory is used for JAVA_HOME if needed.
JVM_SEARCH_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun"

[ -e /usr/share/cassandra/apache-cassandra.jar ] || exit 0
[ -e /etc/cassandra/cassandra.yaml ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# If JAVA_HOME has not been set, try to determine it.
if [ -z "$JAVA_HOME" ]; then
# If java is in PATH, use a JAVA_HOME that corresponds to that. This is
# both consistent with how the upstream startup script works, and how
# Debian works (read: the use of alternatives to set a system JVM).
if [ -n `which java` ]; then
java=`which java`
# Dereference symlink(s)
while true; do
if [ -h "$java" ]; then
java=`readlink "$java"`
continue
fi
break
done
JAVA_HOME="`dirname $java`/../"
# No JAVA_HOME set and no java found in PATH, search for a JVM.
else
for jdir in $JVM_SEARCH_DIRS; do
if [ -x "$jdir/bin/java" ]; then
JAVA_HOME="$jdir"
break
fi
done
fi
fi

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

Expand Down

0 comments on commit 4a7c7e1

Please sign in to comment.