mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
During upgrade, change directory in main process instead of workers.
This Fixes #468 by making sure the new `cwd` will be used for all the workers spawned in the future.
This commit is contained in:
parent
e22921c3d8
commit
0a49a6806e
1 changed files with 9 additions and 13 deletions
|
@ -27,6 +27,13 @@ module Puma
|
||||||
def start_phased_restart
|
def start_phased_restart
|
||||||
@phase += 1
|
@phase += 1
|
||||||
log "- Starting phased worker restart, phase: #{@phase}"
|
log "- Starting phased worker restart, phase: #{@phase}"
|
||||||
|
|
||||||
|
# Be sure to change the directory again before loading
|
||||||
|
# the app. This way we can pick up new code.
|
||||||
|
if dir = @options[:worker_directory]
|
||||||
|
log "+ Changing to #{dir}"
|
||||||
|
Dir.chdir dir
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Worker
|
class Worker
|
||||||
|
@ -80,14 +87,12 @@ module Puma
|
||||||
def spawn_workers
|
def spawn_workers
|
||||||
diff = @options[:workers] - @workers.size
|
diff = @options[:workers] - @workers.size
|
||||||
|
|
||||||
upgrade = (@phased_state == :waiting)
|
|
||||||
|
|
||||||
master = Process.pid
|
master = Process.pid
|
||||||
|
|
||||||
diff.times do
|
diff.times do
|
||||||
idx = next_worker_index
|
idx = next_worker_index
|
||||||
|
|
||||||
pid = fork { worker(idx, upgrade, master) }
|
pid = fork { worker(idx, master) }
|
||||||
@cli.debug "Spawned worker: #{pid}"
|
@cli.debug "Spawned worker: #{pid}"
|
||||||
@workers << Worker.new(idx, pid, @phase)
|
@workers << Worker.new(idx, pid, @phase)
|
||||||
@options[:after_worker_boot].each { |h| h.call }
|
@options[:after_worker_boot].each { |h| h.call }
|
||||||
|
@ -163,7 +168,7 @@ module Puma
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def worker(index, upgrade, master)
|
def worker(index, master)
|
||||||
$0 = "puma: cluster worker #{index}: #{master}"
|
$0 = "puma: cluster worker #{index}: #{master}"
|
||||||
Signal.trap "SIGINT", "IGNORE"
|
Signal.trap "SIGINT", "IGNORE"
|
||||||
|
|
||||||
|
@ -176,15 +181,6 @@ module Puma
|
||||||
exit! 1
|
exit! 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# Be sure to change the directory again before loading
|
|
||||||
# the app. This way we can pick up new code.
|
|
||||||
if upgrade
|
|
||||||
if dir = @options[:worker_directory]
|
|
||||||
log "+ Changing to #{dir}"
|
|
||||||
Dir.chdir dir
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# If we're not running under a Bundler context, then
|
# If we're not running under a Bundler context, then
|
||||||
# report the info about the context we will be using
|
# report the info about the context we will be using
|
||||||
if !ENV['BUNDLER_GEMFILE'] and File.exist?("Gemfile")
|
if !ENV['BUNDLER_GEMFILE'] and File.exist?("Gemfile")
|
||||||
|
|
Loading…
Add table
Reference in a new issue