You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by ee...@apache.org on 2010/08/18 23:09:55 UTC

svn commit: r986939 - /cassandra/trunk/debian/init

Author: eevans
Date: Wed Aug 18 21:09:55 2010
New Revision: 986939

URL: http://svn.apache.org/viewvc?rev=986939&view=rev
Log:
refactor assigment of JAVA_HOME in init script

Path by eevans; review by Brandon Williams for CASSANDRA-1407

Modified:
    cassandra/trunk/debian/init

Modified: cassandra/trunk/debian/init
URL: http://svn.apache.org/viewvc/cassandra/trunk/debian/init?rev=986939&r1=986938&r2=986939&view=diff
==============================================================================
--- cassandra/trunk/debian/init (original)
+++ cassandra/trunk/debian/init Wed Aug 18 21:09:55 2010
@@ -22,16 +22,8 @@ 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
@@ -39,6 +31,33 @@ done
 # 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