1
0
Fork 0
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:
Marwan Al Jubeh 2014-02-17 15:34:40 +02:00 committed by Evan Phoenix
parent e22921c3d8
commit 0a49a6806e

View file

@ -27,6 +27,13 @@ module Puma
def start_phased_restart
@phase += 1
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
class Worker
@ -80,14 +87,12 @@ module Puma
def spawn_workers
diff = @options[:workers] - @workers.size
upgrade = (@phased_state == :waiting)
master = Process.pid
diff.times do
idx = next_worker_index
pid = fork { worker(idx, upgrade, master) }
pid = fork { worker(idx, master) }
@cli.debug "Spawned worker: #{pid}"
@workers << Worker.new(idx, pid, @phase)
@options[:after_worker_boot].each { |h| h.call }
@ -163,7 +168,7 @@ module Puma
end
end
def worker(index, upgrade, master)
def worker(index, master)
$0 = "puma: cluster worker #{index}: #{master}"
Signal.trap "SIGINT", "IGNORE"
@ -176,15 +181,6 @@ module Puma
exit! 1
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
# report the info about the context we will be using
if !ENV['BUNDLER_GEMFILE'] and File.exist?("Gemfile")