19

I am trying to install tomcat on a new CentOS 7 virtual machine. I successfully installed apache httpd, and am able to get the apache test page when I type the ip of the virtual machine into a web browser on another computer in the network. But I am getting the following error message when I type systemctl start tomcat:

Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.  

Here is the complete history of commands in the install of java and tomcat:

I first started by installing java using the instructions from this tutorial because the tomcat instructions (second block below) wanted me to use openjdk, and I need to use real java:

//Install Java
# cd /opt/
# yum install wget
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u60-b27/jdk-8u60-linux-x64.tar.gz"

# tar xzf jdk-8u60-linux-x64.tar.gz

# cd /opt/jdk1.8.0_60/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_60/bin/java 2
# alternatives --config java
(Select the version you want)
# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_60/bin/jar 2
# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_60/bin/javac 2
# alternatives --set jar /opt/jdk1.8.0_60/bin/jar
# alternatives --set javac /opt/jdk1.8.0_60/bin/javac
# java -version (checks to see you install correct version)
# export JAVA_HOME=/opt/jdk1.8.0_60
# export JRE_HOME=/opt/jdk1.8.0_60/jre
# export PATH=$PATH:/opt/jdk1.8.0_60/bin:/opt/jdk1.8.0_60/jre/bin

Note that the preceding tutorial does not explain how to put the environment variables in /etc/environment, so I stopped before that command.

The following commands are from this other tutorial. I started at the point after installing java:

//Install Tomcat
Login as sudo user, not root.
# sudo groupadd tomcat
# sudo useradd -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
# cd ~
# wget http://mirrors.gigenet.com/apache/tomcat/tomcat-8/v8.0.27/bin/apache-tomcat-8.0.27.tar.gz
# sudo mkdir /opt/tomcat
# sudo tar xvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
# cd /opt/tomcat
# sudo chgrp -R tomcat conf
# sudo chmod g+rwx conf
# sudo chmod g+r conf/*
# sudo chown -R tomcat work/ temp/ logs/
# sudo vi /etc/systemd/system/tomcat.service
Cut and paste the following file contents:
##################################################
# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/lib/jvm/jre
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target
##################################################
# sudo systemctl daemon-reload

# sudo systemctl start tomcat
Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details.
# sudo systemctl start tomcat.service

Job for tomcat.service failed. See 'systemctl status tomcat.service' and 'journalctl -xn' for details. # sudo systemctl enable tomcat.service ln -s '/etc/systemd/system/tomcat.service' '/etc/systemd/system/multi-user.target.wants/tomcat.service' # sudo systemctl enable tomcat

# sudo systemctl status tomcat.service
tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled)
   Active: failed (Result: exit-code) since Tue 2015-10-13 11:05:31 PDT; 47s ago

Oct 13 11:05:31 localhost.localdomain kill[20887]: -q, --queue <sig>      use sigqueue(2) rather than kill(2)
Oct 13 11:05:31 localhost.localdomain kill[20887]: -p, --pid              print pids without signaling them
Oct 13 11:05:31 localhost.localdomain kill[20887]: -l, --list [=<signal>] list signal names, or convert one to a name
Oct 13 11:05:31 localhost.localdomain kill[20887]: -L, --table            list signal names and numbers
Oct 13 11:05:31 localhost.localdomain kill[20887]: -h, --help     display this help and exit
Oct 13 11:05:31 localhost.localdomain kill[20887]: -V, --version  output version information and exit
Oct 13 11:05:31 localhost.localdomain kill[20887]: For more details see kill(1).
Oct 13 11:05:31 localhost.localdomain systemd[1]: tomcat.service: control process exited, code=exited status=1
Oct 13 11:05:31 localhost.localdomain systemd[1]: Failed to start Apache Tomcat Web Application Container.
Oct 13 11:05:31 localhost.localdomain systemd[1]: Unit tomcat.service entered failed state.

Doing a yum localinstall of an updated jdk rpm, as suggested in this other posting, did not work.


EDITS:


As per @Bram's suggestion, I changed the config file to the following, but am still getting the same error:

# Systemd unit file for tomcat
[Unit]
Description=Apache Tomcat Web Application Container
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/opt/jdk1.8.0_60
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/bin/kill -15 $MAINPID

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

Also, as per @JeffSchaller's comment in chat, I was able to get tomcat to start natively as follows:

[user@localhost tomcat]$ sudo /opt/tomcat/bin/startup.sh
Using CATALINA_BASE: /opt/tomcat
Using CATALINA_HOME: /opt/tomcat
Using CATALINA_TMPDIR: /opt/tomcat/temp
Using JRE_HOME: /
Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar
Tomcat started.
[user@localhost tomcat]$

Thus the problem in this OP seems to be with the systemd config. How can I fix it?

2
  • Any errors in the tomcat log file? If I remember correctly the file is called catalina.out or something like that.
    – Bram
    Oct 13, 2015 at 19:08
  • Tomcat logs after sudo systemctl start tomcat.service are a bunch of permission denied errors that take hundreds of lines.
    – CodeMed
    Oct 13, 2015 at 19:24

3 Answers 3

16

I had the same problem, fixed it by:

  1. giving tomcat user ownership of the whole tomcat directory:

    cd /opt && sudo chown -R tomcat tomcat/
    
  2. and commenting out below line in /etc/systemd/system/tomcat.service:

    Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
    
5
  • 1
    Is it safe to make tomcat the owner of the entire folder? I thought we want to restrict access as much as possible? Aug 15, 2016 at 18:55
  • I don't have this setup to test now, but I think the problem was in : "sudo chown -R tomcat work/ temp/ logs/". I'd say it needs the ownership of "bin/" as well at least. Aug 16, 2016 at 0:34
  • Step 1 alone did it for me it seems. What does the line in step 2 do exactly? Sep 26, 2016 at 23:24
  • You're right, step 1 is enough to fix this particular issue. Step 2 sets the java heap size and garbage collection type. I needed it because of my environment properties but most people probably won't. Oct 3, 2016 at 23:45
  • in my case only cd /opt && sudo chown -R tomcat tomcat/ worked. Because I changed the owner to system user and forgot to make tomcat as owner back
    – imdzeeshan
    Oct 31, 2017 at 12:16
2

Since you installed Java in a non defalt location you need to tell tomcat where to find it.

In the unit file you posted JAVA_HOME is set to /usr/lib/jvm/jre but in the section about the java installation JAVA_HOME is /opt/jdk1.8.0_60.

If you set JAVA_HOME in the tomcat systemd unit file I believe it will work.

Also the unit file specifies user tomcat. But when you start it manually you start it as root. The problem is likely that tomcat attempts to open a privileged port. Does the start script start tomcat as root? Or does it start processes as user tomcat? Removing the user and group from the unit file should trigger the same behaviour of your command line attempt.

1
  • How to fix following error: Job for tomcat8.service failed because the control process exited with error code. See "systemctl status tomcat8.service" and "journalctl -xe" for details. invoke-rc.d: initscript tomcat8, action "start" failed. --> sudo nano /etc/default/tomcat8 --> Set JAVA_HOME JAVA_HOME=/usr/lib/jvm/java-8-oracle --> gist.github.com/alexislucena/89a046dc747123faf4496fb946c1fe79
    – Combine
    Jul 10, 2018 at 9:23
1

According to error messages, I think the issue comes from ExecStop=/bin/kill -15 $MAINPID where variable is not replaced. According to service documentation $MAINPID is expected only for ExecReload command. The question remains: why ExecStop is ran when you trigger start ?

It is possible systemd leaves JVM process working directory as / which may not be relevant for deployed applications.

I propose you move CATALINA_OPTS and JAVA_OPTS into /opt/tomcat/bin/setenv.sh script and try first with such a simple configuration:

[Unit]
Description=Apache Tomcat
After=syslog.target network.target

[Service]
Type=forking

Environment=JAVA_HOME=/usr/java/default
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat

WorkingDirectory=/opt/tomcat

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

User=tomcat
Group=tomcat

[Install]
WantedBy=multi-user.target

In any case, please report journalctl -xn and logs/catalina.out content

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.