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/bin/unicorn ADDED
@@ -0,0 +1,126 @@
1
+ #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2
+ # -*- encoding: binary -*-
3
+ require 'unicorn/launcher'
4
+ require 'optparse'
5
+
6
+ ENV["RACK_ENV"] ||= "development"
7
+ rackup_opts = Unicorn::Configurator::RACKUP
8
+ options = rackup_opts[:options]
9
+
10
+ op = OptionParser.new("", 24, ' ') do |opts|
11
+ cmd = File.basename($0)
12
+ opts.banner = "Usage: #{cmd} " \
13
+ "[ruby options] [#{cmd} options] [rackup config file]"
14
+ opts.separator "Ruby options:"
15
+
16
+ lineno = 1
17
+ opts.on("-e", "--eval LINE", "evaluate a LINE of code") do |line|
18
+ eval line, TOPLEVEL_BINDING, "-e", lineno
19
+ lineno += 1
20
+ end
21
+
22
+ opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
23
+ $DEBUG = true
24
+ end
25
+
26
+ opts.on("-w", "--warn", "turn warnings on for your script") do
27
+ $-w = true
28
+ end
29
+
30
+ opts.on("-I", "--include PATH",
31
+ "specify $LOAD_PATH (may be used more than once)") do |path|
32
+ $LOAD_PATH.unshift(*path.split(':'))
33
+ end
34
+
35
+ opts.on("-r", "--require LIBRARY",
36
+ "require the library, before executing your script") do |library|
37
+ require library
38
+ end
39
+
40
+ opts.separator "#{cmd} options:"
41
+
42
+ # some of these switches exist for rackup command-line compatibility,
43
+
44
+ opts.on("-o", "--host HOST",
45
+ "listen on HOST (default: #{Unicorn::Const::DEFAULT_HOST})") do |h|
46
+ rackup_opts[:host] = h
47
+ rackup_opts[:set_listener] = true
48
+ end
49
+
50
+ opts.on("-p", "--port PORT", Integer,
51
+ "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |port|
52
+ rackup_opts[:port] = port
53
+ rackup_opts[:set_listener] = true
54
+ end
55
+
56
+ opts.on("-E", "--env RACK_ENV",
57
+ "use RACK_ENV for defaults (default: development)") do |e|
58
+ ENV["RACK_ENV"] = e
59
+ end
60
+
61
+ opts.on("-N", "--no-default-middleware",
62
+ "do not load middleware implied by RACK_ENV") do |e|
63
+ rackup_opts[:no_default_middleware] = true
64
+ end
65
+
66
+ opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
67
+ rackup_opts[:daemonize] = !!d
68
+ end
69
+
70
+ opts.on("-P", "--pid FILE", "DEPRECATED") do |f|
71
+ warn %q{Use of --pid/-P is strongly discouraged}
72
+ warn %q{Use the 'pid' directive in the Unicorn config file instead}
73
+ options[:pid] = f
74
+ end
75
+
76
+ opts.on("-s", "--server SERVER",
77
+ "this flag only exists for compatibility") do |s|
78
+ warn "-s/--server only exists for compatibility with rackup"
79
+ end
80
+
81
+ # Unicorn-specific stuff
82
+ opts.on("-l", "--listen {HOST:PORT|PATH}",
83
+ "listen on HOST:PORT or PATH",
84
+ "this may be specified multiple times",
85
+ "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
86
+ options[:listeners] << address
87
+ end
88
+
89
+ opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
90
+ options[:config_file] = f
91
+ end
92
+
93
+ # I'm avoiding Unicorn-specific config options on the command-line.
94
+ # IMNSHO, config options on the command-line are redundant given
95
+ # config files and make things unnecessarily complicated with multiple
96
+ # places to look for a config option.
97
+
98
+ opts.separator "Common options:"
99
+
100
+ opts.on_tail("-h", "--help", "Show this message") do
101
+ puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
102
+ exit
103
+ end
104
+
105
+ opts.on_tail("-v", "--version", "Show version") do
106
+ puts "#{cmd} v#{Unicorn::Const::UNICORN_VERSION}"
107
+ exit
108
+ end
109
+
110
+ opts.parse! ARGV
111
+ end
112
+
113
+ app = Unicorn.builder(ARGV[0] || 'config.ru', op)
114
+ op = nil
115
+
116
+ if $DEBUG
117
+ require 'pp'
118
+ pp({
119
+ :unicorn_options => options,
120
+ :app => app,
121
+ :daemonize => rackup_opts[:daemonize],
122
+ })
123
+ end
124
+
125
+ Unicorn::Launcher.daemonize!(options) if rackup_opts[:daemonize]
126
+ Unicorn::HttpServer.new(app, options).start.join
data/bin/unicorn_rails ADDED
@@ -0,0 +1,209 @@
1
+ #!/this/will/be/overwritten/or/wrapped/anyways/do/not/worry/ruby
2
+ # -*- encoding: binary -*-
3
+ require 'unicorn/launcher'
4
+ require 'optparse'
5
+ require 'fileutils'
6
+
7
+ ENV['RAILS_ENV'] ||= "development"
8
+ rackup_opts = Unicorn::Configurator::RACKUP
9
+ options = rackup_opts[:options]
10
+
11
+ op = OptionParser.new("", 24, ' ') do |opts|
12
+ cmd = File.basename($0)
13
+ opts.banner = "Usage: #{cmd} " \
14
+ "[ruby options] [#{cmd} options] [rackup config file]"
15
+ opts.separator "Ruby options:"
16
+
17
+ lineno = 1
18
+ opts.on("-e", "--eval LINE", "evaluate a LINE of code") do |line|
19
+ eval line, TOPLEVEL_BINDING, "-e", lineno
20
+ lineno += 1
21
+ end
22
+
23
+ opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") do
24
+ $DEBUG = true
25
+ end
26
+
27
+ opts.on("-w", "--warn", "turn warnings on for your script") do
28
+ $-w = true
29
+ end
30
+
31
+ opts.on("-I", "--include PATH",
32
+ "specify $LOAD_PATH (may be used more than once)") do |path|
33
+ $LOAD_PATH.unshift(*path.split(':'))
34
+ end
35
+
36
+ opts.on("-r", "--require LIBRARY",
37
+ "require the library, before executing your script") do |library|
38
+ require library
39
+ end
40
+
41
+ opts.separator "#{cmd} options:"
42
+
43
+ # some of these switches exist for rackup command-line compatibility,
44
+
45
+ opts.on("-o", "--host HOST",
46
+ "listen on HOST (default: #{Unicorn::Const::DEFAULT_HOST})") do |h|
47
+ rackup_opts[:host] = h
48
+ rackup_opts[:set_listener] = true
49
+ end
50
+
51
+ opts.on("-p", "--port PORT", Integer,
52
+ "use PORT (default: #{Unicorn::Const::DEFAULT_PORT})") do |port|
53
+ rackup_opts[:port] = port
54
+ rackup_opts[:set_listener] = true
55
+ end
56
+
57
+ opts.on("-E", "--env RAILS_ENV",
58
+ "use RAILS_ENV for defaults (default: development)") do |e|
59
+ ENV['RAILS_ENV'] = e
60
+ end
61
+
62
+ opts.on("-D", "--daemonize", "run daemonized in the background") do |d|
63
+ rackup_opts[:daemonize] = !!d
64
+ end
65
+
66
+ # Unicorn-specific stuff
67
+ opts.on("-l", "--listen {HOST:PORT|PATH}",
68
+ "listen on HOST:PORT or PATH",
69
+ "this may be specified multiple times",
70
+ "(default: #{Unicorn::Const::DEFAULT_LISTEN})") do |address|
71
+ options[:listeners] << address
72
+ end
73
+
74
+ opts.on("-c", "--config-file FILE", "Unicorn-specific config file") do |f|
75
+ options[:config_file] = f
76
+ end
77
+
78
+ opts.on("-P PATH", "DEPRECATED") do |v|
79
+ warn %q{Use of -P is ambiguous and discouraged}
80
+ warn %q{Use --path or RAILS_RELATIVE_URL_ROOT instead}
81
+ ENV['RAILS_RELATIVE_URL_ROOT'] = v
82
+ end
83
+
84
+ opts.on("--path PATH", "Runs Rails app mounted at a specific path.",
85
+ "(default: /)") do |v|
86
+ ENV['RAILS_RELATIVE_URL_ROOT'] = v
87
+ end
88
+
89
+ # I'm avoiding Unicorn-specific config options on the command-line.
90
+ # IMNSHO, config options on the command-line are redundant given
91
+ # config files and make things unnecessarily complicated with multiple
92
+ # places to look for a config option.
93
+
94
+ opts.separator "Common options:"
95
+
96
+ opts.on_tail("-h", "--help", "Show this message") do
97
+ puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
98
+ exit
99
+ end
100
+
101
+ opts.on_tail("-v", "--version", "Show version") do
102
+ puts "#{cmd} v#{Unicorn::Const::UNICORN_VERSION}"
103
+ exit
104
+ end
105
+
106
+ opts.parse! ARGV
107
+ end
108
+
109
+ def rails_dispatcher
110
+ if ::Rails::VERSION::MAJOR >= 3 && ::File.exist?('config/application.rb')
111
+ if ::File.read('config/application.rb') =~ /^module\s+([\w:]+)\s*$/
112
+ app_module = Object.const_get($1)
113
+ begin
114
+ result = app_module::Application
115
+ rescue NameError
116
+ end
117
+ end
118
+ end
119
+
120
+ if result.nil? && defined?(ActionController::Dispatcher)
121
+ result = ActionController::Dispatcher.new
122
+ end
123
+
124
+ result || abort("Unable to locate the application dispatcher class")
125
+ end
126
+
127
+ def rails_builder(ru, op, daemonize)
128
+ return Unicorn.builder(ru, op) if ru
129
+
130
+ # allow Configurator to parse cli switches embedded in the ru file
131
+ Unicorn::Configurator::RACKUP.update(:file => :rails, :optparse => op)
132
+
133
+ # this lambda won't run until after forking if preload_app is false
134
+ # this runs after config file reloading
135
+ lambda do ||
136
+ # Rails 3 includes a config.ru, use it if we find it after
137
+ # working_directory is bound.
138
+ ::File.exist?('config.ru') and
139
+ return Unicorn.builder('config.ru', op).call
140
+
141
+ # Load Rails and (possibly) the private version of Rack it bundles.
142
+ begin
143
+ require ::File.expand_path('config/boot')
144
+ require ::File.expand_path('config/environment')
145
+ rescue LoadError => err
146
+ abort "#$0 must be run inside RAILS_ROOT: #{err.inspect}"
147
+ end
148
+
149
+ defined?(::Rails::VERSION::STRING) or
150
+ abort "Rails::VERSION::STRING not defined by config/{boot,environment}"
151
+ # it seems Rails >=2.2 support Rack, but only >=2.3 requires it
152
+ old_rails = case ::Rails::VERSION::MAJOR
153
+ when 0, 1 then true
154
+ when 2 then Rails::VERSION::MINOR < 3 ? true : false
155
+ else
156
+ false
157
+ end
158
+
159
+ Rack::Builder.new do
160
+ map_path = ENV['RAILS_RELATIVE_URL_ROOT'] || '/'
161
+ if old_rails
162
+ if map_path != '/'
163
+ # patches + tests welcome, but I really cbf to deal with this
164
+ # since all apps I've ever dealt with just use "/" ...
165
+ warn "relative URL roots may not work for older Rails"
166
+ end
167
+ warn "LogTailer not available for Rails < 2.3" unless daemonize
168
+ warn "Debugger not available" if $DEBUG
169
+ require 'unicorn/app/old_rails'
170
+ map(map_path) do
171
+ use Unicorn::App::OldRails::Static
172
+ run Unicorn::App::OldRails.new
173
+ end
174
+ else
175
+ use Rails::Rack::LogTailer unless daemonize
176
+ use Rails::Rack::Debugger if $DEBUG
177
+ map(map_path) do
178
+ unless defined?(ActionDispatch::Static)
179
+ use Rails::Rack::Static
180
+ end
181
+ run rails_dispatcher
182
+ end
183
+ end
184
+ end.to_app
185
+ end
186
+ end
187
+
188
+ app = rails_builder(ARGV[0], op, rackup_opts[:daemonize])
189
+ op = nil
190
+
191
+ if $DEBUG
192
+ require 'pp'
193
+ pp({
194
+ :unicorn_options => options,
195
+ :app => app,
196
+ :daemonize => rackup_opts[:daemonize],
197
+ })
198
+ end
199
+
200
+ # ensure Rails standard tmp paths exist
201
+ options[:after_reload] = lambda do
202
+ FileUtils.mkdir_p(%w(cache pids sessions sockets).map! { |d| "tmp/#{d}" })
203
+ end
204
+
205
+ if rackup_opts[:daemonize]
206
+ options[:pid] = "tmp/pids/unicorn.pid"
207
+ Unicorn::Launcher.daemonize!(options)
208
+ end
209
+ Unicorn::HttpServer.new(app, options).start.join
@@ -0,0 +1,2 @@
1
+ # see {Unicorn::OobGC}[https://bogomips.org/unicorn/Unicorn/OobGC.html]
2
+ # Unicorn::OobGC was broken in Unicorn v3.3.1 - v3.6.1 and fixed in v3.6.2
data/examples/echo.ru ADDED
@@ -0,0 +1,27 @@
1
+ #\-E none
2
+ #
3
+ # Example application that echoes read data back to the HTTP client.
4
+ # This emulates the old echo protocol people used to run.
5
+ #
6
+ # An example of using this in a client would be to run:
7
+ # curl --no-buffer -T- http://host:port/
8
+ #
9
+ # Then type random stuff in your terminal to watch it get echoed back!
10
+
11
+ class EchoBody < Struct.new(:input)
12
+
13
+ def each(&block)
14
+ while buf = input.read(4096)
15
+ yield buf
16
+ end
17
+ self
18
+ end
19
+
20
+ end
21
+
22
+ use Rack::Chunked
23
+ run lambda { |env|
24
+ /\A100-continue\z/i =~ env['HTTP_EXPECT'] and return [100, {}, []]
25
+ [ 200, { 'Content-Type' => 'application/octet-stream' },
26
+ EchoBody.new(env['rack.input']) ]
27
+ }
data/examples/init.sh ADDED
@@ -0,0 +1,102 @@
1
+ #!/bin/sh
2
+ set -e
3
+ ### BEGIN INIT INFO
4
+ # Provides: unicorn
5
+ # Required-Start: $local_fs $network
6
+ # Required-Stop: $local_fs $network
7
+ # Default-Start: 2 3 4 5
8
+ # Default-Stop: 0 1 6
9
+ # Short-Description: Start/stop unicorn Rack app server
10
+ ### END INIT INFO
11
+
12
+ # Example init script, this can be used with nginx, too,
13
+ # since nginx and unicorn accept the same signals.
14
+
15
+ # Feel free to change any of the following variables for your app:
16
+ TIMEOUT=${TIMEOUT-60}
17
+ APP_ROOT=/home/x/my_app/current
18
+ PID=$APP_ROOT/tmp/pids/unicorn.pid
19
+ CMD="/usr/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb"
20
+ INIT_CONF=$APP_ROOT/config/init.conf
21
+ UPGRADE_DELAY=${UPGRADE_DELAY-2}
22
+ action="$1"
23
+ set -u
24
+
25
+ test -f "$INIT_CONF" && . $INIT_CONF
26
+
27
+ OLD="$PID.oldbin"
28
+
29
+ cd $APP_ROOT || exit 1
30
+
31
+ sig () {
32
+ test -s "$PID" && kill -$1 $(cat $PID)
33
+ }
34
+
35
+ oldsig () {
36
+ test -s "$OLD" && kill -$1 $(cat $OLD)
37
+ }
38
+
39
+ case $action in
40
+ start)
41
+ sig 0 && echo >&2 "Already running" && exit 0
42
+ $CMD
43
+ ;;
44
+ stop)
45
+ sig QUIT && exit 0
46
+ echo >&2 "Not running"
47
+ ;;
48
+ force-stop)
49
+ sig TERM && exit 0
50
+ echo >&2 "Not running"
51
+ ;;
52
+ restart|reload)
53
+ sig HUP && echo reloaded OK && exit 0
54
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
55
+ $CMD
56
+ ;;
57
+ upgrade)
58
+ if oldsig 0
59
+ then
60
+ echo >&2 "Old upgraded process still running with $OLD"
61
+ exit 1
62
+ fi
63
+
64
+ cur_pid=
65
+ if test -s "$PID"
66
+ then
67
+ cur_pid=$(cat $PID)
68
+ fi
69
+
70
+ if test -n "$cur_pid" &&
71
+ kill -USR2 "$cur_pid" &&
72
+ sleep $UPGRADE_DELAY &&
73
+ new_pid=$(cat $PID) &&
74
+ test x"$new_pid" != x"$cur_pid" &&
75
+ kill -0 "$new_pid" &&
76
+ kill -QUIT "$cur_pid"
77
+ then
78
+ n=$TIMEOUT
79
+ while kill -0 "$cur_pid" 2>/dev/null && test $n -ge 0
80
+ do
81
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
82
+ done
83
+ echo
84
+
85
+ if test $n -lt 0 && kill -0 "$cur_pid" 2>/dev/null
86
+ then
87
+ echo >&2 "$cur_pid still running after $TIMEOUT seconds"
88
+ exit 1
89
+ fi
90
+ exit 0
91
+ fi
92
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
93
+ $CMD
94
+ ;;
95
+ reopen-logs)
96
+ sig USR1
97
+ ;;
98
+ *)
99
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
100
+ exit 1
101
+ ;;
102
+ esac
@@ -0,0 +1,25 @@
1
+ # Multi-Processing-safe monkey patch for Logger
2
+ #
3
+ # This monkey patch fixes the case where "preload_app true" is used and
4
+ # the application spawns a background thread upon being loaded.
5
+ #
6
+ # This removes all lock from the Logger code and solely relies on the
7
+ # underlying filesystem to handle write(2) system calls atomically when
8
+ # O_APPEND is used. This is safe in the presence of both multiple
9
+ # threads (native or green) and multiple processes when writing to
10
+ # a filesystem with POSIX O_APPEND semantics.
11
+ #
12
+ # It should be noted that the original locking on Logger could _never_ be
13
+ # considered reliable on non-POSIX filesystems with multiple processes,
14
+ # either, so nothing is lost in that case.
15
+
16
+ require 'logger'
17
+ class Logger::LogDevice
18
+ def write(message)
19
+ @dev.syswrite(message)
20
+ end
21
+
22
+ def close
23
+ @dev.close
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ # example logrotate config file, I usually keep this in
2
+ # /etc/logrotate.d/unicorn_app on my Debian systems
3
+ #
4
+ # See the logrotate(8) manpage for more information:
5
+ # http://linux.die.net/man/8/logrotate
6
+ #
7
+ # public logrotate-related discussion in our archives:
8
+ # https://bogomips.org/unicorn-public/?q=logrotate
9
+
10
+ # Modify the following glob to match the logfiles your app writes to:
11
+ /var/log/unicorn_app/*.log {
12
+ # this first block is mostly just personal preference, though
13
+ # I wish logrotate offered an "hourly" option...
14
+ daily
15
+ missingok
16
+ rotate 180
17
+ compress # must use with delaycompress below
18
+ dateext
19
+
20
+ # this is important if using "compress" since we need to call
21
+ # the "lastaction" script below before compressing:
22
+ delaycompress
23
+
24
+ # note the lack of the evil "copytruncate" option in this
25
+ # config. Unicorn supports the USR1 signal and we send it
26
+ # as our "lastaction" action:
27
+ lastaction
28
+ # For systemd users, assuming you use two services
29
+ # (as recommended) to allow zero-downtime upgrades.
30
+ # Only one service needs to be started, but signaling
31
+ # both here is harmless as long as they're both enabled
32
+ systemctl kill -s SIGUSR1 unicorn@1.service
33
+ systemctl kill -s SIGUSR1 unicorn@2.service
34
+
35
+ # Examples for other process management systems appreciated
36
+ # Mail us at unicorn-public@bogomips.org
37
+ # (see above for archives)
38
+
39
+ # If you use a pid file and assuming your pid file
40
+ # is in /var/run/unicorn_app/pid
41
+ pid=/var/run/unicorn_app/pid
42
+ test -s $pid && kill -USR1 "$(cat $pid)"
43
+ endscript
44
+ }
@@ -0,0 +1,155 @@
1
+ # This is example contains the bare mininum to get nginx going with
2
+ # unicorn servers. Generally these configuration settings
3
+ # are applicable to other HTTP application servers (and not just Ruby
4
+ # ones), so if you have one working well for proxying another app
5
+ # server, feel free to continue using it.
6
+ #
7
+ # The only setting we feel strongly about is the fail_timeout=0
8
+ # directive in the "upstream" block. max_fails=0 also has the same
9
+ # effect as fail_timeout=0 for current versions of nginx and may be
10
+ # used in its place.
11
+ #
12
+ # Users are strongly encouraged to refer to nginx documentation for more
13
+ # details and search for other example configs.
14
+
15
+ # you generally only need one nginx worker unless you're serving
16
+ # large amounts of static files which require blocking disk reads
17
+ worker_processes 1;
18
+
19
+ # # drop privileges, root is needed on most systems for binding to port 80
20
+ # # (or anything < 1024). Capability-based security may be available for
21
+ # # your system and worth checking out so you won't need to be root to
22
+ # # start nginx to bind on 80
23
+ user nobody nogroup; # for systems with a "nogroup"
24
+ # user nobody nobody; # for systems with "nobody" as a group instead
25
+
26
+ # Feel free to change all paths to suite your needs here, of course
27
+ pid /path/to/nginx.pid;
28
+ error_log /path/to/nginx.error.log;
29
+
30
+ events {
31
+ worker_connections 1024; # increase if you have lots of clients
32
+ accept_mutex off; # "on" if nginx worker_processes > 1
33
+ # use epoll; # enable for Linux 2.6+
34
+ # use kqueue; # enable for FreeBSD, OSX
35
+ }
36
+
37
+ http {
38
+ # nginx will find this file in the config directory set at nginx build time
39
+ include mime.types;
40
+
41
+ # fallback in case we can't determine a type
42
+ default_type application/octet-stream;
43
+
44
+ # click tracking!
45
+ access_log /path/to/nginx.access.log combined;
46
+
47
+ # you generally want to serve static files with nginx since
48
+ # unicorn is not and will never be optimized for it
49
+ sendfile on;
50
+
51
+ tcp_nopush on; # off may be better for *some* Comet/long-poll stuff
52
+ tcp_nodelay off; # on may be better for some Comet/long-poll stuff
53
+
54
+ # we haven't checked to see if Rack::Deflate on the app server is
55
+ # faster or not than doing compression via nginx. It's easier
56
+ # to configure it all in one place here for static files and also
57
+ # to disable gzip for clients who don't get gzip/deflate right.
58
+ # There are other gzip settings that may be needed used to deal with
59
+ # bad clients out there, see http://wiki.nginx.org/NginxHttpGzipModule
60
+ gzip on;
61
+ gzip_http_version 1.0;
62
+ gzip_proxied any;
63
+ gzip_min_length 500;
64
+ gzip_disable "MSIE [1-6]\.";
65
+ gzip_types text/plain text/html text/xml text/css
66
+ text/comma-separated-values
67
+ text/javascript application/x-javascript
68
+ application/atom+xml;
69
+
70
+ # this can be any application server, not just unicorn
71
+ upstream app_server {
72
+ # fail_timeout=0 means we always retry an upstream even if it failed
73
+ # to return a good HTTP response (in case the unicorn master nukes a
74
+ # single worker for timing out).
75
+
76
+ # for UNIX domain socket setups:
77
+ server unix:/path/to/.unicorn.sock fail_timeout=0;
78
+
79
+ # for TCP setups, point these to your backend servers
80
+ # server 192.168.0.7:8080 fail_timeout=0;
81
+ # server 192.168.0.8:8080 fail_timeout=0;
82
+ # server 192.168.0.9:8080 fail_timeout=0;
83
+ }
84
+
85
+ server {
86
+ # enable one of the following if you're on Linux or FreeBSD
87
+ # listen 80 default deferred; # for Linux
88
+ # listen 80 default accept_filter=httpready; # for FreeBSD
89
+
90
+ # If you have IPv6, you'll likely want to have two separate listeners.
91
+ # One on IPv4 only (the default), and another on IPv6 only instead
92
+ # of a single dual-stack listener. A dual-stack listener will make
93
+ # for ugly IPv4 addresses in $remote_addr (e.g ":ffff:10.0.0.1"
94
+ # instead of just "10.0.0.1") and potentially trigger bugs in
95
+ # some software.
96
+ # listen [::]:80 ipv6only=on; # deferred or accept_filter recommended
97
+
98
+ client_max_body_size 4G;
99
+ server_name _;
100
+
101
+ # ~2 seconds is often enough for most folks to parse HTML/CSS and
102
+ # retrieve needed images/icons/frames, connections are cheap in
103
+ # nginx so increasing this is generally safe...
104
+ keepalive_timeout 5;
105
+
106
+ # path for static files
107
+ root /path/to/app/current/public;
108
+
109
+ # Prefer to serve static files directly from nginx to avoid unnecessary
110
+ # data copies from the application server.
111
+ #
112
+ # try_files directive appeared in in nginx 0.7.27 and has stabilized
113
+ # over time. Older versions of nginx (e.g. 0.6.x) requires
114
+ # "if (!-f $request_filename)" which was less efficient:
115
+ # https://bogomips.org/unicorn.git/tree/examples/nginx.conf?id=v3.3.1#n127
116
+ try_files $uri/index.html $uri.html $uri @app;
117
+
118
+ location @app {
119
+ # an HTTP header important enough to have its own Wikipedia entry:
120
+ # http://en.wikipedia.org/wiki/X-Forwarded-For
121
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
122
+
123
+ # enable this if you forward HTTPS traffic to unicorn,
124
+ # this helps Rack set the proper URL scheme for doing redirects:
125
+ # proxy_set_header X-Forwarded-Proto $scheme;
126
+
127
+ # pass the Host: header from the client right along so redirects
128
+ # can be set properly within the Rack application
129
+ proxy_set_header Host $http_host;
130
+
131
+ # we don't want nginx trying to do something clever with
132
+ # redirects, we set the Host: header above already.
133
+ proxy_redirect off;
134
+
135
+ # It's also safe to set if you're using only serving fast clients
136
+ # with unicorn + nginx, but not slow clients. You normally want
137
+ # nginx to buffer responses to slow clients, even with Rails 3.1
138
+ # streaming because otherwise a slow client can become a bottleneck
139
+ # of unicorn.
140
+ #
141
+ # The Rack application may also set "X-Accel-Buffering (yes|no)"
142
+ # in the response headers do disable/enable buffering on a
143
+ # per-response basis.
144
+ # proxy_buffering off;
145
+
146
+ proxy_pass http://app_server;
147
+ }
148
+
149
+ # Rails error pages
150
+ error_page 500 502 503 504 /500.html;
151
+ location = /500.html {
152
+ root /path/to/app/current/public;
153
+ }
154
+ }
155
+ }