unicorn-simon 0.0.1

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 (158) hide show
  1. checksums.yaml +7 -0
  2. data/.CHANGELOG.old +25 -0
  3. data/.document +28 -0
  4. data/.gitattributes +5 -0
  5. data/.gitignore +25 -0
  6. data/.mailmap +26 -0
  7. data/.manifest +156 -0
  8. data/.olddoc.yml +18 -0
  9. data/Application_Timeouts +77 -0
  10. data/CONTRIBUTORS +35 -0
  11. data/COPYING +674 -0
  12. data/DESIGN +95 -0
  13. data/Documentation/.gitignore +5 -0
  14. data/Documentation/GNUmakefile +30 -0
  15. data/Documentation/unicorn.1.txt +187 -0
  16. data/Documentation/unicorn_rails.1.txt +175 -0
  17. data/FAQ +70 -0
  18. data/GIT-VERSION-FILE +1 -0
  19. data/GIT-VERSION-GEN +39 -0
  20. data/GNUmakefile +253 -0
  21. data/HACKING +120 -0
  22. data/ISSUES +90 -0
  23. data/KNOWN_ISSUES +79 -0
  24. data/LATEST +30 -0
  25. data/LICENSE +67 -0
  26. data/Links +56 -0
  27. data/NEWS +2465 -0
  28. data/PHILOSOPHY +139 -0
  29. data/README +138 -0
  30. data/Rakefile +16 -0
  31. data/SIGNALS +123 -0
  32. data/Sandbox +104 -0
  33. data/TODO +3 -0
  34. data/TUNING +119 -0
  35. data/archive/.gitignore +3 -0
  36. data/archive/slrnpull.conf +4 -0
  37. data/bin/unicorn +126 -0
  38. data/bin/unicorn_rails +209 -0
  39. data/examples/big_app_gc.rb +2 -0
  40. data/examples/echo.ru +27 -0
  41. data/examples/init.sh +102 -0
  42. data/examples/logger_mp_safe.rb +25 -0
  43. data/examples/logrotate.conf +44 -0
  44. data/examples/nginx.conf +155 -0
  45. data/examples/unicorn.conf.minimal.rb +13 -0
  46. data/examples/unicorn.conf.rb +110 -0
  47. data/examples/unicorn.socket +11 -0
  48. data/examples/unicorn@.service +33 -0
  49. data/ext/unicorn_http/CFLAGS +13 -0
  50. data/ext/unicorn_http/c_util.h +124 -0
  51. data/ext/unicorn_http/common_field_optimization.h +111 -0
  52. data/ext/unicorn_http/ext_help.h +62 -0
  53. data/ext/unicorn_http/extconf.rb +11 -0
  54. data/ext/unicorn_http/global_variables.h +97 -0
  55. data/ext/unicorn_http/httpdate.c +78 -0
  56. data/ext/unicorn_http/unicorn_http.c +4274 -0
  57. data/ext/unicorn_http/unicorn_http.rl +980 -0
  58. data/ext/unicorn_http/unicorn_http_common.rl +76 -0
  59. data/lib/unicorn/app/old_rails/static.rb +59 -0
  60. data/lib/unicorn/app/old_rails.rb +35 -0
  61. data/lib/unicorn/cgi_wrapper.rb +147 -0
  62. data/lib/unicorn/configurator.rb +664 -0
  63. data/lib/unicorn/const.rb +21 -0
  64. data/lib/unicorn/http_request.rb +122 -0
  65. data/lib/unicorn/http_response.rb +60 -0
  66. data/lib/unicorn/http_server.rb +824 -0
  67. data/lib/unicorn/launcher.rb +62 -0
  68. data/lib/unicorn/oob_gc.rb +82 -0
  69. data/lib/unicorn/preread_input.rb +33 -0
  70. data/lib/unicorn/socket_helper.rb +195 -0
  71. data/lib/unicorn/stream_input.rb +146 -0
  72. data/lib/unicorn/tee_input.rb +133 -0
  73. data/lib/unicorn/tmpio.rb +27 -0
  74. data/lib/unicorn/util.rb +90 -0
  75. data/lib/unicorn/version.rb +1 -0
  76. data/lib/unicorn/worker.rb +140 -0
  77. data/lib/unicorn.rb +123 -0
  78. data/man/man1/unicorn.1 +221 -0
  79. data/man/man1/unicorn_rails.1 +212 -0
  80. data/setup.rb +1586 -0
  81. data/t/.gitignore +4 -0
  82. data/t/GNUmakefile +74 -0
  83. data/t/README +42 -0
  84. data/t/bin/content-md5-put +36 -0
  85. data/t/bin/sha1sum.rb +17 -0
  86. data/t/bin/unused_listen +40 -0
  87. data/t/broken-app.ru +12 -0
  88. data/t/detach.ru +11 -0
  89. data/t/env.ru +3 -0
  90. data/t/fails-rack-lint.ru +5 -0
  91. data/t/heartbeat-timeout.ru +12 -0
  92. data/t/hijack.ru +43 -0
  93. data/t/listener_names.ru +4 -0
  94. data/t/my-tap-lib.sh +201 -0
  95. data/t/oob_gc.ru +20 -0
  96. data/t/oob_gc_path.ru +20 -0
  97. data/t/pid.ru +3 -0
  98. data/t/preread_input.ru +17 -0
  99. data/t/rack-input-tests.ru +21 -0
  100. data/t/t0000-http-basic.sh +50 -0
  101. data/t/t0001-reload-bad-config.sh +53 -0
  102. data/t/t0002-config-conflict.sh +49 -0
  103. data/t/t0002-parser-error.sh +94 -0
  104. data/t/t0003-working_directory.sh +51 -0
  105. data/t/t0004-heartbeat-timeout.sh +69 -0
  106. data/t/t0004-working_directory_broken.sh +24 -0
  107. data/t/t0005-working_directory_app.rb.sh +40 -0
  108. data/t/t0006-reopen-logs.sh +83 -0
  109. data/t/t0006.ru +13 -0
  110. data/t/t0007-working_directory_no_embed_cli.sh +44 -0
  111. data/t/t0008-back_out_of_upgrade.sh +110 -0
  112. data/t/t0009-broken-app.sh +56 -0
  113. data/t/t0009-winch_ttin.sh +59 -0
  114. data/t/t0010-reap-logging.sh +55 -0
  115. data/t/t0011-active-unix-socket.sh +79 -0
  116. data/t/t0012-reload-empty-config.sh +85 -0
  117. data/t/t0013-rewindable-input-false.sh +24 -0
  118. data/t/t0013.ru +12 -0
  119. data/t/t0014-rewindable-input-true.sh +24 -0
  120. data/t/t0014.ru +12 -0
  121. data/t/t0015-configurator-internals.sh +25 -0
  122. data/t/t0018-write-on-close.sh +23 -0
  123. data/t/t0019-max_header_len.sh +49 -0
  124. data/t/t0020-at_exit-handler.sh +49 -0
  125. data/t/t0021-process_detach.sh +29 -0
  126. data/t/t0022-listener_names-preload_app.sh +32 -0
  127. data/t/t0100-rack-input-tests.sh +124 -0
  128. data/t/t0116-client_body_buffer_size.sh +80 -0
  129. data/t/t0116.ru +16 -0
  130. data/t/t0200-rack-hijack.sh +30 -0
  131. data/t/t0300-no-default-middleware.sh +20 -0
  132. data/t/t9000-preread-input.sh +48 -0
  133. data/t/t9001-oob_gc.sh +47 -0
  134. data/t/t9002-oob_gc-path.sh +75 -0
  135. data/t/test-lib.sh +128 -0
  136. data/t/write-on-close.ru +11 -0
  137. data/test/aggregate.rb +15 -0
  138. data/test/benchmark/README +50 -0
  139. data/test/benchmark/dd.ru +18 -0
  140. data/test/benchmark/stack.ru +8 -0
  141. data/test/exec/README +5 -0
  142. data/test/exec/test_exec.rb +1099 -0
  143. data/test/test_helper.rb +298 -0
  144. data/test/unit/test_configurator.rb +175 -0
  145. data/test/unit/test_droplet.rb +28 -0
  146. data/test/unit/test_http_parser.rb +886 -0
  147. data/test/unit/test_http_parser_ng.rb +633 -0
  148. data/test/unit/test_request.rb +182 -0
  149. data/test/unit/test_response.rb +111 -0
  150. data/test/unit/test_server.rb +268 -0
  151. data/test/unit/test_signals.rb +188 -0
  152. data/test/unit/test_socket_helper.rb +197 -0
  153. data/test/unit/test_stream_input.rb +203 -0
  154. data/test/unit/test_tee_input.rb +304 -0
  155. data/test/unit/test_upload.rb +306 -0
  156. data/test/unit/test_util.rb +105 -0
  157. data/unicorn.gemspec +50 -0
  158. metadata +310 -0
data/DESIGN ADDED
@@ -0,0 +1,95 @@
1
+ == Design
2
+
3
+ * Simplicity: Unicorn is a traditional UNIX prefork web server.
4
+ No threads are used at all, this makes applications easier to debug
5
+ and fix. When your application goes awry, a BOFH can just
6
+ "kill -9" the runaway worker process without worrying about tearing
7
+ all clients down, just one. Only UNIX-like systems supporting
8
+ fork() and file descriptor inheritance are supported.
9
+
10
+ * The Ragel+C HTTP parser is taken from Mongrel.
11
+
12
+ * All HTTP parsing and I/O is done much like Mongrel:
13
+ 1. read/parse HTTP request headers in full
14
+ 2. call Rack application
15
+ 3. write HTTP response back to the client
16
+
17
+ * Like Mongrel, neither keepalive nor pipelining are supported.
18
+ These aren't needed since Unicorn is only designed to serve
19
+ fast, low-latency clients directly. Do one thing, do it well;
20
+ let nginx handle slow clients.
21
+
22
+ * Configuration is purely in Ruby and eval(). Ruby is less
23
+ ambiguous than YAML and lets lambdas for
24
+ before_fork/after_fork/before_exec hooks be defined inline. An
25
+ optional, separate config_file may be used to modify supported
26
+ configuration changes (and also gives you plenty of rope if you RTFS
27
+ :>)
28
+
29
+ * One master process spawns and reaps worker processes. The
30
+ Rack application itself is called only within the worker process (but
31
+ can be loaded within the master). A copy-on-write friendly garbage
32
+ collector like the one found in mainline Ruby 2.0.0 and later
33
+ can be used to minimize memory usage along with the "preload_app true"
34
+ directive (see Unicorn::Configurator).
35
+
36
+ * The number of worker processes should be scaled to the number of
37
+ CPUs, memory or even spindles you have. If you have an existing
38
+ Mongrel cluster on a single-threaded app, using the same amount of
39
+ processes should work. Let a full-HTTP-request-buffering reverse
40
+ proxy like nginx manage concurrency to thousands of slow clients for
41
+ you. Unicorn scaling should only be concerned about limits of your
42
+ backend system(s).
43
+
44
+ * Load balancing between worker processes is done by the OS kernel.
45
+ All workers share a common set of listener sockets and does
46
+ non-blocking accept() on them. The kernel will decide which worker
47
+ process to give a socket to and workers will sleep if there is
48
+ nothing to accept().
49
+
50
+ * Since non-blocking accept() is used, there can be a thundering
51
+ herd when an occasional client connects when application
52
+ *is not busy*. The thundering herd problem should not affect
53
+ applications that are running all the time since worker processes
54
+ will only select()/accept() outside of the application dispatch.
55
+
56
+ * Additionally, thundering herds are much smaller than with
57
+ configurations using existing prefork servers. Process counts should
58
+ only be scaled to backend resources, _never_ to the number of expected
59
+ clients like is typical with blocking prefork servers. So while we've
60
+ seen instances of popular prefork servers configured to run many
61
+ hundreds of worker processes, Unicorn deployments are typically only
62
+ 2-4 processes per-core.
63
+
64
+ * On-demand scaling of worker processes never happens automatically.
65
+ Again, Unicorn is concerned about scaling to backend limits and should
66
+ never configured in a fashion where it could be waiting on slow
67
+ clients. For extremely rare circumstances, we provide TTIN and TTOU
68
+ signal handlers to increment/decrement your process counts without
69
+ reloading. Think of it as driving a car with manual transmission:
70
+ you have a lot more control if you know what you're doing.
71
+
72
+ * Blocking I/O is used for clients. This allows a simpler code path
73
+ to be followed within the Ruby interpreter and fewer syscalls.
74
+ Applications that use threads continue to work if Unicorn
75
+ is only serving LAN or localhost clients.
76
+
77
+ * SIGKILL is used to terminate the timed-out workers from misbehaving apps
78
+ as reliably as possible on a UNIX system. The default timeout is a
79
+ generous 60 seconds (same default as in Mongrel).
80
+
81
+ * The poor performance of select() on large FD sets is avoided
82
+ as few file descriptors are used in each worker.
83
+ There should be no gain from moving to highly scalable but
84
+ unportable event notification solutions for watching few
85
+ file descriptors.
86
+
87
+ * If the master process dies unexpectedly for any reason,
88
+ workers will notice within :timeout/2 seconds and follow
89
+ the master to its death.
90
+
91
+ * There is never any explicit real-time dependency or communication
92
+ between the worker processes nor to the master process.
93
+ Synchronization is handled entirely by the OS kernel and shared
94
+ resources are never accessed by the worker when it is servicing
95
+ a client.
@@ -0,0 +1,5 @@
1
+ *.1
2
+ *.5
3
+ *.7
4
+ *.gz
5
+ *.html
@@ -0,0 +1,30 @@
1
+ all::
2
+
3
+ PANDOC = pandoc
4
+ PANDOC_OPTS = -f markdown --email-obfuscation=none
5
+ pandoc = $(PANDOC) $(PANDOC_OPTS)
6
+ pandoc_html = $(pandoc) --toc -t html --no-wrap
7
+
8
+ man1 := $(addsuffix .1,unicorn unicorn_rails)
9
+ html1 := $(addsuffix .html,$(man1))
10
+
11
+ all:: html man
12
+
13
+ html: $(html1)
14
+ man: $(man1)
15
+
16
+ install-html: html
17
+ mkdir -p ../doc/man1
18
+ install -m 644 $(html1) ../doc/man1
19
+
20
+ install-man: man
21
+ mkdir -p ../man/man1
22
+ install -m 644 $(man1) ../man/man1
23
+
24
+ %.1: %.1.txt
25
+ $(pandoc) -s -t man < $< > $@+ && mv $@+ $@
26
+ %.1.html: %.1.txt
27
+ $(pandoc_html) < $< > $@+ && mv $@+ $@
28
+
29
+ clean::
30
+ $(RM) $(man1) $(html1)
@@ -0,0 +1,187 @@
1
+ % UNICORN(1) Unicorn User Manual
2
+ % The Unicorn Community <unicorn-public@bogomips.org>
3
+ % September 15, 2009
4
+
5
+ # NAME
6
+
7
+ unicorn - a rackup-like command to launch the Unicorn HTTP server
8
+
9
+ # SYNOPSIS
10
+
11
+ unicorn [-c CONFIG_FILE] [-E RACK_ENV] [-D] [RACKUP_FILE]
12
+
13
+ # DESCRIPTION
14
+
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),
17
+ but the "working_directory" directive may be used in the CONFIG_FILE.
18
+
19
+ While unicorn takes a myriad of command-line options for
20
+ compatibility with ruby(1) and rackup(1), it is recommended to stick
21
+ to the few command-line options specified in the SYNOPSIS and use
22
+ the CONFIG_FILE as much as possible.
23
+
24
+ # RACKUP FILE
25
+
26
+ This defaults to \"config.ru\" in APP_ROOT. It should be the same
27
+ file used by rackup(1) and other Rack launchers, it uses the
28
+ *Rack::Builder* DSL.
29
+
30
+ Embedded command-line options are mostly parsed for compatibility
31
+ with rackup(1) but strongly discouraged.
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
+
52
+ -E, \--env RACK_ENV
53
+ : Run under the given RACK_ENV. See the RACK ENVIRONMENT section
54
+ for more details.
55
+
56
+ -l, \--listen ADDRESS
57
+ : Listens on a given ADDRESS. ADDRESS may be in the form of
58
+ HOST:PORT or PATH, HOST:PORT is taken to mean a TCP socket
59
+ and PATH is meant to be a path to a UNIX domain socket.
60
+ Defaults to "0.0.0.0:8080" (all addresses on TCP port 8080)
61
+ For production deployments, specifying the "listen" directive in
62
+ CONFIG_FILE is recommended as it allows fine-tuning of socket
63
+ options.
64
+ -N, \--no-default-middleware
65
+ : Disables loading middleware implied by RACK_ENV. This bypasses the
66
+ configuration documented in the RACK ENVIRONMENT section, but still
67
+ allows RACK_ENV to be used for application/framework-specific purposes.
68
+
69
+ # RACKUP COMPATIBILITY OPTIONS
70
+ -o, \--host HOST
71
+ : Listen on a TCP socket belonging to HOST, default is
72
+ "0.0.0.0" (all addresses).
73
+ If specified multiple times on the command-line, only the
74
+ last-specified value takes effect.
75
+ This option only exists for compatibility with the rackup(1) command,
76
+ use of "-l"/"\--listen" switch is recommended instead.
77
+
78
+ -p, \--port PORT
79
+ : Listen on the specified TCP PORT, default is 8080.
80
+ If specified multiple times on the command-line, only the last-specified
81
+ value takes effect.
82
+ This option only exists for compatibility with the rackup(1) command,
83
+ use of "-l"/"\--listen" switch is recommended instead.
84
+
85
+ -s, \--server SERVER
86
+ : No-op, this exists only for compatibility with rackup(1).
87
+
88
+ # RUBY OPTIONS
89
+ -e, \--eval LINE
90
+ : Evaluate a LINE of Ruby code. This evaluation happens
91
+ immediately as the command-line is being parsed.
92
+
93
+ -d, \--debug
94
+ : Turn on debug mode, the $DEBUG variable is set to true.
95
+
96
+ -w, \--warn
97
+ : Turn on verbose warnings, the $VERBOSE variable is set to true.
98
+
99
+ -I, \--include PATH
100
+ : specify $LOAD_PATH. PATH will be prepended to $LOAD_PATH.
101
+ The \':\' character may be used to delimit multiple directories.
102
+ This directive may be used more than once. Modifications to
103
+ $LOAD_PATH take place immediately and in the order they were
104
+ specified on the command-line.
105
+
106
+ -r, \--require LIBRARY
107
+ : require a specified LIBRARY before executing the application. The
108
+ \"require\" statement will be executed immediately and in the order
109
+ they were specified on the command-line.
110
+
111
+ # SIGNALS
112
+
113
+ The following UNIX signals may be sent to the master process:
114
+
115
+ * HUP - reload config file, app, and gracefully restart all workers
116
+ * INT/TERM - quick shutdown, kills all workers immediately
117
+ * QUIT - graceful shutdown, waits for workers to finish their
118
+ current request before finishing.
119
+ * USR1 - reopen all logs owned by the master and all workers
120
+ See Unicorn::Util.reopen_logs for what is considered a log.
121
+ * USR2 - reexecute the running binary. A separate QUIT
122
+ should be sent to the original process once the child is verified to
123
+ be up and running.
124
+ * WINCH - gracefully stops workers but keep the master running.
125
+ This will only work for daemonized processes.
126
+ * TTIN - increment the number of worker processes by one
127
+ * TTOU - decrement the number of worker processes by one
128
+
129
+ See the [SIGNALS][4] document for full description of all signals
130
+ used by Unicorn.
131
+
132
+ # RACK ENVIRONMENT
133
+
134
+ Accepted values of RACK_ENV and the middleware they automatically load
135
+ (outside of RACKUP_FILE) are exactly as those in rackup(1):
136
+
137
+ * development - loads Rack::CommonLogger, Rack::ShowExceptions, and
138
+ Rack::Lint middleware
139
+ * deployment - loads Rack::CommonLogger middleware
140
+ * none - loads no middleware at all, relying
141
+ entirely on RACKUP_FILE
142
+
143
+ All unrecognized values for RACK_ENV are assumed to be
144
+ "none". Production deployments are strongly encouraged to use
145
+ "deployment" or "none" for maximum performance.
146
+
147
+ As of Unicorn 0.94.0, RACK_ENV is exported as a process-wide environment
148
+ variable as well. While not current a part of the Rack specification as
149
+ of Rack 1.0.1, this has become a de facto standard in the Rack world.
150
+
151
+ Note the Rack::ContentLength and Rack::Chunked middlewares are also
152
+ loaded by "deployment" and "development", but no other values of
153
+ RACK_ENV. If needed, they must be individually specified in the
154
+ RACKUP_FILE, some frameworks do not require them.
155
+
156
+ # ENVIRONMENT VARIABLES
157
+
158
+ The RACK_ENV variable is set by the aforementioned \-E switch.
159
+ All application or library-specific environment variables (e.g. TMPDIR)
160
+ may always be set in the Unicorn CONFIG_FILE in addition to the spawning
161
+ shell. When transparently upgrading Unicorn, all environment variables
162
+ set in the old master process are inherited by the new master process.
163
+ Unicorn only uses (and will overwrite) the UNICORN_FD environment
164
+ variable internally when doing transparent upgrades.
165
+
166
+ UNICORN_FD is a comma-delimited list of one or more file descriptors
167
+ used to implement USR2 upgrades. Init systems may bind listen sockets
168
+ itself and spawn unicorn with UNICORN_FD set to the file descriptor
169
+ numbers of the listen socket(s).
170
+
171
+ As of unicorn 5.0, LISTEN_PID and LISTEN_FDS are used for socket
172
+ activation as documented in the sd_listen_fds(3) manpage. Users
173
+ relying on this feature do not need to specify a listen socket in
174
+ the unicorn config file.
175
+
176
+ # SEE ALSO
177
+
178
+ * *Rack::Builder* ri/RDoc
179
+ * *Unicorn::Configurator* ri/RDoc
180
+ * [Unicorn RDoc][1]
181
+ * [Rack RDoc][2]
182
+ * [Rackup HowTo][3]
183
+
184
+ [1]: https://bogomips.org/unicorn/
185
+ [2]: http://www.rubydoc.info/github/rack/rack/
186
+ [3]: https://github.com/rack/rack/wiki/tutorial-rackup-howto
187
+ [4]: https://bogomips.org/unicorn/SIGNALS.html
@@ -0,0 +1,175 @@
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 - unicorn launcher for Rails 1.x and 2.x users
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]: https://bogomips.org/unicorn/
173
+ [2]: http://www.rubydoc.info/github/rack/rack/
174
+ [3]: https://github.com/rack/rack/wiki/tutorial-rackup-howto
175
+ [4]: https://bogomips.org/unicorn/SIGNALS.html
data/FAQ ADDED
@@ -0,0 +1,70 @@
1
+ = Frequently Asked Questions about Unicorn
2
+
3
+ === Why is nginx getting ECONNRESET as a reverse proxy?
4
+
5
+ Request body data (commonly from POST and PUT requests) may not be
6
+ drained entirely by the application. This may happen when request
7
+ bodies are gzipped, as unicorn reads request body data lazily to avoid
8
+ overhead from bad requests.
9
+
10
+ Ref: https://bogomips.org/unicorn-public/FC91211E-FD32-432C-92FC-0318714C2170@zendesk.com/
11
+
12
+ === Why aren't my Rails log files rotated when I use SIGUSR1?
13
+
14
+ The Rails autoflush_log option must remain disabled with multiprocess
15
+ servers such as unicorn. Buffering in userspace may cause lines to be
16
+ partially written and lead to corruption in the presence of multiple
17
+ processes. With reasonable amounts of logging, the performance impact
18
+ of autoflush_log should be negligible on Linux and other modern kernels.
19
+
20
+ === Why are my redirects going to "http" URLs when my site uses https?
21
+
22
+ If your site is entirely behind https, then Rack applications that use
23
+ "rack.url_scheme" can set the following in the Unicorn config file:
24
+
25
+ HttpRequest::DEFAULTS["rack.url_scheme"] = "https"
26
+
27
+ For frameworks that do not use "rack.url_scheme", you can also
28
+ try setting one or both of the following:
29
+
30
+ HttpRequest::DEFAULTS["HTTPS"] = "on"
31
+ HttpRequest::DEFAULTS["HTTP_X_FORWARDED_PROTO"] = "https"
32
+
33
+ Otherwise, you can configure your proxy (nginx) to send the
34
+ "X-Forwarded-Proto: https" header only for parts of the site that use
35
+ https. For nginx, you can do it with the following line in appropriate
36
+ "location" blocks of your nginx config file:
37
+
38
+ proxy_set_header X-Forwarded-Proto https;
39
+
40
+ === Why are log messages from Unicorn are unformatted when using Rails?
41
+
42
+ Current versions of Rails unfortunately overrides the default Logger
43
+ formatter.
44
+
45
+ You can undo this behavior with the default logger in your Unicorn
46
+ config file:
47
+
48
+ Configurator::DEFAULTS[:logger].formatter = Logger::Formatter.new
49
+
50
+ Of course you can specify an entirely different logger as well
51
+ with the "logger" directive described by Unicorn::Configurator.
52
+
53
+ === Why am I getting "connection refused"/502 errors under high load?
54
+
55
+ Short answer: your application cannot keep up.
56
+
57
+ You can increase the size of the :backlog parameter if your kernel
58
+ supports a larger listen() queue, but keep in mind having a large listen
59
+ queue makes failover to a different machine more difficult.
60
+
61
+ See the TUNING and Unicorn::Configurator documents for more information
62
+ on :backlog-related topics.
63
+
64
+ === I've installed Rack 1.1.x, why can't Unicorn load Rails (2.3.5)?
65
+
66
+ Rails 2.3.5 is not compatible with Rack 1.1.x. Unicorn is compatible
67
+ with both Rack 1.1.x and Rack 1.0.x, and RubyGems will load the latest
68
+ version of Rack installed on the system. Uninstalling the Rack 1.1.x
69
+ gem should solve gem loading issues with Rails 2.3.5. Rails 2.3.6
70
+ and later correctly support Rack 1.1.x.
data/GIT-VERSION-FILE ADDED
@@ -0,0 +1 @@
1
+ GIT_VERSION = 5.2.0.2.gd893.dirty
data/GIT-VERSION-GEN ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ DEF_VER = "v5.2.0"
3
+ CONSTANT = "Unicorn::Const::UNICORN_VERSION"
4
+ RVF = "lib/unicorn/version.rb"
5
+ GVF = "GIT-VERSION-FILE"
6
+ vn = DEF_VER
7
+
8
+ # First see if there is a version file (included in release tarballs),
9
+ # then try git-describe, then default.
10
+ if File.exist?(".git")
11
+ describe = `git describe --abbrev=4 HEAD 2>/dev/null`.strip
12
+ case describe
13
+ when /\Av[0-9]*/
14
+ vn = describe
15
+ system(*%w(git update-index -q --refresh))
16
+ unless `git diff-index --name-only HEAD --`.chomp.empty?
17
+ vn << "-dirty"
18
+ end
19
+ vn.tr!('-', '.')
20
+ end
21
+ end
22
+
23
+ vn = vn.sub!(/\Av/, "")
24
+
25
+ # generate the Ruby constant
26
+ new_ruby_version = "#{CONSTANT} = '#{vn}'\n"
27
+ cur_ruby_version = File.read(RVF) rescue nil
28
+ if new_ruby_version != cur_ruby_version
29
+ File.open(RVF, "w") { |fp| fp.write(new_ruby_version) }
30
+ end
31
+
32
+ # generate the makefile snippet
33
+ new_make_version = "GIT_VERSION = #{vn}\n"
34
+ cur_make_version = File.read(GVF) rescue nil
35
+ if new_make_version != cur_make_version
36
+ File.open(GVF, "w") { |fp| fp.write(new_make_version) }
37
+ end
38
+
39
+ puts vn if $0 == __FILE__