Report this

What is the reason for this report?

Can't kill $MAINPID in Tomcat (code=exited, status=1/FAILURE)

Posted on February 1, 2019

I follow the Digital Ocean Guide How To Install Apache Tomcat 8 on CentOS 7? https://www.digitalocean.com/community/tutorials/how-to-install-apache-tomcat-8-on-centos-7 Because I want to able to run Tomcat as a service. But in the config file(/etc/systemd/system/tomcat.service) there is a wrong part: I got folowing error if I get the command: **systemctl tomcat status: **ExecStop=/bin/kill -15 $MAINPID (code=exited, status=1/FAILURE) here is the content of the file:

# 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
UMask=0007
RestartSec=10
Restart=always

[Install]
WantedBy=multi-user.target
```****


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi @milan7,

Thanks for pointing out this bug! I’ve gone over the tutorial and found out what’s going on. So, notice the following line

ExecStop=/bin/kill -15 $MAINPID

in the configuration file. It’s giving a kill signal 15, which states the process to close itself. That’s good until the process you are trying to kill has stuck and can’t do it. In your case,I’ll recommend using

ExecStop=/bin/kill -9 $MAINPID

kill -9 actually closes the process no matter what. So it seems like your process is getting stuck and needs to be killed with -9 rather than -15.

Regards, KDSys

When you use CATALINA_PID in tomcat.service file please make sure to use the path inside of the double-quotes.

Environment="CATALINA_PID=/opt/tomcat/latest/temp/tomcat.pid" 

Like below

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

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="/usr/lib/jvm/java-1.8.0-openjdk-amd64"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom -Djava.awt.headless=true"

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

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

[Install]
WantedBy=multi-user.target

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.