Bug#966338: tomcat9: overrriding JAVA_HOME in /e/d/tomcat9 has changed
Vincent McIntyre
vmcintyr at atnf.csiro.au
Mon Jul 27 07:23:23 BST 2020
Package: tomcat9
Version: 9.0.31-1~deb10u2
Severity: normal
Tags: patch
I'm reporting a change in behaviour from tomcat8 and I'm not sure what the
correct fix is. While I'm reporting against the buster version, the issue
still seems to exist in current git (1ac6d044 Update changelog).
The gist is trying to override JAVA_HOME in the /etc/defaults/tomcat9 file
now _requires_ an export statement. This was not the case for tomcat8.
Gory details:
I found this on a machine upgraded from stretch to buster.
The old java version was the default and tomcat8 was still running:
% update-alternatives --display java
java - manual mode
link best version is /usr/lib/jvm/java-11-openjdk-amd64/bin/java
link currently points to /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
link java is /usr/bin/java
slave java.1.gz is /usr/share/man/man1/java.1.gz
/usr/lib/jvm/java-11-openjdk-amd64/bin/java - priority 1111
slave java.1.gz: /usr/lib/jvm/java-11-openjdk-amd64/man/man1/java.1.gz
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java - priority 1069
slave java.1.gz: /usr/lib/jvm/java-8-openjdk-amd64/jre/man/man1/java.1.gz
When I tried to start tomcat9 under java 11,
I did made the usual change in /etc/default/tomcat9
#JAVA_HOME=/usr/lib/jvm/java-8-openjdk
+JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
But when tomcat9 starts, it reports it is running under java 8
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name: Apache Tomcat/9.0.31 (Debian)
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built: Jul 15 2020 11:43:33 UTC
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 9.0.31.0
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name: Linux
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version: 4.19.0-9-amd64
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture: amd64
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home: /usr/lib/jvm/java-8-openjdk-amd64/jre
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version: 1.8.0_252-8u252-b09-1~deb9u1-b09
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor: Oracle Corporation
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE: /var/lib/tomcat9
INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME: /usr/share/tomcat9
This seems to be because there is no export of JAVA_HOME when it is overridden,
i.e. this configuration in /etc/default/tomcat9 works correctly:
#JAVA_HOME=/usr/lib/jvm/java-8-openjdk
+JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
+export JAVA_HOME
The 'export' was not necessary in tomcat8 because the init script takes
care of it
81 # Look for the right JVM to use
82 for jdir in $JDK_DIRS; do
83 if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
84 JAVA_HOME="$jdir"
85 fi
86 done
87 export JAVA_HOME
Where the startup sequence loses track of a JAVA_HOME override is when
/usr/libexec/tomcat9/tomcat-start.sh
execs into
"/usr/share/tomcat9/bin/catalina.sh run"
and that script sources
/usr/share/tomcat9/bin/setclasspath.sh
In that script this test fails and JAVA_HOME is set to /usr
24 # Make sure prerequisite environment variables are set
25 if [ -z "$JAVA_HOME" ] && [ -z "$JRE_HOME" ]; then
26 if $darwin; then
...
34 else
35 JAVA_PATH=`which java 2>/dev/null`
36 if [ "x$JAVA_PATH" != "x" ]; then
37 JAVA_PATH=`dirname "$JAVA_PATH" 2>/dev/null`
38 JRE_HOME=`dirname "$JAVA_PATH" 2>/dev/null`
39 fi
The squence of events leading up to this is
systemd calls
/usr/libexec/tomcat9/tomcat-start.sh
which sources
/etc/default/tomcat9
and then sources
/usr/libexec/tomcat9/tomcat-locate-java.sh
This script does the same job as the init script code above,
but the important difference is that it only exports JAVA_HOME
if it updates it; if JAVA_HOME is already set then the script
does not export it.
Before, that hunk of code exported JAVA_HOME unconditionally.
Then we exec into catalina.sh and the not-exported JAVA_HOME override is lost.
Possible fixes:
* tweak the example override in /etc/default/tomcat9
- #JAVA_HOME=/usr/lib/jvm/java-8-openjdk
+ #JAVA_HOME=/usr/lib/jvm/java-8-openjdk; export JAVA_HOME
* unconditionally export JAVA_HOME
--- tomcat-locate-java.sh 2020-07-27 16:13:45.903064630 +1000
+++ tomcat-locate-java.sh.new 2020-07-27 16:14:09.283692229 +1000
@@ -40,10 +40,11 @@
JAVA_HOME="$jdir"
fi
done
- export JAVA_HOME
fi
if [ -z "$JAVA_HOME" ]; then
echo "<2>No JDK or JRE found - Please set the JAVA_HOME variable or install the default-jdk package"
exit 1
fi
+
+export JAVA_HOME
Kind regards
Vince
-- System Information:
Debian Release: 10.4
APT prefers stable
APT policy: (990, 'stable'), (500, 'stable-debug')
Architecture: amd64 (x86_64)
Kernel: Linux 4.19.0-9-amd64 (SMP w/28 CPU cores)
Kernel taint flags: TAINT_OOT_MODULE, TAINT_UNSIGNED_MODULE
Locale: LANG=en_AU.UTF-8, LC_CTYPE=en_AU.UTF-8 (charmap=UTF-8), LANGUAGE=en_AU:en (charmap=UTF-8)
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages tomcat9 depends on:
ii lsb-base 10.2019051400
ii systemd 241-7~deb10u4
ii tomcat9-common 9.0.31-1~deb10u2
ii ucf 3.0038+nmu1
Versions of packages tomcat9 recommends:
pn libtcnative-1 <none>
Versions of packages tomcat9 suggests:
pn tomcat9-admin <none>
pn tomcat9-docs <none>
pn tomcat9-examples <none>
pn tomcat9-user <none>
-- no debconf information
More information about the pkg-java-maintainers
mailing list