giraffesoft-unicorn 0.93.5 → 0.93.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -490,13 +490,6 @@ module Unicorn
490
490
  def spawn_missing_workers
491
491
  (0...worker_processes).each do |worker_nr|
492
492
  WORKERS.values.include?(worker_nr) and next
493
- begin
494
- Dir.chdir(START_CTX[:cwd])
495
- rescue Errno::ENOENT => err
496
- logger.fatal "#{err.inspect} (#{START_CTX[:cwd]})"
497
- SIG_QUEUE << :QUIT # forcibly emulate SIGQUIT
498
- return
499
- end
500
493
  worker = Worker.new(worker_nr, Unicorn::Util.tmpio)
501
494
  before_fork.call(self, worker)
502
495
  WORKERS[fork { worker_loop(worker) }] = worker
@@ -9,6 +9,7 @@ module Unicorn
9
9
  #
10
10
  # Example (when used with the unicorn config file):
11
11
  # worker_processes 4
12
+ # working_directory "/path/to/deploy/app/current"
12
13
  # listen '/tmp/my_app.sock', :backlog => 1
13
14
  # listen 9292, :tcp_nopush => true
14
15
  # timeout 10
@@ -345,6 +346,16 @@ module Unicorn
345
346
  set_path(:stdout_path, path)
346
347
  end
347
348
 
349
+ # sets the working directory for Unicorn. This ensures USR2 will
350
+ # start a new instance of Unicorn in this directory. This may be
351
+ # a symlink. You should specify this directive near the top or
352
+ # your config file before any relative paths for other config
353
+ # directives (or avoid relative paths entirely).
354
+ def working_directory(path)
355
+ # just let chdir raise errors
356
+ Dir.chdir(HttpServer::START_CTX[:cwd] = path)
357
+ end
358
+
348
359
  # expands "unix:path/to/foo" to a socket relative to the current path
349
360
  # expands pathnames of sockets if relative to "~" or "~username"
350
361
  # expands "*:port and ":port" to "0.0.0.0:port"
@@ -75,6 +75,45 @@ end
75
75
  end
76
76
  end
77
77
 
78
+ def test_working_directory
79
+ other = Tempfile.new('unicorn.wd')
80
+ File.unlink(other.path)
81
+ Dir.mkdir(other.path)
82
+ File.open("config.ru", "wb") do |fp|
83
+ fp.syswrite <<EOF
84
+ use Rack::ContentLength
85
+ run proc { |env| [ 200, { 'Content-Type' => 'text/plain' }, [ Dir.pwd ] ] }
86
+ EOF
87
+ end
88
+ FileUtils.cp("config.ru", other.path + "/config.ru")
89
+ tmp = Tempfile.new('unicorn.config')
90
+ tmp.syswrite <<EOF
91
+ working_directory '#@tmpdir'
92
+ listen '#@addr:#@port'
93
+ EOF
94
+ pid = xfork { redirect_test_io { exec($unicorn_bin, "-c#{tmp.path}") } }
95
+ wait_workers_ready("test_stderr.#{pid}.log", 1)
96
+ results = hit(["http://#@addr:#@port/"])
97
+ assert_equal @tmpdir, results.first
98
+ File.truncate("test_stderr.#{pid}.log", 0)
99
+
100
+ tmp.sysseek(0)
101
+ tmp.truncate(0)
102
+ tmp.syswrite <<EOF
103
+ working_directory '#{other.path}'
104
+ listen '#@addr:#@port'
105
+ EOF
106
+
107
+ Process.kill(:HUP, pid)
108
+ wait_workers_ready("test_stderr.#{pid}.log", 1)
109
+ results = hit(["http://#@addr:#@port/"])
110
+ assert_equal other.path, results.first
111
+
112
+ Process.kill(:QUIT, pid)
113
+ ensure
114
+ FileUtils.rmtree(other.path)
115
+ end
116
+
78
117
  def test_exit_signals
79
118
  %w(INT TERM QUIT).each do |sig|
80
119
  File.open("config.ru", "wb") { |fp| fp.syswrite(HI) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giraffesoft-unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.93.5
4
+ version: 0.93.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unicorn developers