0

If i stop Tomcat server as soon as it is started, it gives an error about:

Aug 08, 2016 11:54:26 AM org.apache.catalina.startup.Catalina stopServer SEVERE: Could not contact localhost:8080. Tomcat may not be running. Aug 08, 2016 11:54:26 AM org.apache.catalina.startup.Catalina stopServer SEVERE: Catalina.stop: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345) at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at java.net.Socket.connect(Socket.java:538) at java.net.Socket.<init>(Socket.java:434) at java.net.Socket.<init>(Socket.java:211) at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:450) 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:497) at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:400) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:487) The stop command failed. Attempting to signal the process to stop through OS signal. Tomcat stopped. 

Normally, when tomcat is started, the very last message is something like "Server startup in XXX ms". Shutdown listener is started at the end of starting Tomcat.

How can i start "Shutdown Listener" at the beginning when tomcat start.

4
  • A shutdown is for indicating a shutdown, not a starting. Why do you want it ? Commented Aug 8, 2016 at 9:08
  • Why do you want to stop Tomcat as soon as it is started? Commented Aug 8, 2016 at 9:23
  • Tomcat depends another scripts in my Codes and sometimes These scripts require to stop Tomcat. Commented Aug 8, 2016 at 10:13
  • It's unusual to have the shutdown listener listening on port 8080. Why have you chosen to use port 8080 for the shutdown port? Commented Aug 10, 2016 at 4:09

1 Answer 1

1

You do not want to do that(*). To cleanly ask Tomcat to stop, the stop scripts tries to send it a special request. Tomcat developpers have found that there was a possible problem here if Tomcat could not answer requests because any reason: no still active, partially or totally crashed, etc. To solve it, they just log that Tomcat is not in its normal stated and proceed with an OS signal to force stop it. BTW, the scripts proceeds normally with printing Tomcat stopped at the real end if it was able to stop it.

Even if you could build a special version of Tomcat that would try to process request as soon as possible, there would still be a moment for a race condition, not speaking of possible crashes.

If you simply do not want the error message to be displayed, just wrap the real script with a thin wrapper that takes the output and error output, optionaly logs everything for further research in case of a real problem arising, and just search for the string Tomcat stopped. If it is found drop everything else and just display that, if it is not found after the end of the script signal the the error and give the full output for reference.

(*) anyway, I cannot imagine a reliable system for it...

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Im going to use LOGS and until shutdown listener is shown, i wont let Tomcat is stopped :)
Tomcat never emits the string "Tomcat stopped" to any log file. Also, catalina.sh will only attempt to kill the process if the CATALINA_PID environment variable has been set to a filename where the process-id can be stored.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.