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

February 1, 2019 1.2k views
DigitalOcean Articles CentOS

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
```****
Be the first one to answer this question.