unicorn 0.95.3 → 0.96.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (30) hide show
  1. data/Documentation/unicorn.1.txt +5 -6
  2. data/Documentation/unicorn_rails.1.txt +4 -6
  3. data/GIT-VERSION-GEN +1 -1
  4. data/GNUmakefile +2 -2
  5. data/bin/unicorn +2 -2
  6. data/bin/unicorn_rails +2 -2
  7. data/lib/unicorn.rb +19 -2
  8. data/lib/unicorn/const.rb +1 -1
  9. data/lib/unicorn/http_request.rb +1 -1
  10. data/lib/unicorn/http_response.rb +2 -1
  11. data/lib/unicorn/launcher.rb +32 -6
  12. data/local.mk.sample +1 -1
  13. data/test/exec/test_exec.rb +1 -1
  14. data/test/rails/{app-2.3.3.1 → app-2.3.5}/.gitignore +0 -0
  15. data/test/rails/{app-2.3.3.1 → app-2.3.5}/Rakefile +0 -0
  16. data/test/rails/{app-2.3.3.1 → app-2.3.5}/app/controllers/application_controller.rb +0 -0
  17. data/test/rails/{app-2.3.3.1 → app-2.3.5}/app/controllers/foo_controller.rb +0 -0
  18. data/test/rails/{app-2.3.3.1 → app-2.3.5}/app/helpers/application_helper.rb +0 -0
  19. data/test/rails/{app-2.3.3.1 → app-2.3.5}/config/boot.rb +0 -0
  20. data/test/rails/{app-2.3.3.1 → app-2.3.5}/config/database.yml +0 -0
  21. data/test/rails/{app-2.3.3.1 → app-2.3.5}/config/environment.rb +0 -0
  22. data/test/rails/{app-2.3.3.1 → app-2.3.5}/config/environments/development.rb +0 -0
  23. data/test/rails/{app-2.3.3.1 → app-2.3.5}/config/environments/production.rb +0 -0
  24. data/test/rails/{app-2.3.3.1 → app-2.3.5}/config/routes.rb +0 -0
  25. data/test/rails/{app-2.3.3.1 → app-2.3.5}/db/.gitignore +0 -0
  26. data/test/rails/{app-2.3.3.1 → app-2.3.5}/public/404.html +0 -0
  27. data/test/rails/{app-2.3.3.1 → app-2.3.5}/public/500.html +0 -0
  28. data/test/rails/{app-2.3.3.1 → app-2.3.5}/public/x.txt +0 -0
  29. data/test/unit/test_server.rb +10 -0
  30. metadata +18 -18
@@ -13,8 +13,8 @@ unicorn [-c CONFIG_FILE] [-E RACK_ENV] [-D] [RACKUP_FILE]
13
13
  # DESCRIPTION
14
14
 
15
15
  A rackup(1)-like command to launch Rack applications using Unicorn.
16
- It is expected to be started in your application root (APP_ROOT), but
17
- "Dir.chdir" may also be executed in the CONFIG_FILE or RACKUP_FILE.
16
+ It is expected to be started in your application root (APP_ROOT),
17
+ but the "working_directory" directive may be used in the CONFIG_FILE.
18
18
 
19
19
  While Unicorn takes a myriad of command-line options for
20
20
  compatibility with ruby(1) and rackup(1), it is recommended to stick
@@ -33,10 +33,9 @@ with rackup(1) but strongly discouraged.
33
33
  # UNICORN OPTIONS
34
34
  -c, \--config-file CONFIG_FILE
35
35
  : Path to the Unicorn-specific config file. The config file is
36
- implemented as a Ruby DSL, so Ruby code may executed (e.g.
37
- "Dir.chdir", "Process::UID.change_privilege"). See the RDoc/ri
38
- for the *Unicorn::Configurator* class for the full list of
39
- directives available from the DSL.
36
+ implemented as a Ruby DSL, so Ruby code may executed.
37
+ See the RDoc/ri for the *Unicorn::Configurator* class for the full
38
+ list of directives available from the DSL.
40
39
 
41
40
  -D, \--daemonize
42
41
  : Run daemonized in the background. The process is detached from
@@ -14,8 +14,7 @@ unicorn_rails [-c CONFIG_FILE] [-E RAILS_ENV] [-D] [RACKUP_FILE]
14
14
 
15
15
  A rackup(1)-like command to launch Rails applications using Unicorn. It
16
16
  is expected to be started in your Rails application root (RAILS_ROOT),
17
- but "Dir.chdir" may also be executed in the CONFIG_FILE or
18
- optionally, RACKUP_FILE.
17
+ but the "working_directory" directive may be used in the CONFIG_FILE.
19
18
 
20
19
  The outward interface resembles rackup(1), the internals and default
21
20
  middleware loading is designed like the `script/server` command
@@ -29,10 +28,9 @@ as much as possible.
29
28
  # UNICORN OPTIONS
30
29
  -c, \--config-file CONFIG_FILE
31
30
  : Path to the Unicorn-specific config file. The config file is
32
- implemented as a Ruby DSL, so Ruby code may executed (e.g.
33
- "Dir.chdir", "Process::UID.change_privilege"). See the RDoc/ri
34
- for the *Unicorn::Configurator* class for the full list of
35
- directives available from the DSL.
31
+ implemented as a Ruby DSL, so Ruby code may executed.
32
+ See the RDoc/ri for the *Unicorn::Configurator* class for the
33
+ full list of directives available from the DSL.
36
34
 
37
35
  -D, \--daemonize
38
36
  : Run daemonized in the background. The process is detached from
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
 
3
3
  GVF=GIT-VERSION-FILE
4
- DEF_VER=v0.95.3.GIT
4
+ DEF_VER=v0.96.0.GIT
5
5
 
6
6
  LF='
7
7
  '
@@ -159,11 +159,11 @@ manifest: $(pkg_extra) man
159
159
  cmp $@+ $@ || mv $@+ $@
160
160
  $(RM) $@+
161
161
 
162
- NEWS: GIT-VERSION-FILE
162
+ NEWS: GIT-VERSION-FILE .manifest
163
163
  $(RAKE) -s news_rdoc > $@+
164
164
  mv $@+ $@
165
165
 
166
- SINCE = 0.94.0
166
+ SINCE = 0.95.0
167
167
  ChangeLog: LOG_VERSION = \
168
168
  $(shell git rev-parse -q "$(GIT_VERSION)" >/dev/null 2>&1 && \
169
169
  echo $(GIT_VERSION) || git describe)
@@ -1,4 +1,4 @@
1
- #!/home/ew/bin/ruby
1
+ #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2
2
  # -*- encoding: binary -*-
3
3
  require 'unicorn/launcher'
4
4
  require 'optparse'
@@ -161,5 +161,5 @@ if $DEBUG
161
161
  })
162
162
  end
163
163
 
164
- Unicorn::Launcher.daemonize! if daemonize
164
+ Unicorn::Launcher.daemonize!(options) if daemonize
165
165
  Unicorn.run(app, options)
@@ -1,4 +1,4 @@
1
- #!/home/ew/bin/ruby
1
+ #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2
2
  # -*- encoding: binary -*-
3
3
  require 'unicorn/launcher'
4
4
  require 'optparse'
@@ -202,6 +202,6 @@ end
202
202
 
203
203
  if daemonize
204
204
  options[:pid] = rails_pid
205
- Unicorn::Launcher.daemonize!
205
+ Unicorn::Launcher.daemonize!(options)
206
206
  end
207
207
  Unicorn.run(app, options)
@@ -38,7 +38,7 @@ module Unicorn
38
38
  :before_fork, :after_fork, :before_exec,
39
39
  :logger, :pid, :app, :preload_app,
40
40
  :reexec_pid, :orig_app, :init_listeners,
41
- :master_pid, :config)
41
+ :master_pid, :config, :ready_pipe)
42
42
  include ::Unicorn::SocketHelper
43
43
 
44
44
  # prevents IO objects in here from being GC-ed
@@ -162,6 +162,7 @@ module Unicorn
162
162
  def initialize(app, options = {})
163
163
  self.app = app
164
164
  self.reexec_pid = 0
165
+ self.ready_pipe = options.delete(:ready_pipe)
165
166
  self.init_listeners = options[:listeners] ? options[:listeners].dup : []
166
167
  self.config = Configurator.new(options.merge(:use_defaults => true))
167
168
  self.listener_opts = {}
@@ -249,6 +250,10 @@ module Unicorn
249
250
  def stdout_path=(path); redirect_io($stdout, path); end
250
251
  def stderr_path=(path); redirect_io($stderr, path); end
251
252
 
253
+ def logger=(obj)
254
+ HttpRequest::DEFAULTS["rack.logger"] = super
255
+ end
256
+
252
257
  # sets the path for the PID file of the master process
253
258
  def pid=(path)
254
259
  if path
@@ -306,6 +311,9 @@ module Unicorn
306
311
  "(#{tries < 0 ? 'infinite' : tries} tries left)"
307
312
  sleep(delay)
308
313
  retry
314
+ rescue => err
315
+ logger.fatal "error adding listener addr=#{address}"
316
+ raise err
309
317
  end
310
318
  end
311
319
 
@@ -324,6 +332,11 @@ module Unicorn
324
332
  trap(:CHLD) { |sig_nr| awaken_master }
325
333
  proc_name 'master'
326
334
  logger.info "master process ready" # test_exec.rb relies on this message
335
+ if ready_pipe
336
+ ready_pipe.syswrite($$.to_s)
337
+ ready_pipe.close rescue nil
338
+ self.ready_pipe = nil
339
+ end
327
340
  begin
328
341
  loop do
329
342
  reap_all_workers
@@ -528,7 +541,11 @@ module Unicorn
528
541
  WORKERS.values.include?(worker_nr) and next
529
542
  worker = Worker.new(worker_nr, Unicorn::Util.tmpio)
530
543
  before_fork.call(self, worker)
531
- WORKERS[fork { worker_loop(worker) }] = worker
544
+ WORKERS[fork {
545
+ ready_pipe.close if ready_pipe
546
+ self.ready_pipe = nil
547
+ worker_loop(worker)
548
+ }] = worker
532
549
  end
533
550
  end
534
551
 
@@ -7,7 +7,7 @@ module Unicorn
7
7
  # gave about a 3% to 10% performance improvement over using the strings directly.
8
8
  # Symbols did not really improve things much compared to constants.
9
9
  module Const
10
- UNICORN_VERSION="0.95.3"
10
+ UNICORN_VERSION="0.96.0"
11
11
 
12
12
  DEFAULT_HOST = "0.0.0.0" # default TCP listen host address
13
13
  DEFAULT_PORT = 8080 # default TCP listen port
@@ -12,7 +12,7 @@ module Unicorn
12
12
  "rack.multiprocess" => true,
13
13
  "rack.multithread" => false,
14
14
  "rack.run_once" => false,
15
- "rack.version" => [1, 0],
15
+ "rack.version" => [1, 1],
16
16
  "SCRIPT_NAME" => "",
17
17
 
18
18
  # this is not in the Rack spec, but some apps may rely on it
@@ -47,7 +47,8 @@ module Unicorn
47
47
  headers.each do |key, value|
48
48
  next if SKIP.include?(key.downcase)
49
49
  if value =~ /\n/
50
- out.concat(value.split(/\n/).map! { |v| "#{key}: #{v}\r\n" })
50
+ # avoiding blank, key-only cookies with /\n+/
51
+ out.concat(value.split(/\n+/).map! { |v| "#{key}: #{v}\r\n" })
51
52
  else
52
53
  out << "#{key}: #{value}\r\n"
53
54
  end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: binary -*-
2
2
 
3
- $stdin.sync = $stdout.sync = $stderr.sync = true
3
+ $stdout.sync = $stderr.sync = true
4
4
  $stdin.binmode
5
5
  $stdout.binmode
6
6
  $stderr.binmode
@@ -19,21 +19,47 @@ class Unicorn::Launcher
19
19
  # the directory it was started in when being re-executed
20
20
  # to pickup code changes if the original deployment directory
21
21
  # is a symlink or otherwise got replaced.
22
- def self.daemonize!
22
+ def self.daemonize!(options = nil)
23
23
  $stdin.reopen("/dev/null")
24
24
 
25
25
  # We only start a new process group if we're not being reexecuted
26
26
  # and inheriting file descriptors from our parent
27
27
  unless ENV['UNICORN_FD']
28
- exit if fork
29
- Process.setsid
30
- exit if fork
28
+ if options
29
+ # grandparent - reads pipe, exits when master is ready
30
+ # \_ parent - exits immediately ASAP
31
+ # \_ unicorn master - writes to pipe when ready
31
32
 
33
+ rd, wr = IO.pipe
34
+ grandparent = $$
35
+ if fork
36
+ wr.close # grandparent does not write
37
+ else
38
+ rd.close # unicorn master does not read
39
+ Process.setsid
40
+ exit if fork # parent dies now
41
+ end
42
+
43
+ if grandparent == $$
44
+ # this will block until HttpServer#join runs (or it dies)
45
+ master_pid = (rd.readpartial(16) rescue nil).to_i
46
+ unless master_pid > 1
47
+ warn "master failed to start, check stderr log for details"
48
+ exit!(1)
49
+ end
50
+ exit 0
51
+ else # unicorn master process
52
+ options[:ready_pipe] = wr
53
+ end
54
+ else # backwards compat
55
+ exit if fork
56
+ Process.setsid
57
+ exit if fork
58
+ end
32
59
  # $stderr/$stderr can/will be redirected separately in the Unicorn config
33
60
  Unicorn::Configurator::DEFAULTS[:stderr_path] = "/dev/null"
34
61
  Unicorn::Configurator::DEFAULTS[:stdout_path] = "/dev/null"
35
62
  end
36
- $stdin.sync = $stdout.sync = $stderr.sync = true
37
63
  end
38
64
 
39
65
  end
@@ -5,7 +5,7 @@
5
5
  # This is depends on a bunch of GNU-isms from bash, sed, touch.
6
6
 
7
7
  DLEXT := so
8
- gems := rack-1.0.1
8
+ gems := rack-1.1.0
9
9
 
10
10
  # Avoid loading rubygems to speed up tests because gmake is
11
11
  # fork+exec heavy with Ruby.
@@ -805,7 +805,7 @@ EOF
805
805
  exec($unicorn_bin, "-D", "-l#{@addr}:#{@port}", "-c#{ucfg.path}")
806
806
  end
807
807
  pid, status = Process.waitpid2(pid)
808
- assert status.success?, "original process exited successfully"
808
+ assert ! status.success?, "original process exited successfully"
809
809
  sleep 1 # can't waitpid on a daemonized process :<
810
810
  assert err.stat.size > 0
811
811
  end
@@ -228,6 +228,16 @@ class WebServerTest < Test::Unit::TestCase
228
228
  end
229
229
  end
230
230
 
231
+ def test_logger_set
232
+ assert_equal @server.logger, Unicorn::HttpRequest::DEFAULTS["rack.logger"]
233
+ end
234
+
235
+ def test_logger_changed
236
+ tmp = Logger.new($stdout)
237
+ @server.logger = tmp
238
+ assert_equal tmp, Unicorn::HttpRequest::DEFAULTS["rack.logger"]
239
+ end
240
+
231
241
  def test_bad_client_400
232
242
  sock = nil
233
243
  assert_nothing_raised do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unicorn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.95.3
4
+ version: 0.96.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unicorn hackers
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-21 00:00:00 +00:00
12
+ date: 2010-01-08 00:00:00 +00:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -191,22 +191,22 @@ files:
191
191
  - test/rails/app-2.2.2/log/.gitignore
192
192
  - test/rails/app-2.2.2/public/404.html
193
193
  - test/rails/app-2.2.2/public/500.html
194
- - test/rails/app-2.3.3.1/.gitignore
195
- - test/rails/app-2.3.3.1/Rakefile
196
- - test/rails/app-2.3.3.1/app/controllers/application_controller.rb
197
- - test/rails/app-2.3.3.1/app/controllers/foo_controller.rb
198
- - test/rails/app-2.3.3.1/app/helpers/application_helper.rb
199
- - test/rails/app-2.3.3.1/config/boot.rb
200
- - test/rails/app-2.3.3.1/config/database.yml
201
- - test/rails/app-2.3.3.1/config/environment.rb
202
- - test/rails/app-2.3.3.1/config/environments/development.rb
203
- - test/rails/app-2.3.3.1/config/environments/production.rb
204
- - test/rails/app-2.3.3.1/config/routes.rb
205
- - test/rails/app-2.3.3.1/db/.gitignore
206
- - test/rails/app-2.3.3.1/log/.gitignore
207
- - test/rails/app-2.3.3.1/public/404.html
208
- - test/rails/app-2.3.3.1/public/500.html
209
- - test/rails/app-2.3.3.1/public/x.txt
194
+ - test/rails/app-2.3.5/.gitignore
195
+ - test/rails/app-2.3.5/Rakefile
196
+ - test/rails/app-2.3.5/app/controllers/application_controller.rb
197
+ - test/rails/app-2.3.5/app/controllers/foo_controller.rb
198
+ - test/rails/app-2.3.5/app/helpers/application_helper.rb
199
+ - test/rails/app-2.3.5/config/boot.rb
200
+ - test/rails/app-2.3.5/config/database.yml
201
+ - test/rails/app-2.3.5/config/environment.rb
202
+ - test/rails/app-2.3.5/config/environments/development.rb
203
+ - test/rails/app-2.3.5/config/environments/production.rb
204
+ - test/rails/app-2.3.5/config/routes.rb
205
+ - test/rails/app-2.3.5/db/.gitignore
206
+ - test/rails/app-2.3.5/log/.gitignore
207
+ - test/rails/app-2.3.5/public/404.html
208
+ - test/rails/app-2.3.5/public/500.html
209
+ - test/rails/app-2.3.5/public/x.txt
210
210
  - test/rails/test_rails.rb
211
211
  - test/test_helper.rb
212
212
  - test/unit/test_configurator.rb