I want to start Apache Tomcat 7 on my Redhat-7 (RHEL7) server automatically on system startup.
To do that, I did the following steps:
- create the following init.d script and make it executable (works fine)
- put init.d tomcat script link in rc files
The problem: Tomcat cannot start because the corresponding ports, especially the AJP port, are already in use (only after rebooting the system; a simple use of the init.d script does not cause the problem).
My guess: Either it doesn't shutdown properly or it starts twice and causes the problem that way.
If I reboot the system, Tomcat tries to start. I'm trying to access my website, but only a blank page appears. This is the catalina.out where it starts to fail (example of failure with port 8005, but I have the same problem with 8009 and 8080):
20-Apr-2020 20:24:00.813 INFO (localhost-startStop-1) org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /opt/apache-tomcat-8.0.32/webapps/ROOT has finished in 79 ms
20-Apr-2020 20:24:00.821 INFO (main) org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ("http-nio-127.0.0.1-8080")
20-Apr-2020 20:24:00.831 INFO (main) org.apache.catalina.startup.Catalina.start Server startup in 58427 ms
20-Apr-2020 20:24:00.831 SEVERE (main) org.apache.catalina.core.StandardServer.await StandardServer.await: create(localhost:8005):
java.net.BindException: Address already in use
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.AbstractPlainSocketImpl.bind(AbstractPlainSocketImpl.java:387)
at java.net.ServerSocket.bind(ServerSocket.java:375)
at java.net.ServerSocket.(ServerSocket.java:237)
at org.apache.catalina.core.StandardServer.await(StandardServer.java:420)
at org.apache.catalina.startup.Catalina.await(Catalina.java:717)
at org.apache.catalina.startup.Catalina.start(Catalina.java:663)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
20-Apr-2020 20:24:00.832 INFO (main) org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ("http-nio-127.0.0.1-8080")
20-Apr-2020 20:24:00.832 INFO (main) org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ("ajp-nio-8009")
20-Apr-2020 20:24:00.832 INFO (main) org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
2020-04-20 20:24:00,856 (localhost-startStop-1) DEBUG o.x.shutdown - Stopping XWiki...
After doing a & # 39; pgrep java & # 39; I have to kill the process manually. Then I can start the tomcat without problems.
Of course, I can manually kill the process using pkill -9 java and start it later. Since this process must be automated, I can't just kill it all the time.
I tried automatic startup on my Debian 9 server with Tomcat 8, everything works fine there.
Do you have an idea of how I can solve or at least avoid the error?
Appendix
My server.xml file:
(...)
Logout error (extract):
20-Apr-2020 20:22:26.607 SEVERE (localhost-startStop-2) org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application (xwiki) created a ThreadLocal with key of type (com.xpn.xwiki.store.migration.AbstractDataMigrationManager.ThreadLock) (value (com.xpn.xwiki.store.migration.AbstractDataMigrationManager$ThreadLock@7f9e8cb9)) and a value of type (java.lang.Integer) (value (0)) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
20-Apr-2020 20:22:26.607 SEVERE (localhost-startStop-2) org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application (xwiki) created a ThreadLocal with key of type (org.apache.solr.logging.MDCLoggingContext$1) (value (org.apache.solr.logging.MDCLoggingContext$1@21089b81)) and a value of type (java.lang.Integer) (value (0)) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
20-Apr-2020 20:22:26.623 INFO (Thread-15) org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ("http-nio-127.0.0.1-8080")
20-Apr-2020 20:22:26.714 INFO (Thread-15) org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ("ajp-nio-8009")
20-Apr-2020 20:22:26.767 INFO (Thread-15) org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ("http-nio-127.0.0.1-8080")
20-Apr-2020 20:22:26.768 INFO (Thread-15) org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ("ajp-nio-8009")
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0