Skip to content

Commit

Permalink
Change directory in working during upgrade. Fixes #185
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Feb 6, 2013
1 parent f336e8f commit 40af41e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/puma/cli.rb
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -481,7 +483,7 @@ def run_single
end
end

def worker
def worker(upgrade)
$0 = "puma: cluster worker: #{@master_pid}"
Signal.trap "SIGINT", "IGNORE"

Expand All @@ -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]

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 40af41e

Please sign in to comment.