Discussion:
Working dir incorrect tomcat 9.10?
Carl-Henrik Tjärnlund
2018-06-30 09:55:21 UTC
Permalink
Hi!
I'm in the process of upgrading from tomcat 8 to 9 and was running into a
probelm with velocity not beeing able to create the default log file,
./velocity.log and after some troubleshooting it seems it is trying to
create it in the root of the file system instead of the current working
directory, which i thought would be CATALINA_BASE.

I just did some test and logging in the webapp:

log.info("Working path: " + new File(".").getAbsolutePath());

would report "Working path: /.
And I could do a workaround by creating /velocity.log manually and give the
tomcat9 user ownership.

From the logs it seems that tomcat is picking up the correct settings, see
below, so I really cant get my head around it..

This has been workign without a problem from tomcat6 to tomcat8, is there
some configuration change I may have missed?

28-Jun-2018 08:42:28.896 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Server
version: Apache Tomcat/9.0.10
28-Jun-2018 08:42:28.897 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Server
built: Jun 20 2018 17:32:21 UTC
28-Jun-2018 08:42:28.898 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Server
number: 9.0.10.0
28-Jun-2018 08:42:28.899 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log OS
Name: Linux
28-Jun-2018 08:42:28.899 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log OS
Version: 4.15.0-23-generic
28-Jun-2018 08:42:28.900 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log
Architecture: amd64
28-Jun-2018 08:42:28.900 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Java
Home: /usr/lib/jvm/java-11-openjdk-amd64
28-Jun-2018 08:42:28.901 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log JVM
Version: 10.0.1+10-Ubuntu-3ubuntu1
28-Jun-2018 08:42:28.902 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log JVM
Vendor: Oracle Corporation
28-Jun-2018 08:42:28.902 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log
CATALINA_BASE: /ssd/opt/apache-tomcat-9.0.10
28-Jun-2018 08:42:28.903 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log
CATALINA_HOME: /ssd/opt/apache-tomcat-9.0.10
28-Jun-2018 08:42:28.904 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-opens=java.base/java.lang=ALL-UNNAMED
28-Jun-2018 08:42:28.905 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-opens=java.base/java.io=ALL-UNNAMED
28-Jun-2018 08:42:28.905 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
28-Jun-2018 08:42:28.906 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.util.logging.config.file=/opt/tomcat/conf/logging.pro
perties
28-Jun-2018 08:42:28.906 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogMa
nager
28-Jun-2018 08:42:28.907 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dfile.encoding=ISO-8859-1
28-Jun-2018 08:42:28.907 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dnet.sf.ehcache.skipUpdateCheck=true
28-Jun-2018 08:42:28.908 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -XX:+CMSClassUnloadingEnabled
28-Jun-2018 08:42:28.908 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djdk.tls.ephemeralDHKeySize=2048
28-Jun-2018 08:42:28.909 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresource
s
28-Jun-2018 08:42:28.909 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
28-Jun-2018 08:42:28.910 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Xms512m
28-Jun-2018 08:42:28.910 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Xmx1G
28-Jun-2018 08:42:28.912 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-modules=java.xml.bind
28-Jun-2018 08:42:28.913 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-modules=java.xml.ws
28-Jun-2018 08:42:28.914 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dignore.endorsed.dirs=
28-Jun-2018 08:42:28.915 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dcatalina.base=/opt/tomcat
28-Jun-2018 08:42:28.918 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dcatalina.home=/opt/tomcat
28-Jun-2018 08:42:28.919 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.io.tmpdir=/opt/tomcat/temp
Carl-Henrik Tjärnlund
2018-06-30 13:37:59 UTC
Permalink
Hi!
I'm in the process of upgrading from tomcat 8 to 9 and was running
into a probelm with velocity not beeing able to create the default log
file, ./velocity.log and after some troubleshooting it seems it is
trying to create it in the root of the file system instead of the
current working directory, which i thought would be CATALINA_BASE.

I just did some test and logging in the webapp:

log.info("Working path: " + new File(".").getAbsolutePath());

is reporting "Working path: /.

Also, I could do a workaround by creating /velocity.log manually and
give the tomcat9 user ownership which strengthen my belief that there
is something strange with the working path..

From the logs it seems that tomcat is picking up the correct settings,
see below, so I really cant get my head around it..

This has been workign without a problem from tomcat6 to tomcat8, is
there some configuration change I may have missed?

28-Jun-2018 08:42:28.896 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Server version:
Apache Tomcat/9.0.10
28-Jun-2018 08:42:28.897 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Server built:
Jun 20 2018 17:32:21 UTC
28-Jun-2018 08:42:28.898 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Server number:
9.0.10.0
28-Jun-2018 08:42:28.899 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log OS Name:
Linux
28-Jun-2018 08:42:28.899 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log OS Version:
4.15.0-23-generic
28-Jun-2018 08:42:28.900 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Architecture:
amd64
28-Jun-2018 08:42:28.900 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Java Home:
/usr/lib/jvm/java-11-openjdk-amd64
28-Jun-2018 08:42:28.901 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log JVM Version:
10.0.1+10-Ubuntu-3ubuntu1
28-Jun-2018 08:42:28.902 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:
Oracle Corporation
28-Jun-2018 08:42:28.902 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:
/ssd/opt/apache-tomcat-9.0.10
28-Jun-2018 08:42:28.903 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:
/ssd/opt/apache-tomcat-9.0.10
28-Jun-2018 08:42:28.904 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-opens=java.base/java.lang=ALL-UNNAMED
28-Jun-2018 08:42:28.905 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-opens=java.base/java.io=ALL-UNNAMED
28-Jun-2018 08:42:28.905 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
28-Jun-2018 08:42:28.906 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.util.logging.config.file=/opt/tomcat/conf/logging.pro
perties
28-Jun-2018 08:42:28.906 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogMa
nager
28-Jun-2018 08:42:28.907 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dfile.encoding=ISO-8859-1
28-Jun-2018 08:42:28.907 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dnet.sf.ehcache.skipUpdateCheck=true
28-Jun-2018 08:42:28.908 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -XX:+CMSClassUnloadingEnabled
28-Jun-2018 08:42:28.908 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djdk.tls.ephemeralDHKeySize=2048
28-Jun-2018 08:42:28.909 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresource
s
28-Jun-2018 08:42:28.909 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
28-Jun-2018 08:42:28.910 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Xms512m
28-Jun-2018 08:42:28.910 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Xmx1G
28-Jun-2018 08:42:28.912 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-modules=java.xml.bind
28-Jun-2018 08:42:28.913 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: --add-modules=java.xml.ws
28-Jun-2018 08:42:28.914 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dignore.endorsed.dirs=
28-Jun-2018 08:42:28.915 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dcatalina.base=/opt/tomcat
28-Jun-2018 08:42:28.918 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Dcatalina.home=/opt/tomcat
28-Jun-2018 08:42:28.919 INFO [main]
org.apache.catalina.startup.VersionLoggerListener.log Command line
argument: -Djava.io.tmpdir=/opt/tomcat/temp

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Konstantin Kolinko
2018-06-30 15:49:57 UTC
Permalink
Post by Carl-Henrik Tjärnlund
Hi!
I'm in the process of upgrading from tomcat 8 to 9 and was running into a
probelm with velocity not beeing able to create the default log file,
./velocity.log and after some troubleshooting it seems it is trying to
create it in the root of the file system instead of the current working
directory, which i thought would be CATALINA_BASE.
log.info("Working path: " + new File(".").getAbsolutePath());
would report "Working path: /.
And I could do a workaround by creating /velocity.log manually and give the
tomcat9 user ownership.
Or you could do System.getProperty("user.dir").


Tomcat does not care what the current working directory is when you
launch it. All it cares is the value of system properties
"catalina.home" and "catalina.base".

(The well known environment variables CATALINA_HOME, CATALINA_BASE are
used by catalina.sh/catalina.bat scripts to set those system
properties when launching Java process for Tomcat).


If your logging configuration supports substitution of environment
variables, use one of those variables explicitly, e.g. as
"${catalina.base}/logs" (see the default conf/logging.properties in
Tomcat for an example).

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Christopher Schultz
2018-06-30 19:45:21 UTC
Permalink
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Konstantin,
2018-06-30 12:55 GMT+03:00 Carl-Henrik Tjärnlund
Hi! I'm in the process of upgrading from tomcat 8 to 9 and was
running into a probelm with velocity not beeing able to create
the default log file, ./velocity.log and after some
troubleshooting it seems it is trying to create it in the root of
the file system instead of the current working directory, which i
thought would be CATALINA_BASE.
log.info("Working path: " + new File(".").getAbsolutePath());
would report "Working path: /. And I could do a workaround by
creating /velocity.log manually and give the tomcat9 user
ownership.
Or you could do System.getProperty("user.dir").
Or put -Duser.dir=[whatever] in CATALINA_BASE/bin/setenv.sh
Tomcat does not care what the current working directory is when
you launch it. All it cares is the value of system properties
"catalina.home" and "catalina.base".
(The well known environment variables CATALINA_HOME, CATALINA_BASE
are used by catalina.sh/catalina.bat scripts to set those system
properties when launching Java process for Tomcat).
+1

Moreover, Tomcat does not alter the CWD from whatever process launched i
t.
If your logging configuration supports substitution of environment
variables, use one of those variables explicitly, e.g. as
"${catalina.base}/logs" (see the default conf/logging.properties
in Tomcat for an example).
This would be best. Relying on the CWD is a bad practice that will
lead to these kinds of problems.

- -chris
-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAls33dEACgkQHPApP6U8
pFgKuQ/7BnyehnsnqDCrMuOZCsRnP/b24Iqpx5PHduknwCp8y1eweR+Yy5gnCTg4
BlNYabwKXdde5U+2IcE6CIxlOVKUDSaK7S0/QrrOy+QExSn5GKIlJ88F4OA5o4ow
6gkzegtMfN4FHfXUKWlCnu9x1Gpv2aAGong9tdLyoXtUo1klrjKim4NgDB7lpqNp
U8fjkkNGyAL55NlqAIaRKwCCq2EfkrgSYnbsO6KgwvOJozWMTU345WrYeUEEnNup
eTByANX1s5hyNsaCyViG12Ossa5kjWcDO2hfhki28z3HiXpay8MIQOgccD3PoWj8
2/oUYZzrc3zCqmKOcda+0bdI33oltSeMX0g+qGnZH05G17BhNC5KCOSf5/2n3mGS
iNpBVwA0bYbgY1S0rYeLukviyr+t8LCR1ccRzgm/ureNFLt09uDXEBy6vfSjGdtP
pMxUtjbBFWWY/jiTKGP4EULWjUODl9osmcAvQZAB9w22r0gyO8JJSijMjiericPH
dWdPcUhTsV0PyK7tw8jxcCX91XX2nUODVPjdxP6KIo95uRRX5ZSe6RFSMEP6AOfK
yrUg93gXC6ZIlJ0c0UCJJXSzb79AAy3FYkCHEnpXUyIaLPvuPiKGgScRvwhFciUh
peaC/7K2/1ICRZoEoye2QSmwY999F24mwqE6uHS+8LquTnpHGQU=
=AvVE
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Carl-Henrik Tjärnlund
2018-06-30 21:05:51 UTC
Permalink
Ok, thanks for the clarification and of course there are multiple ways
to solve this; I just ran in to problems since the behaviour seemed to
have changed between the versions but I've upgrade the whole stack
from OS to java to tomcat so its was hard to isolate the change and I
made the wrong assumption that the CWD was set to CATALINA_BASE. With
your information I got to the root of why the CWD has changed to '/'
and it was a simple as I had not set a home dir for the tomcat9 user
and thus the user-dir was automatically set to '/' when the
systemd-script started tomcat as the tomcat9 user..

Br,
Kalle

---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org

Loading...