Permalink
Browse files

Change directory in working during upgrade. Fixes #185

  • Loading branch information...
1 parent f336e8f commit 40af41e5ef13c6e0c9343f4fe40bafca9441b80b @evanphx evanphx committed Feb 6, 2013
Showing with 15 additions and 2 deletions.
  1. +15 −2 lib/puma/cli.rb
View
@@ -63,6 +63,7 @@ def generate_restart_data
if s_env.ino == s_pwd.ino and s_env.dev == s_pwd.dev
@restart_dir = dir
+ @options[:worker_directory] = dir
end
end
@@ -208,6 +209,7 @@ def setup_options
o.on "--dir DIR", "Change to DIR before starting" do |d|
@options[:directory] = d.to_s
+ @options[:worker_directory] = d.to_s
end
o.on "-e", "--environment ENVIRONMENT",
@@ -481,7 +483,7 @@ def run_single
end
end
- def worker
+ def worker(upgrade)
$0 = "puma: cluster worker: #{@master_pid}"
Signal.trap "SIGINT", "IGNORE"
@@ -494,6 +496,15 @@ def worker
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
+
min_t = @options[:min_threads]
max_t = @options[:max_threads]
@@ -560,8 +571,10 @@ def term
def spawn_workers
diff = @options[:workers] - @workers.size
+ upgrade = (@phased_state == :waiting)
+
diff.times do
- pid = fork { worker }
+ pid = fork { worker(upgrade) }
debug "Spawned worker: #{pid}"
@workers << Worker.new(pid, @phase)
end

0 comments on commit 40af41e

Please sign in to comment.