Hi Guys,
I am trying to understand how apps, specifically how java webapps are shutdown by cloudfoundry.
I have the following code in my java webapp.
public class TestContextListener implements ServletContextListener {
@Override
public void contextInitialized(final ServletContextEvent evt) {
System.out.println("#####################################################");
System.out.println("contextInitialized");
System.out.println("#####################################################");
}
@Override
public void contextDestroyed(final ServletContextEvent evt) {
System.out.println("#####################################################");
System.out.println("contextDestroyed");
System.out.println("#####################################################");
}
}
Logs:
2014-10-02T14:04:49.70-0500 [App/0] OUT [CONTAINER] org.apache.coyote.http11.Http11NioProtocol INFO Initializing ProtocolHandler ["http-nio-61004"]
2014-10-02T14:04:49.71-0500 [App/0] OUT [CONTAINER] org.apache.catalina.startup.Catalina INFO Initialization processed in 417 ms
2014-10-02T14:04:49.72-0500 [App/0] OUT [CONTAINER] org.apache.catalina.core.StandardService INFO Starting service Catalina
2014-10-02T14:04:49.72-0500 [App/0] OUT [CONTAINER] org.apache.catalina.core.StandardEngine INFO Starting Servlet Engine: Apache Tomcat/8.0.12
2014-10-02T14:04:49.74-0500 [App/0] OUT [CONTAINER] org.apache.catalina.startup.HostConfig INFO Deploying web application directory /home/vcap/app/.java-buildpack/tomcat/webapps/ROOT
2014-10-02T14:04:53.29-0500 [App/0] OUT #####################################################
2014-10-02T14:04:53.29-0500 [App/0] OUT #####################################################
2014-10-02T14:04:53.29-0500 [App/0] OUT contextInitialized
2014-10-02T14:04:53.30-0500 [App/0] OUT #####################################################
2014-10-02T14:04:53.30-0500 [App/0] OUT #####################################################
2014-10-02T14:04:55.75-0500 [App/0] OUT [CONTAINER] org.apache.catalina.startup.Catalina INFO Server startup in 6043 ms
2014-10-02T14:04:56.23-0500 [DEA] ERR Instance (index 0) failed to start accepting connections
2014-10-02T14:06:05.58-0500 [API] OUT Updated app with guid d235c71a-10e9-45b8-b878-55b4a5433c94 ({"state"=>"STOPPED"})
2014-10-02T14:06:05.58-0500 [App/0] OUT Dropped a message because of read error: read unix /var/vcap/data/warden/depot/184edailtu7/jobs/40/stdout.sock: use of closed network connection
2014-10-02T14:06:05.58-0500 [App/0] ERR
2014-10-02T14:06:16.81-0500 [DEA] OUT Stopping app instance (index 0) with guid d235c71a-10e9-45b8-b878-55b4a5433c94
2014-10-02T14:06:16.81-0500 [DEA] OUT Stopped app instance (index 0) with guid d235c71a-10e9-45b8-b878-55b4a5433c94
2014-10-02T14:06:16.81-0500 [DEA] OUT Stopping app instance (index 0) with guid d235c71a-10e9-45b8-b878-55b4a5433c94
2014-10-02T14:06:16.81-0500 [DEA] OUT Stopped app instance (index 0) with guid d235c71a-10e9-45b8-b878-55b4a5433c94
So when my app is deployed I see the above context initialized logs. But when I do "cf stop/delete" i dont see logs from the contextDestroyed() method.
But also came across this documentation (
https://github.com/cloudfoundry/warden/tree/master/warden >
Container Lifecycle > Destroy) which says that cloudfoundry sends a "SIGTERM" first, waits for a couple of seconds and then sends a "SIGKILL" to shutdown the tomcat container where the app is deployed.
If this is true is there a way to configure this "wait for a couple of seconds before sending a 'SIGKILL'" through some env or config file.
I need a way to execute some cleanup code in the contextDestroyed() method.
If you guys can provide any pointers that would be very helpfull.
Thank you.