Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Systemd tomcat.service failed with no errors

I have Tomcat configured to run as a service using Systemd on CentOS 7.2. I can start Tomcat with no problems:

sudo systemctl start tomcat

I can access the splash screen, the manager app, and even deploy applications. Then I shut down Tomcat:

sudo systemctl stop tomcat

I don't see any errors. But then I check the status:

sudo systemctl status tomcat

● tomcat.service - Apache Tomcat Web Application Container
   Loaded: loaded (/etc/systemd/system/tomcat.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2016-10-30 17:27:19 UTC; 2s ago
  Process: 10833 ExecStop=/bin/kill -TERM $MAINPID (code=exited, status=0/SUCCESS)
  Process: 10785 ExecStart=/opt/tomcat/bin/startup.sh (code=exited, status=0/SUCCESS)
 Main PID: 10795 (code=exited, status=143)

Oct 30 17:26:31 java2016 systemd[1]: Starting Apache Tomcat Web Application Container...
Oct 30 17:26:31 java2016 startup.sh[10785]: Existing PID file found during start.
Oct 30 17:26:31 java2016 startup.sh[10785]: Removing/clearing stale PID file.
Oct 30 17:26:31 java2016 systemd[1]: Started Apache Tomcat Web Application Container.
Oct 30 17:27:19 java2016 systemd[1]: Stopping Apache Tomcat Web Application Container...
Oct 30 17:27:19 java2016 systemd[1]: tomcat.service: main process exited, code=exited, status=143/n/a
Oct 30 17:27:19 java2016 systemd[1]: Stopped Apache Tomcat Web Application Container.
Oct 30 17:27:19 java2016 systemd[1]: Unit tomcat.service entered failed state.
Oct 30 17:27:19 java2016 systemd[1]: tomcat.service failed.

It shows that kill functioned just fine. And /opt/tomcat/logs/catalina.out doesn't show any problems, either:

30-Oct-2016 17:27:19.268 INFO [Thread-5] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
30-Oct-2016 17:27:19.324 INFO [Thread-5] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
30-Oct-2016 17:27:19.375 INFO [Thread-5] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
30-Oct-2016 17:27:19.491 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
30-Oct-2016 17:27:19.493 INFO [Thread-5] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
30-Oct-2016 17:27:19.494 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
30-Oct-2016 17:27:19.495 INFO [Thread-5] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]

Why does Systemd consider Tomcat "failed"? Does it have anything to do with that "stale PID file" message?

like image 501
Garret Wilson Avatar asked Oct 30 '16 17:10

Garret Wilson


People also ask

How do I know if Tomcat is running on Linux?

A simple way to see if Tomcat is running is to check if there is a service listening on TCP port 8080 with the netstat command. This will, of course, only work if you are running Tomcat on the port you specify (its default port of 8080, for example) and not running any other service on that port.

Where is Tomcat Service file?

By default, these files are located at TOMCAT-HOME/conf/server. xml and TOMCAT-HOME/conf/web. xml, respectively.


1 Answers

Ah, never mind; this has been answered already on serverfault for general Java applications.

Basically Java programs sometimes don't send back the expected exit status when shutting down in response to SIGTERM. Adding the following to the tomcat.service file fixes the problem:

[Service]
SuccessExitStatus=143
like image 101
Garret Wilson Avatar answered Sep 19 '22 21:09

Garret Wilson