postrank-labs / goliath

Goliath is a non-blocking Ruby web server framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

What's the purpose of Goliath.run_app_on_exit = true ?

devmod opened this issue · comments

So, I had accidentally put a typo into

  def on_close(env) 

on my Goliath::API class and noticed the app would (after crashing) remain running but on a different port (9000).
I tested locally and noticed that it does not happen if we use the --daemonize flag.
(We don't use --daemonize flag bc of how we have upstart configured.)

So, long story short I realized that what was happening was that the app was being restarted with the default configuration by this flag:

   Goliath.run_app_on_exit

So, I am wondering.. what is the purpose of this flag? and why is it true by default?

Cheers

It's the default behavior for Goliath:

. The motivation is similar to why minitest and others use the same pattern (see here). You can override this behavior though.. see our spec runner code.

Thanks for the explanation, I based myself on the custom server example https://github.com/postrank-labs/goliath/blob/master/examples/custom_server.rb

So, I have the following right now:

runner = Goliath::Runner.new(ARGV, nil)
runner.api = ApiServer.new
runner.logger = custom_logger
runner.app = Goliath::Rack::Builder.build(ApiServer, runner.api)
runner.run

But if I comment runner.run, the app starts anyway because of the on_exit hook, so I am now wondering if the runner.run is required in here? Having it there is what's causing my "starts a new instance when exiting/halting" issue.
(starting it manually like so: ruby my_api.rb --e dev )

You can disable the on_exit logic via:

# Controls whether or not the application will be run using an at_exit block.