简体   繁体   中英

Running Tomcat9 with dedicated tomcat user: Startup fails with JAVA_HOME or 500 in localhost:8080

I have just installed Apache Tomcat9 on my machine, following mostly these instructions , but I am really stuck with user management here.

My enviroment: Ubuntu 20.04, Java 11 ( There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-oracle/bin/java ).

Few exceptions: I neither have JAVA_HOME , nor the java home directory in my PATH environment variable.

I also have created a symlink at /opt/tomcat/latest/ for pointing to the right folder for all tomcat files.

Now I want to let tomcat run as a service as user 'tomcat'.

This is how my tomcat.service file looks like:

[Unit]
Description=Tomcat 9 servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/java-11-oracle/bin/java"
# Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

Environment="CATALINA_BASE=/opt/tomcat/latest"
Environment="CATALINA_HOME=/opt/tomcat/latest"
Environment="CATALINA_PID=/opt/tomcat/latest/tomcat.pid"
# Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/latest/bin/startup.sh
ExecStop=/opt/tomcat/latest/bin/shutdown.sh

[Install]
WantedBy=multi-user.target

Now, when I comment out the line for the JAVA_HOME environment variable, the startup of the tomcat service fails (journalctl -xe):

Okt 27 17:43:52 my-user startup.sh[7714]: Tomcat started.
Okt 27 17:43:52 my-user shutdown.sh[7737]: PID file found but either no matching process was found or the current user does not have permission to stop the process. Stop aborted.
Okt 27 17:43:52 my-user sudo[7690]: pam_unix(sudo:session): session closed for user root

So there is something running as root, what I don't get.

But when I comment out this line, tomcat runs happily, but on localhost:8080 I am getting this 500 :

Message org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.index_jsp

or this 404

Message JSP file [/index.jsp] not found

It is similar like here and here .

I also did sudo chown -R tomcat /opt/tomcat/latest/work/Catalina/localhost , but this did not help.

Any help is appreciated.

Now it works and I'm going to list my changes here, but I'm not sure, which one was crucial and which was unnecessary.

  1. JAVA_HOME in tomcat.service changed to: Environment="JAVA_HOME=/usr/lib/jvm/java-11-oracle"
  2. CATALINA_PID in tomcat.service changed to: Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid"
  3. give write access to other users to folders work, temp, logs, webapps . Sources here and here .
  4. using this guide: https://www.interserver.net/tips/kb/install-apache-tomcat-on-ubuntu-18-04/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM