mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add prune_bundler option
This option makes it possible to specify puma in a Gemfile, but then have puma use future Gemfiles in future releases when those releases are seen via cluster workers. Basically, this implements the feature that many people want: the ability to specify puma in a context file and have restarts pickup Gemfile changes.
This commit is contained in:
parent
5dc0c755db
commit
84b7b6a674
3 changed files with 45 additions and 0 deletions
|
@ -162,6 +162,10 @@ module Puma
|
|||
@options[:preload_app] = true
|
||||
end
|
||||
|
||||
o.on "--prune-bundler", "Prune out the bundler env if possible" do
|
||||
@options[:prune_bundler] = true
|
||||
end
|
||||
|
||||
o.on "-q", "--quiet", "Quiet down the output" do
|
||||
@options[:quiet] = true
|
||||
end
|
||||
|
@ -437,6 +441,10 @@ module Puma
|
|||
end
|
||||
end
|
||||
|
||||
def prune_bundler?
|
||||
@options[:prune_bundler] && clustered? && !@options[:preload_app]
|
||||
end
|
||||
|
||||
# Parse the options, load the rackup, start the server and wait
|
||||
# for it to finish.
|
||||
#
|
||||
|
@ -447,6 +455,21 @@ module Puma
|
|||
exit 1
|
||||
end
|
||||
|
||||
if prune_bundler? && defined?(Bundler)
|
||||
puma_lib_dir = $:.detect { |d| File.exist? File.join(d, "puma", "const.rb") }
|
||||
|
||||
if puma_lib_dir
|
||||
log "* Pruning Bundler environment"
|
||||
Bundler.with_clean_env do
|
||||
Kernel.exec(Gem.ruby, "-I", puma_lib_dir,
|
||||
File.expand_path(puma_lib_dir + "/../bin/puma"),
|
||||
*@original_argv)
|
||||
end
|
||||
end
|
||||
|
||||
log "! Unable to prune Bundler environment, continuing"
|
||||
end
|
||||
|
||||
if dir = @options[:directory]
|
||||
Dir.chdir dir
|
||||
end
|
||||
|
|
|
@ -185,6 +185,12 @@ module Puma
|
|||
end
|
||||
end
|
||||
|
||||
# If we're not running under a Bundler context, then
|
||||
# report the info about the context we will be using
|
||||
if !ENV['BUNDLER_GEMFILE'] and File.exist?("Gemfile")
|
||||
log "+ Gemfile in context: #{File.expand_path("Gemfile")}"
|
||||
end
|
||||
|
||||
# Invoke any worker boot hooks so they can get
|
||||
# things in shape before booting the app.
|
||||
hooks = @options[:before_worker_boot]
|
||||
|
|
|
@ -346,6 +346,22 @@ module Puma
|
|||
raise "Provide either a #call'able or a block" unless obj
|
||||
@options[:lowlevel_error_handler] = obj
|
||||
end
|
||||
|
||||
# This option is used to allow your app and it's gems to be
|
||||
# properly reloaded when not using preload.
|
||||
#
|
||||
# When set, if puma detects that it's been invoked in the
|
||||
# context of Bundler, it will cleanup the environment and
|
||||
# re-run itself outside the Bundler environment, but directly
|
||||
# using the files that Bundler has setup.
|
||||
#
|
||||
# This means that puma is now decoupled from your Bundler
|
||||
# context and when each worker loads, it will be loading a
|
||||
# new Bundler context and thus can float around as the release
|
||||
# dictates.
|
||||
def prune_bundler(answer=true)
|
||||
@options[:prune_bundler] = answer
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue