5

Quote from CF training on twelve-factor app’s processes are disposable:

Apps should also shut down gracefully (but can also die unexpectedly). Cloud Foundry stops routing traffic nearly instantaneously to failed or shutdown instances.

Cloud Foundry apps are stateless. I don't understand how to shut down gracefully a stateless app. A stateless app can always handle kill -9?

Sybil
  • 472
  • 4
  • 11

2 Answers2

6

kill -9 is used by the kernel to terminate stateful programs that are no longer responding (including to shutdown requests). To gracefully shut down a stateful app you would use kill -15 which instructs the application to call it's shutdown functions and do the requisite cleanup. If you app is truly stateless, there should be no difference in the results of kill -9 and kill -15, but technically, a graceful shutdown of this program would still be kill -15

James Shewey
  • 3,752
  • 1
  • 17
  • 38
3

A stateless app can always handle kill -9?

Yes. But even a stateless app handles connections from the outside (or it would do nothing, really!). That is the issue here. If your app, say, some HTTP server that only serves static files, and is thus stateless, were to be routinely killed with -9, then ever so often, you would kill it with an active connection. So your customer would get some HTTP error code. In the best case, it is an unimportant small image and he doesn't even notice; in the worst case, it is your main .js or .css file and he will indeed notice badly.

So, by using a weaker signal, you give your stateless app the chance to finish the current request before shutting down.

Obviously, you can finish it off with -9 if it does not go away after a second or two (or however long you wish to give it time to end its business).

AnoE
  • 4,936
  • 14
  • 26