On RHEL/Centos/Fedora, when java is installed from the RPMs neither JAVA_HOME nor JRE_HOME environment variables are set. Luckily, the Tomcat startup scripts are able to auto-detect them but the daemon.sh script cannot properly do so. The failure is in the JAVA_HOME auto-detection in the script here: daemon.sh:96: ~~~ JAVA_BIN="`which java 2>/dev/null || type java 2>&1`" test -x "$JAVA_BIN" && JAVA_HOME="`dirname $JAVA_BIN`" test ".$JAVA_HOME" != . && JAVA_HOME=`cd "$JAVA_HOME/.." >/dev/null; pwd` ~~~ The problem is that when java is installed from the RPMs, `which java` evaluates to '/usr/bin/java', which is a symlink maintained by alternatives. The code snippet above will evaluate to JAVA_HOME and JRE_HOME being set to '/usr'. Having JRE_HOME set to '/usr' doesn't seem to cause problems for Tomcat, but the problem manifests itself when running the daemon.sh script: ~~~ # ./daemon.sh start Cannot find any VM in Java Home /usr ~~~ jsvc is only used in daemon.sh, therefore this problem was not seen when starting Tomcat using startup.sh or catalina.sh. I think a good fallback for JAVA_HOME and JRE_HOME is '/usr/lib/jvm/java' and '/usr/lib/jvm/jre' respectively. To Reproduce: 1. Install tomcat 2. Install java from RPMs 3. cd $CATALINA_HOME 4. bin/daemon.sh start 5. Observe error mentioned above
Created attachment 35246 [details] Option to add fallbacks This patch would just add a check for JAVA_HOME being /usr and if it is, use the correct directories for the JDK or JRE installation.
Created attachment 35247 [details] Another seemingly viable option Another option is to remove the -java-home option from the JSVC command lines. Doing so resolves the issue for me because JSVC seems to be able to figure out what to do on it's own.
What about the following addition, copied and adjusted from the top of the file where it is used to resolve another possible symlink: Index: bin/daemon.sh =================================================================== --- bin/daemon.sh (revision 1805340) +++ bin/daemon.sh (working copy) @@ -94,6 +94,15 @@ # if [ -z "$JAVA_HOME" ]; then JAVA_BIN="`which java 2>/dev/null || type java 2>&1`" + while [ -h "$JAVA_BIN" ]; do + ls=`ls -ld "$JAVA_BIN"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + JAVA_BIN="$link" + else + JAVA_BIN="`dirname $JAVA_BIN`/$link" + fi + done test -x "$JAVA_BIN" && JAVA_HOME="`dirname $JAVA_BIN`" test ".$JAVA_HOME" != . && JAVA_HOME=`cd "$JAVA_HOME/.." >/dev/null; pwd` else Does that work?
Yeah, that works. I think I like that approach best also because it eliminates guessing.
Fixed in: - trunk for 9.0.0.M27 onwards - 8.5.x for 8.5.21 onwards - 8.0.x for 8.0.47 onwards - 7.0.x for 7.0.82 onwards