https://bz.apache.org/bugzilla/show_bug.cgi?id=63389
--- Comment #10 from Eugène Adell <eugene.ad...@gmail.com> --- (In reply to Igal Sapir from comment #0) > Currently, one hack that many use is to launch Tomcat during the container > build process, wait for an arbitrary length of time, e.g. 10s or 20s, and > then shut Tomcat down. >From your question and some comments, if the problem is with the "arbitrary length of time", I suggest to rely on JMX particularly on the Connector stateName value. It is changing from INITIALIZED to STARTED once Tomcat has finished deploying. If you can bring ANT within your docker, the effort is not that huge, you just need 2 targets, one for monitoring the Connector state, and one for stopping Tomcat. This is the result that I get with a servlet called at the startup and that sleeps 60 during its initialization : catalina.out 09-Jul-2019 22:10:55.804 INFO [localhost-startStop-5] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/eadell/tests/apache-tomcat-8.5.15/webapps/host-manager] has finished in [27] ms 09-Jul-2019 22:10:55.879 FINE [localhost-startStop-4] org.apache.catalina.authenticator.AuthenticatorBase.startInternal No SingleSignOn Valve is present 09-Jul-2019 22:10:56.055 INFO [localhost-startStop-4] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/eadell/tests/apache-tomcat-8.5.15/webapps/examples] has finished in [793] ms 09-Jul-2019 22:11:55.779 INFO [localhost-startStop-3] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/home/eadell/tests/apache-tomcat-8.5.15/webapps/slowstart] has finished in [60,518] ms 09-Jul-2019 22:11:55.790 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8280"] 09-Jul-2019 22:11:55.811 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8281"] 09-Jul-2019 22:11:55.815 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 60719 ms 09-Jul-2019 22:11:57.411 INFO [main] org.apache.catalina.core.StandardServer.await A valid shutdown command was received via the shutdown port. Stopping the Server instance. 09-Jul-2019 22:11:57.412 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8280"] 09-Jul-2019 22:11:57.469 INFO [main] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8281"] 09-Jul-2019 22:11:57.521 INFO [main] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina] destroying LongInitServlet shell output $ time (bin/startup.sh ; ant -f anted-jmx/project.xml buildAndStop) Using CATALINA_BASE: /home/eadell/tests/apache-tomcat Using CATALINA_HOME: /home/eadell/tests/apache-tomcat Using CATALINA_TMPDIR: /home/eadell/tests/apache-tomcat/temp Using JRE_HOME: /usr/local/java/1.9 Using CLASSPATH: /home/eadell/tests/apache-tomcat/bin/bootstrap.jar:/home/eadell/tests/apache-tomcat/bin/tomcat-juli.jar Tomcat started. Buildfile: /home/eadell/tests/apache-tomcat-8.5.15/anted-jmx/project.xml waitMBEAN: [echo] Server url alive shutdown: [echo] shutting down ${tomcat.catalina_base} buildAndStop: BUILD SUCCESSFUL Total time: 1 minute 3 seconds real 1m4.673s user 0m5.157s sys 0m0.600s Here are the ANT targets : <target name="waitMBEAN"> <jmxOpen host="${jmx.server.name}" port="${jmx.server.port}" username="controlRole" password="******" /> <waitfor maxwait="1200" maxwaitunit="second" timeoutproperty="server.timeout" > <jmxCondition operation="==" name="Catalina:type=Connector,port=8281" attribute="stateName" value="STARTED" /> </waitfor> <fail if="server.timeout" message="Server url don't answer inside 1200 sec" /> <echo message="Tomcat finished starting" /> </target> <target name="shutdown" description="stop tomcat"> <echo message="shutting down ${tomcat.catalina_base}" /> <exec executable="/bin/bash"> <arg line="${catalina.home}/bin/shutdown.sh" /> </exec> </target> <target name="buildAndStop" depends="waitMBEAN,shutdown" /> If required you could also add targets to call servlets, and stop once you have finished these calls. Of course, remember to use a random JMX password then you would not compromise all of your Tomcats if something bad happened. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org