From 0a49a6806e058411ce788418ba954d70a3a1cb67 Mon Sep 17 00:00:00 2001 From: Marwan Al Jubeh Date: Mon, 17 Feb 2014 15:34:40 +0200 Subject: [PATCH] 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. --- lib/puma/cluster.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/lib/puma/cluster.rb b/lib/puma/cluster.rb index 7c571fa2..1fcd621b 100644 --- a/lib/puma/cluster.rb +++ b/lib/puma/cluster.rb @@ -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")