Coder Social home page Coder Social logo

cf-shutdown-hook's Introduction

cf-shutdown-hook

This app demonstrates graceful shutdown of an app running in Cloud Foundry.

Build the app with the following command:

$ ./gradlew assemble

Then push to Cloud Foundry with the included manifest.yml.

When the application container is shut down, a shutdown hook in the app will count down from 9 seconds and then allow the app to exit. Log output like the following will be written, along with Tomcat's shutdown logging:

2014-08-14 20:44:02.037  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Initiating graceful shutdown
2014-08-14 20:44:02.037  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 9 seconds
14-Aug-2014 20:44:02.081 INFO [Thread-6] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["ajp-nio-8009"]
14-Aug-2014 20:44:02.133 INFO [Thread-6] org.apache.catalina.core.StandardService.stopInternal Stopping service Catalina
14-Aug-2014 20:44:02.180 INFO [Thread-6] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
14-Aug-2014 20:44:02.181 INFO [Thread-6] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["ajp-nio-8009"]
14-Aug-2014 20:44:02.182 INFO [Thread-6] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
14-Aug-2014 20:44:02.182 INFO [Thread-6] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["ajp-nio-8009"]
2014-08-14 20:44:03.039  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 8 seconds
2014-08-14 20:44:04.040  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 7 seconds
2014-08-14 20:44:05.041  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 6 seconds
2014-08-14 20:44:06.042  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 5 seconds
2014-08-14 20:44:07.043  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 4 seconds
2014-08-14 20:44:08.045  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 3 seconds
2014-08-14 20:44:09.046  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 2 seconds
2014-08-14 20:44:10.048  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 1 seconds
2014-08-14 20:44:11.050  INFO 7816 --- [       Thread-5] o.c.s.shutdown.web.LifecycleComponent    : Shutting down now

cf-shutdown-hook's People

Contributors

scottfrederick avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

kumareshbabuns

cf-shutdown-hook's Issues

10 second limitation?

Hi Scott,

Appreciate nice clean example.

Are you aware that there is a 10 second override? Predestroy needs to be finished in 10 seconds otherwise application exits anyways :-(

Do you have any idea/suggestion about overriding it?
I changed you code to start the count down at 19 and this is what happened

2016-01-23T07:06:31.35-0600 [APP]     OUT 2016-01-23 13:06:31.355  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Initiating graceful shutdown
2016-01-23T07:06:31.35-0600 [APP]     OUT 2016-01-23 13:06:31.356  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 19 seconds
2016-01-23T07:06:32.35-0600 [APP]     OUT 2016-01-23 13:06:32.356  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 18 seconds
2016-01-23T07:06:33.35-0600 [APP]     OUT 2016-01-23 13:06:33.356  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 17 seconds
2016-01-23T07:06:34.35-0600 [APP]     OUT 2016-01-23 13:06:34.357  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 16 seconds
2016-01-23T07:06:35.35-0600 [APP]     OUT 2016-01-23 13:06:35.357  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 15 seconds
2016-01-23T07:06:36.35-0600 [APP]     OUT 2016-01-23 13:06:36.358  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 14 seconds
2016-01-23T07:06:37.35-0600 [APP]     OUT 2016-01-23 13:06:37.358  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 13 seconds
2016-01-23T07:06:38.35-0600 [APP]     OUT 2016-01-23 13:06:38.359  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 12 seconds
2016-01-23T07:06:39.35-0600 [APP]     OUT 2016-01-23 13:06:39.359  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 11 seconds
2016-01-23T07:06:40.36-0600 [APP]     OUT 2016-01-23 13:06:40.359  INFO 14 --- [       Thread-3] o.c.s.shutdown.web.LifecycleComponent    : Shutting down in 10 seconds
2016-01-23T07:06:41.32-0600 [API]     OUT Updated app with guid 5df203f0-48ae-4e2e-88fe-c60d7fc3520a ({"state"=>"STOPPED"})
2016-01-23T07:06:41.34-0600 [APP]     OUT Exit status 255

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.