我将Tomcat配置为在CentOS 7.2上使用Systemd作为服务运行。我可以毫无问题地启动Tomcat:
sudo systemctl start tomcat
我可以访问启动画面,管理器应用程序,甚至可以部署应用程序。然后我关闭了Tomcat:
sudo systemctl stop tomcat
我没有看到任何错误。但后来我检查状态:
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.
它表明kill
功能正常。并且/opt/tomcat/logs/catalina.out
也没有显示任何问题:
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"]
为什么Systemd会考虑Tomcat"失败"?它与#34;陈旧的PID文件有什么关系"消息?
答案 0 :(得分:2)
基本上,Java程序有时在关闭以响应SIGTERM时不会发回预期的退出状态。将以下内容添加到tomcat.service
文件可以解决问题:
[Service]
SuccessExitStatus=143