unicorn 4.9.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +5 -5
  2. data/.gitattributes +5 -0
  3. data/.olddoc.yml +13 -6
  4. data/Application_Timeouts +7 -7
  5. data/DESIGN +2 -4
  6. data/Documentation/.gitignore +1 -3
  7. data/Documentation/unicorn.1 +222 -0
  8. data/Documentation/unicorn_rails.1 +207 -0
  9. data/FAQ +17 -8
  10. data/GIT-VERSION-GEN +1 -1
  11. data/GNUmakefile +121 -56
  12. data/HACKING +1 -2
  13. data/ISSUES +40 -41
  14. data/KNOWN_ISSUES +11 -11
  15. data/LICENSE +2 -2
  16. data/Links +24 -25
  17. data/PHILOSOPHY +0 -6
  18. data/README +46 -39
  19. data/SIGNALS +2 -2
  20. data/Sandbox +10 -9
  21. data/TODO +0 -2
  22. data/TUNING +30 -9
  23. data/archive/slrnpull.conf +1 -1
  24. data/bin/unicorn +4 -2
  25. data/bin/unicorn_rails +3 -3
  26. data/examples/big_app_gc.rb +1 -1
  27. data/examples/init.sh +36 -8
  28. data/examples/logrotate.conf +17 -2
  29. data/examples/nginx.conf +14 -14
  30. data/examples/unicorn.conf.minimal.rb +2 -2
  31. data/examples/unicorn.conf.rb +3 -6
  32. data/examples/unicorn.socket +11 -0
  33. data/examples/unicorn@.service +40 -0
  34. data/ext/unicorn_http/common_field_optimization.h +23 -5
  35. data/ext/unicorn_http/ext_help.h +0 -20
  36. data/ext/unicorn_http/extconf.rb +37 -1
  37. data/ext/unicorn_http/global_variables.h +1 -1
  38. data/ext/unicorn_http/httpdate.c +2 -2
  39. data/ext/unicorn_http/unicorn_http.rl +167 -170
  40. data/ext/unicorn_http/unicorn_http_common.rl +1 -1
  41. data/lib/unicorn.rb +66 -46
  42. data/lib/unicorn/configurator.rb +110 -44
  43. data/lib/unicorn/const.rb +2 -25
  44. data/lib/unicorn/http_request.rb +110 -31
  45. data/lib/unicorn/http_response.rb +17 -31
  46. data/lib/unicorn/http_server.rb +238 -157
  47. data/lib/unicorn/launcher.rb +1 -1
  48. data/lib/unicorn/oob_gc.rb +6 -6
  49. data/lib/unicorn/socket_helper.rb +58 -78
  50. data/lib/unicorn/stream_input.rb +8 -7
  51. data/lib/unicorn/tee_input.rb +8 -10
  52. data/lib/unicorn/tmpio.rb +8 -7
  53. data/lib/unicorn/util.rb +5 -4
  54. data/lib/unicorn/worker.rb +36 -23
  55. data/t/GNUmakefile +3 -72
  56. data/t/README +4 -4
  57. data/t/t0011-active-unix-socket.sh +1 -1
  58. data/t/t0012-reload-empty-config.sh +2 -1
  59. data/t/t0301-no-default-middleware-ignored-in-config.sh +25 -0
  60. data/t/t0301.ru +13 -0
  61. data/t/test-lib.sh +2 -2
  62. data/test/benchmark/README +14 -4
  63. data/test/benchmark/ddstream.ru +50 -0
  64. data/test/benchmark/readinput.ru +40 -0
  65. data/test/benchmark/uconnect.perl +66 -0
  66. data/test/exec/test_exec.rb +73 -19
  67. data/test/test_helper.rb +40 -31
  68. data/test/unit/test_ccc.rb +91 -0
  69. data/test/unit/test_droplet.rb +1 -1
  70. data/test/unit/test_http_parser.rb +46 -16
  71. data/test/unit/test_http_parser_ng.rb +97 -114
  72. data/test/unit/test_request.rb +10 -10
  73. data/test/unit/test_response.rb +28 -16
  74. data/test/unit/test_server.rb +86 -12
  75. data/test/unit/test_signals.rb +8 -8
  76. data/test/unit/test_socket_helper.rb +14 -10
  77. data/test/unit/test_upload.rb +9 -14
  78. data/test/unit/test_util.rb +27 -2
  79. data/unicorn.gemspec +27 -19
  80. metadata +24 -45
  81. data/Documentation/GNUmakefile +0 -30
  82. data/Documentation/unicorn.1.txt +0 -185
  83. data/Documentation/unicorn_rails.1.txt +0 -175
  84. data/examples/git.ru +0 -13
  85. data/lib/unicorn/app/exec_cgi.rb +0 -154
  86. data/lib/unicorn/app/inetd.rb +0 -109
  87. data/lib/unicorn/ssl_client.rb +0 -11
  88. data/lib/unicorn/ssl_configurator.rb +0 -104
  89. data/lib/unicorn/ssl_server.rb +0 -42
  90. data/t/hijack.ru +0 -42
  91. data/t/t0016-trust-x-forwarded-false.sh +0 -30
  92. data/t/t0017-trust-x-forwarded-true.sh +0 -30
  93. data/t/t0200-rack-hijack.sh +0 -27
  94. data/test/unit/test_http_parser_xftrust.rb +0 -38
  95. data/test/unit/test_sni_hostnames.rb +0 -47
@@ -1,175 +0,0 @@
1
- % UNICORN_RAILS(1) Unicorn User Manual
2
- % The Unicorn Community <unicorn-public@bogomips.org>
3
- % September 17, 2009
4
-
5
- # NAME
6
-
7
- unicorn_rails - a script/server-like command to launch the Unicorn HTTP server
8
-
9
- # SYNOPSIS
10
-
11
- unicorn_rails [-c CONFIG_FILE] [-E RAILS_ENV] [-D] [RACKUP_FILE]
12
-
13
- # DESCRIPTION
14
-
15
- A rackup(1)-like command to launch Rails applications using Unicorn. It
16
- is expected to be started in your Rails application root (RAILS_ROOT),
17
- but the "working_directory" directive may be used in the CONFIG_FILE.
18
-
19
- It is designed to help Rails 1.x and 2.y users transition to Rack, but
20
- it is NOT needed for Rails 3 applications. Rails 3 users are encouraged
21
- to use unicorn(1) instead of unicorn_rails(1). Users of Rails 1.x/2.y
22
- may also use unicorn(1) instead of unicorn_rails(1).
23
-
24
- The outward interface resembles rackup(1), the internals and default
25
- middleware loading is designed like the `script/server` command
26
- distributed with Rails.
27
-
28
- While Unicorn takes a myriad of command-line options for compatibility
29
- with ruby(1) and rackup(1), it is recommended to stick to the few
30
- command-line options specified in the SYNOPSIS and use the CONFIG_FILE
31
- as much as possible.
32
-
33
- # UNICORN OPTIONS
34
- -c, \--config-file CONFIG_FILE
35
- : Path to the Unicorn-specific config file. The config file is
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.
39
- Using an absolute path for for CONFIG_FILE is recommended as it
40
- makes multiple instances of Unicorn easily distinguishable when
41
- viewing ps(1) output.
42
-
43
- -D, \--daemonize
44
- : Run daemonized in the background. The process is detached from
45
- the controlling terminal and stdin is redirected to "/dev/null".
46
- Unlike many common UNIX daemons, we do not chdir to \"/\"
47
- upon daemonization to allow more control over the startup/upgrade
48
- process.
49
- Unless specified in the CONFIG_FILE, stderr and stdout will
50
- also be redirected to "/dev/null".
51
- Daemonization will _skip_ loading of the *Rails::Rack::LogTailer*
52
- middleware under Rails \>\= 2.3.x.
53
- By default, unicorn\_rails(1) will create a PID file in
54
- _\"RAILS\_ROOT/tmp/pids/unicorn.pid\"_. You may override this
55
- by specifying the "pid" directive to override this Unicorn config file.
56
-
57
- -E, \--env RAILS_ENV
58
- : Run under the given RAILS_ENV. This sets the RAILS_ENV environment
59
- variable. Acceptable values are exactly those you expect in your Rails
60
- application, typically "development" or "production".
61
-
62
- -l, \--listen ADDRESS
63
- : Listens on a given ADDRESS. ADDRESS may be in the form of
64
- HOST:PORT or PATH, HOST:PORT is taken to mean a TCP socket
65
- and PATH is meant to be a path to a UNIX domain socket.
66
- Defaults to "0.0.0.0:8080" (all addresses on TCP port 8080).
67
- For production deployments, specifying the "listen" directive in
68
- CONFIG_FILE is recommended as it allows fine-tuning of socket
69
- options.
70
-
71
- # RACKUP COMPATIBILITY OPTIONS
72
- -o, \--host HOST
73
- : Listen on a TCP socket belonging to HOST, default is
74
- "0.0.0.0" (all addresses).
75
- If specified multiple times on the command-line, only the
76
- last-specified value takes effect.
77
- This option only exists for compatibility with the rackup(1) command,
78
- use of "-l"/"\--listen" switch is recommended instead.
79
-
80
- -p, \--port PORT
81
- : Listen on the specified TCP PORT, default is 8080.
82
- If specified multiple times on the command-line, only the last-specified
83
- value takes effect.
84
- This option only exists for compatibility with the rackup(1) command,
85
- use of "-l"/"\--listen" switch is recommended instead.
86
-
87
- \--path PATH
88
- : Mounts the Rails application at the given PATH (instead of "/").
89
- This is equivalent to setting the RAILS_RELATIVE_URL_ROOT
90
- environment variable. This is only supported under Rails 2.3
91
- or later at the moment.
92
-
93
- # RUBY OPTIONS
94
- -e, \--eval LINE
95
- : Evaluate a LINE of Ruby code. This evaluation happens
96
- immediately as the command-line is being parsed.
97
-
98
- -d, \--debug
99
- : Turn on debug mode, the $DEBUG variable is set to true.
100
- For Rails \>\= 2.3.x, this loads the *Rails::Rack::Debugger*
101
- middleware.
102
-
103
- -w, \--warn
104
- : Turn on verbose warnings, the $VERBOSE variable is set to true.
105
-
106
- -I, \--include PATH
107
- : specify $LOAD_PATH. PATH will be prepended to $LOAD_PATH.
108
- The \':\' character may be used to delimit multiple directories.
109
- This directive may be used more than once. Modifications to
110
- $LOAD_PATH take place immediately and in the order they were
111
- specified on the command-line.
112
-
113
- -r, \--require LIBRARY
114
- : require a specified LIBRARY before executing the application. The
115
- \"require\" statement will be executed immediately and in the order
116
- they were specified on the command-line.
117
-
118
- # RACKUP FILE
119
-
120
- This defaults to \"config.ru\" in RAILS_ROOT. It should be the same
121
- file used by rackup(1) and other Rack launchers, it uses the
122
- *Rack::Builder* DSL. Unlike many other Rack applications, RACKUP_FILE
123
- is completely _optional_ for Rails, but may be used to disable some
124
- of the default middleware for performance.
125
-
126
- Embedded command-line options are mostly parsed for compatibility
127
- with rackup(1) but strongly discouraged.
128
-
129
- # ENVIRONMENT VARIABLES
130
-
131
- The RAILS_ENV variable is set by the aforementioned \-E switch. The
132
- RAILS_RELATIVE_URL_ROOT is set by the aforementioned \--path switch.
133
- Either of these variables may also be set in the shell or the Unicorn
134
- CONFIG_FILE. All application or library-specific environment variables
135
- (e.g. TMPDIR, RAILS_ASSET_ID) may always be set in the Unicorn
136
- CONFIG_FILE in addition to the spawning shell. When transparently
137
- upgrading Unicorn, all environment variables set in the old master
138
- process are inherited by the new master process. Unicorn only uses (and
139
- will overwrite) the UNICORN_FD environment variable internally when
140
- doing transparent upgrades.
141
-
142
- # SIGNALS
143
-
144
- The following UNIX signals may be sent to the master process:
145
-
146
- * HUP - reload config file, app, and gracefully restart all workers
147
- * INT/TERM - quick shutdown, kills all workers immediately
148
- * QUIT - graceful shutdown, waits for workers to finish their
149
- current request before finishing.
150
- * USR1 - reopen all logs owned by the master and all workers
151
- See Unicorn::Util.reopen_logs for what is considered a log.
152
- * USR2 - reexecute the running binary. A separate QUIT
153
- should be sent to the original process once the child is verified to
154
- be up and running.
155
- * WINCH - gracefully stops workers but keep the master running.
156
- This will only work for daemonized processes.
157
- * TTIN - increment the number of worker processes by one
158
- * TTOU - decrement the number of worker processes by one
159
-
160
- See the [SIGNALS][4] document for full description of all signals
161
- used by Unicorn.
162
-
163
- # SEE ALSO
164
-
165
- * unicorn(1)
166
- * *Rack::Builder* ri/RDoc
167
- * *Unicorn::Configurator* ri/RDoc
168
- * [Unicorn RDoc][1]
169
- * [Rack RDoc][2]
170
- * [Rackup HowTo][3]
171
-
172
- [1]: http://unicorn.bogomips.org/
173
- [2]: http://rdoc.info/gems/r#/gems/rack/frames
174
- [3]: http://wiki.github.com/rack/rack/tutorial-rackup-howto
175
- [4]: http://unicorn.bogomips.org/SIGNALS.html
data/examples/git.ru DELETED
@@ -1,13 +0,0 @@
1
- #\-E none
2
-
3
- # See http://thread.gmane.org/gmane.comp.web.curl.general/10473/raw on
4
- # how to setup git for this. A better version of the above patch was
5
- # accepted and committed on June 15, 2009, so you can pull the latest
6
- # curl CVS snapshot to try this out.
7
- require 'unicorn/app/inetd'
8
-
9
- use Rack::Lint
10
- use Rack::Chunked # important!
11
- run Unicorn::App::Inetd.new(
12
- *%w(git daemon --verbose --inetd --export-all --base-path=/home/ew/unicorn)
13
- )
@@ -1,154 +0,0 @@
1
- # -*- encoding: binary -*-
2
- # :enddoc:
3
- require 'unicorn'
4
-
5
- module Unicorn::App
6
-
7
- # This class is highly experimental (even more so than the rest of Unicorn)
8
- # and has never run anything other than cgit.
9
- class ExecCgi < Struct.new(:args)
10
-
11
- CHUNK_SIZE = 16384
12
- PASS_VARS = %w(
13
- CONTENT_LENGTH
14
- CONTENT_TYPE
15
- GATEWAY_INTERFACE
16
- AUTH_TYPE
17
- PATH_INFO
18
- PATH_TRANSLATED
19
- QUERY_STRING
20
- REMOTE_ADDR
21
- REMOTE_HOST
22
- REMOTE_IDENT
23
- REMOTE_USER
24
- REQUEST_METHOD
25
- SERVER_NAME
26
- SERVER_PORT
27
- SERVER_PROTOCOL
28
- SERVER_SOFTWARE
29
- ).map { |x| x.freeze } # frozen strings are faster for Hash assignments
30
-
31
- class Body < Unicorn::TmpIO
32
- def body_offset=(n)
33
- sysseek(@body_offset = n)
34
- end
35
-
36
- def each
37
- sysseek @body_offset
38
- # don't use a preallocated buffer for sysread since we can't
39
- # guarantee an actual socket is consuming the yielded string
40
- # (or if somebody is pushing to an array for eventual concatenation
41
- begin
42
- yield sysread(CHUNK_SIZE)
43
- rescue EOFError
44
- break
45
- end while true
46
- end
47
- end
48
-
49
- # Intializes the app, example of usage in a config.ru
50
- # map "/cgit" do
51
- # run Unicorn::App::ExecCgi.new("/path/to/cgit.cgi")
52
- # end
53
- def initialize(*args)
54
- self.args = args
55
- first = args[0] or
56
- raise ArgumentError, "need path to executable"
57
- first[0] == ?/ or args[0] = ::File.expand_path(first)
58
- File.executable?(args[0]) or
59
- raise ArgumentError, "#{args[0]} is not executable"
60
- end
61
-
62
- # Calls the app
63
- def call(env)
64
- out, err = Body.new, Unicorn::TmpIO.new
65
- inp = force_file_input(env)
66
- pid = fork { run_child(inp, out, err, env) }
67
- inp.close
68
- pid, status = Process.waitpid2(pid)
69
- write_errors(env, err, status) if err.stat.size > 0
70
- err.close
71
-
72
- return parse_output!(out) if status.success?
73
- out.close
74
- [ 500, { 'Content-Length' => '0', 'Content-Type' => 'text/plain' }, [] ]
75
- end
76
-
77
- private
78
-
79
- def run_child(inp, out, err, env)
80
- PASS_VARS.each do |key|
81
- val = env[key] or next
82
- ENV[key] = val
83
- end
84
- ENV['SCRIPT_NAME'] = args[0]
85
- ENV['GATEWAY_INTERFACE'] = 'CGI/1.1'
86
- env.keys.grep(/^HTTP_/) { |key| ENV[key] = env[key] }
87
-
88
- $stdin.reopen(inp)
89
- $stdout.reopen(out)
90
- $stderr.reopen(err)
91
- exec(*args)
92
- end
93
-
94
- # Extracts headers from CGI out, will change the offset of out.
95
- # This returns a standard Rack-compatible return value:
96
- # [ 200, HeadersHash, body ]
97
- def parse_output!(out)
98
- size = out.stat.size
99
- out.sysseek(0)
100
- head = out.sysread(CHUNK_SIZE)
101
- offset = 2
102
- head, body = head.split(/\n\n/, 2)
103
- if body.nil?
104
- head, body = head.split(/\r\n\r\n/, 2)
105
- offset = 4
106
- end
107
- offset += head.length
108
- out.body_offset = offset
109
- size -= offset
110
- prev = nil
111
- headers = Rack::Utils::HeaderHash.new
112
- head.split(/\r?\n/).each do |line|
113
- case line
114
- when /^([A-Za-z0-9-]+):\s*(.*)$/ then headers[prev = $1] = $2
115
- when /^[ \t]/ then headers[prev] << "\n#{line}" if prev
116
- end
117
- end
118
- status = headers.delete("Status") || 200
119
- headers['Content-Length'] = size.to_s
120
- [ status, headers, out ]
121
- end
122
-
123
- # ensures rack.input is a file handle that we can redirect stdin to
124
- def force_file_input(env)
125
- inp = env['rack.input']
126
- # inp could be a StringIO or StringIO-like object
127
- if inp.respond_to?(:size) && inp.size == 0
128
- ::File.open('/dev/null', 'rb')
129
- else
130
- tmp = Unicorn::TmpIO.new
131
-
132
- buf = inp.read(CHUNK_SIZE)
133
- begin
134
- tmp.syswrite(buf)
135
- end while inp.read(CHUNK_SIZE, buf)
136
- tmp.sysseek(0)
137
- tmp
138
- end
139
- end
140
-
141
- # rack.errors this may not be an IO object, so we couldn't
142
- # just redirect the CGI executable to that earlier.
143
- def write_errors(env, err, status)
144
- err.seek(0)
145
- dst = env['rack.errors']
146
- pid = status.pid
147
- dst.write("#{pid}: #{args.inspect} status=#{status} stderr:\n")
148
- err.each_line { |line| dst.write("#{pid}: #{line}") }
149
- dst.flush
150
- end
151
-
152
- end
153
-
154
- end
@@ -1,109 +0,0 @@
1
- # -*- encoding: binary -*-
2
- # :enddoc:
3
- # Copyright (c) 2009 Eric Wong
4
- # You can redistribute it and/or modify it under the same terms as Ruby 1.8 or
5
- # the GPLv2+ (GPLv3+ preferred)
6
-
7
- # this class *must* be used with Rack::Chunked
8
- module Unicorn::App
9
- class Inetd < Struct.new(:cmd)
10
-
11
- class CatBody < Struct.new(:errors, :err_rd, :out_rd, :pid_map)
12
- def initialize(env, cmd)
13
- self.errors = env['rack.errors']
14
- in_rd, in_wr = IO.pipe
15
- self.err_rd, err_wr = IO.pipe
16
- self.out_rd, out_wr = IO.pipe
17
-
18
- cmd_pid = fork {
19
- inp, out, err = (0..2).map { |i| IO.new(i) }
20
- inp.reopen(in_rd)
21
- out.reopen(out_wr)
22
- err.reopen(err_wr)
23
- [ in_rd, in_wr, err_rd, err_wr, out_rd, out_wr ].each { |i| i.close }
24
- exec(*cmd)
25
- }
26
- [ in_rd, err_wr, out_wr ].each { |io| io.close }
27
- [ in_wr, err_rd, out_rd ].each { |io| io.binmode }
28
- in_wr.sync = true
29
-
30
- # Unfortunately, input here must be processed inside a seperate
31
- # thread/process using blocking I/O since env['rack.input'] is not
32
- # IO.select-able and attempting to make it so would trip Rack::Lint
33
- inp_pid = fork {
34
- input = env['rack.input']
35
- [ err_rd, out_rd ].each { |io| io.close }
36
-
37
- # this is dependent on input.read having readpartial semantics:
38
- buf = input.read(16384)
39
- begin
40
- in_wr.write(buf)
41
- end while input.read(16384, buf)
42
- }
43
- in_wr.close
44
- self.pid_map = {
45
- inp_pid => 'input streamer',
46
- cmd_pid => cmd.inspect,
47
- }
48
- end
49
-
50
- def each
51
- begin
52
- rd, = IO.select([err_rd, out_rd])
53
- rd && rd.first or next
54
-
55
- if rd.include?(err_rd)
56
- begin
57
- errors.write(err_rd.read_nonblock(16384))
58
- rescue Errno::EINTR
59
- rescue Errno::EAGAIN
60
- break
61
- end while true
62
- end
63
-
64
- rd.include?(out_rd) or next
65
-
66
- begin
67
- yield out_rd.read_nonblock(16384)
68
- rescue Errno::EINTR
69
- rescue Errno::EAGAIN
70
- break
71
- end while true
72
- rescue EOFError,Errno::EPIPE,Errno::EBADF,Errno::EINVAL
73
- break
74
- end while true
75
-
76
- self
77
- end
78
-
79
- def close
80
- pid_map.each { |pid, str|
81
- begin
82
- pid, status = Process.waitpid2(pid)
83
- status.success? or
84
- errors.write("#{str}: #{status.inspect} (PID:#{pid})\n")
85
- rescue Errno::ECHILD
86
- errors.write("Failed to reap #{str} (PID:#{pid})\n")
87
- end
88
- }
89
- out_rd.close
90
- err_rd.close
91
- end
92
-
93
- end
94
-
95
- def initialize(*cmd)
96
- self.cmd = cmd
97
- end
98
-
99
- def call(env)
100
- /\A100-continue\z/i =~ env[Unicorn::Const::HTTP_EXPECT] and
101
- return [ 100, {} , [] ]
102
-
103
- [ 200, { 'Content-Type' => 'application/octet-stream' },
104
- CatBody.new(env, cmd) ]
105
- end
106
-
107
- end
108
-
109
- end