Tomcat not work on CentOs - ExecStop=/bin/kill -15 $MAINPID (code=exited, status=1/FAILURE)

February 12, 2019 2.7k views
Linux Basics CentOS Apache Linux Commands

Dear Digital Ocean Community!
I can’t run tomcat as service on CentOs. Somebody else encounter with this problem? Please write here.

The error after systemctl status tomcat

● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; enabled; vendor preset: dis                                                                                      abled)
   Active: activating (auto-restart) (Result: exit-code) since Fri 2019-02-08 07:3                                                                                      7:49 UTC; 1s ago
  Process: 3198 ExecStop=/bin/kill -15 $MAINPID (code=exited, status=1/FAILURE)
  Process: 3185 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCES                                                                                      S)
 Main PID: 3196 (code=exited, status=0/SUCCESS)

Feb 08 07:37:49 centos-s-1vcpu-1gb-ams3-01 systemd[1]: Unit tomcat.service ente...
Feb 08 07:37:49 centos-s-1vcpu-1gb-ams3-01 systemd[1]: tomcat.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

So I think my configuration is good, but anyone think i miss something please write here

Here is my configuration:
-1.
(If I use tomcat 9.0.14 I have an error message in catalina.out: OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appr opriately using -XX:ParallelGCThreads=N

But this I can fix it with change in the 14.point config file(/etc/systemd/system/tomcat.service ) this one: -XX:ParallelGCThreads=N for this: -XX:-AssumeMP Because I use virtual server on Digital Ocean and I have one processor.)

BUT it’s not needed if I use Tomcat 8.5.37

So I use now this step by step…

0.
[root@centos-s-1vcpu-1gb-ams3-01 ~]# java -version
openjdk version “1.8.0191”
OpenJDK Runtime Environment (build 1.8.0
191-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

1.
wget http://xenia.sote.hu/ftp/mirrors/www.apache.org/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz
2.
tar xzf apache-tomcat-8.5.37.tar.gz
3.
mv apache-tomcat-8.5.37/ /opt/tomcat
4.
groupadd tomcat
5.
useradd -g tomcat -M -d /opt/tomcat -s /bin/nologin tomcat
6.
chgrp -R tomcat /opt/tomcat/
7.
chmod -R g+r /opt/tomcat/conf
8.
chmod -R g+x /opt/tomcat/conf
9.
chown -R tomcat /opt/tomcat/webapps/
10.
chown -R tomcat /opt/tomcat/work/
11.
chown -R tomcat /opt/tomcat/temp/
12.
chown -R tomcat /opt/tomcat/logs/
13.
vi /etc/systemd/system/tomcat.service
14.

Systemd unit file for tomcat

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

[Service]
Type=forking

Environment=JAVAHOME=/usr/lib/jvm/jre
Environment=CATALINA
PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINAHOME=/opt/tomcat
Environment=CATALINA
BASE=/opt/tomcat
Environment=‘CATALINAOPTS=-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

15.
systemctl daemon-reload
16.
systemctl start tomcat
17.
systemctl status tomcat

Be the first one to answer this question.

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