Tomcat 9 doesn't have tomcat.pid file

I've installed Tomcat 9 on Ubuntu 18.04, and trying to add it to service.

However, unlike other users, tomcat.pid file doesn't exist anywhere. So my Tomcat service file generates an error.

[Unit]
Description=Apache Tomcat 9 Servlet Container
After=syslog.target network.target
[Service]
User=nblizz
Group=nblizz
Type=forking
Environment=CATALINA_PID=/opt/apache-tomcat-9.0.16/tomcat.pid <--- !! (Not exist)
Environment=CATALINA_HOME=/opt/apache-tomcat-9.0.16
Environment=CATALINA_BASE=/opt/apache-tomcat-9.0.16
ExecStart=/opt/apache-tomcat-9.0.16/bin/startup.sh
ExecStop=/opt/apache-tomcat-9.0.16/bin/shutdown.sh
Restart=on-failure
[Install]
WantedBy=multi-user.target

Running Tomcat is fine, but error message is displayed when stopping tomcat.

● apache-tomcat.service - Apache Tomcat 9 Servlet Container Loaded: loaded (/etc/systemd/system/apache-tomcat.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Sat 2019-03-16 01:30:39 KST; 1s ago Process: 1462 ExecStop=/opt/apache-tomcat-9.0.16/bin/shutdown.sh (code=exited, status=1/FAILURE) <--- !! Process: 545 ExecStart=/opt/apache-tomcat-9.0.16/bin/startup.sh (code=exited, status=0/SUCCESS) Main PID: 573 (code=killed, signal=TERM)
Mar 16 01:17:29 ndelt-personal systemd[1]: Starting Apache Tomcat 9 Servlet Container...
Mar 16 01:17:29 ndelt-personal startup.sh[545]: Tomcat started.
Mar 16 01:17:29 ndelt-personal systemd[1]: Started Apache Tomcat 9 Servlet Container.
Mar 16 01:30:39 ndelt-personal systemd[1]: Stopping Apache Tomcat 9 Servlet Container...
Mar 16 01:30:39 ndelt-personal shutdown.sh[1462]: $CATALINA_PID was set but the specified file does not exist. Is Tomcat running? Stop aborted.
Mar 16 01:30:39 ndelt-personal systemd[1]: apache-tomcat.service: Control process exited, code=exited status=1
Mar 16 01:30:39 ndelt-personal systemd[1]: apache-tomcat.service: Failed with result 'exit-code'.
Mar 16 01:30:39 ndelt-personal systemd[1]: Stopped Apache Tomcat 9 Servlet Container.

Plus, the color of apache-tomcat.service file is different from the others. ()

What is the problem?

1 Answer

It looks like there was a change from v9.0.14 in the catalina.sh file

$ diff bin/catalina.sh ../tomcats/apache-tomcat-9.0.14/bin/catalina.sh

479c479

< 2\>\&1 \&\& echo \$! \>\“$catalina_pid_file\” \; \} $catalina_out_command “&”

> 2\>\&1 \& echo \$! \>\“$catalina_pid_file\” \; \} $catalina_out_command “&”

489c489

< 2\>\&1 \&\& echo \$! \>\“$catalina_pid_file\” \; \} $catalina_out_command “&”

> 2\>\&1 \& echo \$! \>\“$catalina_pid_file\” \; \} $catalina_out_command “&”

If you remove the extra ampersand there, the pid file is created as expected.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like