unicorn-fork 6.1.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.
- checksums.yaml +7 -0
- data/.CHANGELOG.old +25 -0
- data/.document +28 -0
- data/.gitattributes +5 -0
- data/.gitignore +25 -0
- data/.mailmap +26 -0
- data/.manifest +144 -0
- data/.olddoc.yml +25 -0
- data/Application_Timeouts +77 -0
- data/CONTRIBUTORS +39 -0
- data/COPYING +674 -0
- data/DESIGN +99 -0
- data/Documentation/.gitignore +3 -0
- data/Documentation/unicorn.1 +222 -0
- data/Documentation/unicorn_rails.1 +207 -0
- data/FAQ +70 -0
- data/GIT-VERSION-FILE +1 -0
- data/GIT-VERSION-GEN +39 -0
- data/GNUmakefile +318 -0
- data/HACKING +117 -0
- data/ISSUES +102 -0
- data/KNOWN_ISSUES +79 -0
- data/LICENSE +67 -0
- data/Links +58 -0
- data/PHILOSOPHY +139 -0
- data/README +165 -0
- data/Rakefile +17 -0
- data/SIGNALS +123 -0
- data/Sandbox +104 -0
- data/TODO +1 -0
- data/TUNING +119 -0
- data/archive/.gitignore +3 -0
- data/archive/slrnpull.conf +4 -0
- data/bin/unicorn +129 -0
- data/bin/unicorn_rails +210 -0
- data/examples/big_app_gc.rb +3 -0
- data/examples/echo.ru +27 -0
- data/examples/init.sh +102 -0
- data/examples/logger_mp_safe.rb +26 -0
- data/examples/logrotate.conf +44 -0
- data/examples/nginx.conf +156 -0
- data/examples/unicorn.conf.minimal.rb +14 -0
- data/examples/unicorn.conf.rb +111 -0
- data/examples/unicorn.socket +11 -0
- data/examples/unicorn@.service +40 -0
- data/ext/unicorn_http/CFLAGS +13 -0
- data/ext/unicorn_http/c_util.h +115 -0
- data/ext/unicorn_http/common_field_optimization.h +128 -0
- data/ext/unicorn_http/epollexclusive.h +128 -0
- data/ext/unicorn_http/ext_help.h +38 -0
- data/ext/unicorn_http/extconf.rb +40 -0
- data/ext/unicorn_http/global_variables.h +97 -0
- data/ext/unicorn_http/httpdate.c +91 -0
- data/ext/unicorn_http/unicorn_http.c +4348 -0
- data/ext/unicorn_http/unicorn_http.rl +1054 -0
- data/ext/unicorn_http/unicorn_http_common.rl +76 -0
- data/lib/unicorn/app/old_rails/static.rb +60 -0
- data/lib/unicorn/app/old_rails.rb +36 -0
- data/lib/unicorn/cgi_wrapper.rb +148 -0
- data/lib/unicorn/configurator.rb +749 -0
- data/lib/unicorn/const.rb +22 -0
- data/lib/unicorn/http_request.rb +180 -0
- data/lib/unicorn/http_response.rb +95 -0
- data/lib/unicorn/http_server.rb +860 -0
- data/lib/unicorn/launcher.rb +63 -0
- data/lib/unicorn/oob_gc.rb +82 -0
- data/lib/unicorn/preread_input.rb +34 -0
- data/lib/unicorn/select_waiter.rb +7 -0
- data/lib/unicorn/socket_helper.rb +186 -0
- data/lib/unicorn/stream_input.rb +152 -0
- data/lib/unicorn/tee_input.rb +132 -0
- data/lib/unicorn/tmpio.rb +34 -0
- data/lib/unicorn/util.rb +91 -0
- data/lib/unicorn/version.rb +1 -0
- data/lib/unicorn/worker.rb +166 -0
- data/lib/unicorn.rb +137 -0
- data/man/man1/unicorn.1 +222 -0
- data/man/man1/unicorn_rails.1 +207 -0
- data/setup.rb +1587 -0
- data/t/.gitignore +4 -0
- data/t/GNUmakefile +5 -0
- data/t/README +49 -0
- data/t/active-unix-socket.t +110 -0
- data/t/back-out-of-upgrade.t +44 -0
- data/t/bin/unused_listen +40 -0
- data/t/client_body_buffer_size.ru +15 -0
- data/t/client_body_buffer_size.t +79 -0
- data/t/detach.ru +12 -0
- data/t/env.ru +4 -0
- data/t/fails-rack-lint.ru +6 -0
- data/t/heartbeat-timeout.ru +13 -0
- data/t/heartbeat-timeout.t +60 -0
- data/t/integration.ru +129 -0
- data/t/integration.t +509 -0
- data/t/lib.perl +309 -0
- data/t/listener_names.ru +5 -0
- data/t/my-tap-lib.sh +201 -0
- data/t/oob_gc.ru +18 -0
- data/t/oob_gc_path.ru +18 -0
- data/t/pid.ru +4 -0
- data/t/preread_input.ru +23 -0
- data/t/reload-bad-config.t +49 -0
- data/t/reopen-logs.ru +14 -0
- data/t/reopen-logs.t +36 -0
- data/t/t0010-reap-logging.sh +55 -0
- data/t/t0012-reload-empty-config.sh +86 -0
- data/t/t0013-rewindable-input-false.sh +24 -0
- data/t/t0013.ru +13 -0
- data/t/t0014-rewindable-input-true.sh +24 -0
- data/t/t0014.ru +13 -0
- data/t/t0015-configurator-internals.sh +25 -0
- data/t/t0020-at_exit-handler.sh +49 -0
- data/t/t0021-process_detach.sh +29 -0
- data/t/t0022-listener_names-preload_app.sh +32 -0
- data/t/t0300-no-default-middleware.sh +20 -0
- data/t/t0301-no-default-middleware-ignored-in-config.sh +25 -0
- data/t/t0301.ru +14 -0
- data/t/t9001-oob_gc.sh +47 -0
- data/t/t9002-oob_gc-path.sh +75 -0
- data/t/test-lib.sh +125 -0
- data/t/winch_ttin.t +64 -0
- data/t/working_directory.t +86 -0
- data/test/aggregate.rb +16 -0
- data/test/benchmark/README +60 -0
- data/test/benchmark/dd.ru +19 -0
- data/test/benchmark/ddstream.ru +51 -0
- data/test/benchmark/readinput.ru +41 -0
- data/test/benchmark/stack.ru +9 -0
- data/test/benchmark/uconnect.perl +66 -0
- data/test/exec/README +5 -0
- data/test/exec/test_exec.rb +1030 -0
- data/test/test_helper.rb +307 -0
- data/test/unit/test_configurator.rb +176 -0
- data/test/unit/test_droplet.rb +29 -0
- data/test/unit/test_http_parser.rb +885 -0
- data/test/unit/test_http_parser_ng.rb +715 -0
- data/test/unit/test_server.rb +245 -0
- data/test/unit/test_signals.rb +189 -0
- data/test/unit/test_socket_helper.rb +160 -0
- data/test/unit/test_stream_input.rb +211 -0
- data/test/unit/test_tee_input.rb +304 -0
- data/test/unit/test_util.rb +132 -0
- data/test/unit/test_waiter.rb +35 -0
- data/unicorn.gemspec +49 -0
- metadata +266 -0
data/lib/unicorn/util.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
# frozen_string_literal: false
|
3
|
+
|
4
|
+
require 'fcntl'
|
5
|
+
module Unicorn::Util # :nodoc:
|
6
|
+
|
7
|
+
# :stopdoc:
|
8
|
+
def self.is_log?(fp)
|
9
|
+
append_flags = File::WRONLY | File::APPEND
|
10
|
+
|
11
|
+
! fp.closed? &&
|
12
|
+
fp.stat.file? &&
|
13
|
+
fp.sync &&
|
14
|
+
(fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
|
15
|
+
rescue IOError, Errno::EBADF
|
16
|
+
false
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.chown_logs(uid, gid)
|
20
|
+
ObjectSpace.each_object(File) do |fp|
|
21
|
+
fp.chown(uid, gid) if is_log?(fp)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
# :startdoc:
|
25
|
+
|
26
|
+
# This reopens ALL logfiles in the process that have been rotated
|
27
|
+
# using logrotate(8) (without copytruncate) or similar tools.
|
28
|
+
# A +File+ object is considered for reopening if it is:
|
29
|
+
# 1) opened with the O_APPEND and O_WRONLY flags
|
30
|
+
# 2) the current open file handle does not match its original open path
|
31
|
+
# 3) unbuffered (as far as userspace buffering goes, not O_SYNC)
|
32
|
+
# Returns the number of files reopened
|
33
|
+
#
|
34
|
+
# In Unicorn 3.5.x and earlier, files must be opened with an absolute
|
35
|
+
# path to be considered a log file.
|
36
|
+
def self.reopen_logs
|
37
|
+
to_reopen = []
|
38
|
+
nr = 0
|
39
|
+
ObjectSpace.each_object(File) { |fp| is_log?(fp) and to_reopen << fp }
|
40
|
+
|
41
|
+
to_reopen.each do |fp|
|
42
|
+
orig_st = begin
|
43
|
+
fp.stat
|
44
|
+
rescue IOError, Errno::EBADF # race
|
45
|
+
next
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
b = File.stat(fp.path)
|
50
|
+
next if orig_st.ino == b.ino && orig_st.dev == b.dev
|
51
|
+
rescue Errno::ENOENT
|
52
|
+
end
|
53
|
+
|
54
|
+
begin
|
55
|
+
# stdin, stdout, stderr are special. The following dance should
|
56
|
+
# guarantee there is no window where `fp' is unwritable in MRI
|
57
|
+
# (or any correct Ruby implementation).
|
58
|
+
#
|
59
|
+
# Fwiw, GVL has zero bearing here. This is tricky because of
|
60
|
+
# the unavoidable existence of stdio FILE * pointers for
|
61
|
+
# std{in,out,err} in all programs which may use the standard C library
|
62
|
+
if fp.fileno <= 2
|
63
|
+
# We do not want to hit fclose(3)->dup(2) window for std{in,out,err}
|
64
|
+
# MRI will use freopen(3) here internally on std{in,out,err}
|
65
|
+
fp.reopen(fp.path, "a")
|
66
|
+
else
|
67
|
+
# We should not need this workaround, Ruby can be fixed:
|
68
|
+
# https://bugs.ruby-lang.org/issues/9036
|
69
|
+
# MRI will not call call fclose(3) or freopen(3) here
|
70
|
+
# since there's no associated std{in,out,err} FILE * pointer
|
71
|
+
# This should atomically use dup3(2) (or dup2(2)) syscall
|
72
|
+
File.open(fp.path, "a") { |tmpfp| fp.reopen(tmpfp) }
|
73
|
+
end
|
74
|
+
|
75
|
+
fp.sync = true
|
76
|
+
fp.flush # IO#sync=true may not implicitly flush
|
77
|
+
new_st = fp.stat
|
78
|
+
|
79
|
+
# this should only happen in the master:
|
80
|
+
if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
|
81
|
+
fp.chown(orig_st.uid, orig_st.gid)
|
82
|
+
end
|
83
|
+
|
84
|
+
nr += 1
|
85
|
+
rescue IOError, Errno::EBADF
|
86
|
+
# not much we can do...
|
87
|
+
end
|
88
|
+
end
|
89
|
+
nr
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Unicorn::Const::UNICORN_VERSION = '6.1.0.68.ge9862.dirty'
|
@@ -0,0 +1,166 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
# frozen_string_literal: false
|
3
|
+
require "raindrops"
|
4
|
+
|
5
|
+
# This class and its members can be considered a stable interface
|
6
|
+
# and will not change in a backwards-incompatible fashion between
|
7
|
+
# releases of unicorn. Knowledge of this class is generally not
|
8
|
+
# not needed for most users of unicorn.
|
9
|
+
#
|
10
|
+
# Some users may want to access it in the before_fork/after_fork hooks.
|
11
|
+
# See the Unicorn::Configurator RDoc for examples.
|
12
|
+
class Unicorn::Worker
|
13
|
+
# :stopdoc:
|
14
|
+
attr_accessor :nr, :switched
|
15
|
+
attr_reader :to_io # IO.select-compatible
|
16
|
+
attr_reader :master
|
17
|
+
|
18
|
+
PER_DROP = Raindrops::PAGE_SIZE / Raindrops::SIZE
|
19
|
+
DROPS = []
|
20
|
+
|
21
|
+
def initialize(nr, pipe=nil)
|
22
|
+
drop_index = nr / PER_DROP
|
23
|
+
@raindrop = DROPS[drop_index] ||= Raindrops.new(PER_DROP)
|
24
|
+
@offset = nr % PER_DROP
|
25
|
+
@raindrop[@offset] = 0
|
26
|
+
@nr = nr
|
27
|
+
@switched = false
|
28
|
+
@to_io, @master = pipe || Unicorn.pipe
|
29
|
+
end
|
30
|
+
|
31
|
+
def atfork_child # :nodoc:
|
32
|
+
# we _must_ close in child, parent just holds this open to signal
|
33
|
+
@master = @master.close
|
34
|
+
end
|
35
|
+
|
36
|
+
# master fakes SIGQUIT using this
|
37
|
+
def quit # :nodoc:
|
38
|
+
@master = @master.close if @master
|
39
|
+
end
|
40
|
+
|
41
|
+
# parent does not read
|
42
|
+
def atfork_parent # :nodoc:
|
43
|
+
@to_io = @to_io.close
|
44
|
+
end
|
45
|
+
|
46
|
+
# call a signal handler immediately without triggering EINTR
|
47
|
+
# We do not use the more obvious Process.kill(sig, $$) here since
|
48
|
+
# that signal delivery may be deferred. We want to avoid signal delivery
|
49
|
+
# while the Rack app.call is running because some database drivers
|
50
|
+
# (e.g. ruby-pg) may cancel pending requests.
|
51
|
+
def fake_sig(sig) # :nodoc:
|
52
|
+
old_cb = trap(sig, "IGNORE")
|
53
|
+
old_cb.call
|
54
|
+
ensure
|
55
|
+
trap(sig, old_cb)
|
56
|
+
end
|
57
|
+
|
58
|
+
# master sends fake signals to children
|
59
|
+
def soft_kill(sig) # :nodoc:
|
60
|
+
case sig
|
61
|
+
when Integer
|
62
|
+
signum = sig
|
63
|
+
else
|
64
|
+
signum = Signal.list[sig.to_s] or
|
65
|
+
raise ArgumentError, "BUG: bad signal: #{sig.inspect}"
|
66
|
+
end
|
67
|
+
# writing and reading 4 bytes on a pipe is atomic on all POSIX platforms
|
68
|
+
# Do not care in the odd case the buffer is full, here.
|
69
|
+
@master.write_nonblock([signum].pack('l'), exception: false)
|
70
|
+
rescue Errno::EPIPE
|
71
|
+
# worker will be reaped soon
|
72
|
+
end
|
73
|
+
|
74
|
+
# this only runs when the Rack app.call is not running
|
75
|
+
# act like Socket#accept_nonblock(exception: false)
|
76
|
+
def accept_nonblock(*_unused) # :nodoc:
|
77
|
+
case buf = @to_io.read_nonblock(4, exception: false)
|
78
|
+
when String
|
79
|
+
# unpack the buffer and trigger the signal handler
|
80
|
+
signum = buf.unpack('l')
|
81
|
+
fake_sig(signum[0])
|
82
|
+
# keep looping, more signals may be queued
|
83
|
+
when nil # EOF: master died, but we are at a safe place to exit
|
84
|
+
fake_sig(:QUIT)
|
85
|
+
when :wait_readable # keep waiting
|
86
|
+
return :wait_readable
|
87
|
+
end while true # loop, as multiple signals may be sent
|
88
|
+
end
|
89
|
+
|
90
|
+
# worker objects may be compared to just plain Integers
|
91
|
+
def ==(other_nr) # :nodoc:
|
92
|
+
@nr == other_nr
|
93
|
+
end
|
94
|
+
|
95
|
+
# called in the worker process
|
96
|
+
def tick=(value) # :nodoc:
|
97
|
+
@raindrop[@offset] = value
|
98
|
+
end
|
99
|
+
|
100
|
+
# called in the master process
|
101
|
+
def tick # :nodoc:
|
102
|
+
@raindrop[@offset]
|
103
|
+
end
|
104
|
+
|
105
|
+
# called in both the master (reaping worker) and worker (SIGQUIT handler)
|
106
|
+
def close # :nodoc:
|
107
|
+
@master.close if @master
|
108
|
+
@to_io.close if @to_io
|
109
|
+
end
|
110
|
+
|
111
|
+
# :startdoc:
|
112
|
+
|
113
|
+
# In most cases, you should be using the Unicorn::Configurator#user
|
114
|
+
# directive instead. This method should only be used if you need
|
115
|
+
# fine-grained control of exactly when you want to change permissions
|
116
|
+
# in your after_fork or after_worker_ready hooks, or if you want to
|
117
|
+
# use the chroot support.
|
118
|
+
#
|
119
|
+
# Changes the worker process to the specified +user+ and +group+,
|
120
|
+
# and chroots to the current working directory if +chroot+ is set.
|
121
|
+
# This is only intended to be called from within the worker
|
122
|
+
# process from the +after_fork+ hook. This should be called in
|
123
|
+
# the +after_fork+ hook after any privileged functions need to be
|
124
|
+
# run (e.g. to set per-worker CPU affinity, niceness, etc)
|
125
|
+
#
|
126
|
+
# +group+ can be specified as a string, or as an array of two
|
127
|
+
# strings. If an array of two strings is given, the first string
|
128
|
+
# is used as the primary group of the process, and the second is
|
129
|
+
# used as the group of the log files.
|
130
|
+
#
|
131
|
+
# Any and all errors raised within this method will be propagated
|
132
|
+
# directly back to the caller (usually the +after_fork+ hook.
|
133
|
+
# These errors commonly include ArgumentError for specifying an
|
134
|
+
# invalid user/group and Errno::EPERM for insufficient privileges.
|
135
|
+
#
|
136
|
+
# chroot support is only available in unicorn 5.3.0+
|
137
|
+
# user and group switching appeared in unicorn 0.94.0 (2009-11-05)
|
138
|
+
def user(user, group = nil, chroot = false)
|
139
|
+
# we do not protect the caller, checking Process.euid == 0 is
|
140
|
+
# insufficient because modern systems have fine-grained
|
141
|
+
# capabilities. Let the caller handle any and all errors.
|
142
|
+
uid = Etc.getpwnam(user).uid
|
143
|
+
|
144
|
+
if group
|
145
|
+
if group.is_a?(Array)
|
146
|
+
group, log_group = group
|
147
|
+
log_gid = Etc.getgrnam(log_group).gid
|
148
|
+
end
|
149
|
+
gid = Etc.getgrnam(group).gid
|
150
|
+
log_gid ||= gid
|
151
|
+
end
|
152
|
+
|
153
|
+
Unicorn::Util.chown_logs(uid, log_gid)
|
154
|
+
if gid && Process.egid != gid
|
155
|
+
Process.initgroups(user, gid)
|
156
|
+
Process::GID.change_privilege(gid)
|
157
|
+
end
|
158
|
+
if chroot
|
159
|
+
chroot = Dir.pwd if chroot == true
|
160
|
+
Dir.chroot(chroot)
|
161
|
+
Dir.chdir('/')
|
162
|
+
end
|
163
|
+
Process.euid != uid and Process::UID.change_privilege(uid)
|
164
|
+
@switched = true
|
165
|
+
end
|
166
|
+
end
|
data/lib/unicorn.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
# frozen_string_literal: false
|
3
|
+
require 'etc'
|
4
|
+
require 'stringio'
|
5
|
+
require 'raindrops'
|
6
|
+
require 'io/wait'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'rack'
|
10
|
+
rescue LoadError
|
11
|
+
warn 'rack not available, functionality reduced'
|
12
|
+
end
|
13
|
+
|
14
|
+
# :stopdoc:
|
15
|
+
# Unicorn module containing all of the classes (include C extensions) for
|
16
|
+
# running a Unicorn web server. It contains a minimalist HTTP server with just
|
17
|
+
# enough functionality to service web application requests fast as possible.
|
18
|
+
# :startdoc:
|
19
|
+
|
20
|
+
# unicorn exposes very little of an user-visible API and most of its
|
21
|
+
# internals are subject to change. unicorn is designed to host Rack
|
22
|
+
# applications, so applications should be written against the Rack SPEC
|
23
|
+
# and not unicorn internals.
|
24
|
+
module Unicorn
|
25
|
+
|
26
|
+
# Raised inside TeeInput when a client closes the socket inside the
|
27
|
+
# application dispatch. This is always raised with an empty backtrace
|
28
|
+
# since there is nothing in the application stack that is responsible
|
29
|
+
# for client shutdowns/disconnects. This exception is visible to Rack
|
30
|
+
# applications unless PrereadInput middleware is loaded. This
|
31
|
+
# is a subclass of the standard EOFError class and applications should
|
32
|
+
# not rescue it explicitly, but rescue EOFError instead.
|
33
|
+
ClientShutdown = Class.new(EOFError)
|
34
|
+
|
35
|
+
# :stopdoc:
|
36
|
+
|
37
|
+
# This returns a lambda to pass in as the app, this does not "build" the
|
38
|
+
# app (which we defer based on the outcome of "preload_app" in the
|
39
|
+
# Unicorn config). The returned lambda will be called when it is
|
40
|
+
# time to build the app.
|
41
|
+
def self.builder(ru, op)
|
42
|
+
# allow Configurator to parse cli switches embedded in the ru file
|
43
|
+
op = Unicorn::Configurator::RACKUP.merge!(:file => ru, :optparse => op)
|
44
|
+
if ru =~ /\.ru$/ && !defined?(Rack::Builder)
|
45
|
+
abort "rack and Rack::Builder must be available for processing #{ru}"
|
46
|
+
end
|
47
|
+
|
48
|
+
# always called after config file parsing, may be called after forking
|
49
|
+
lambda do |_, server|
|
50
|
+
inner_app = case ru
|
51
|
+
when /\.ru$/
|
52
|
+
raw = File.read(ru)
|
53
|
+
raw.sub!(/^__END__\n.*/, '')
|
54
|
+
eval("Rack::Builder.new {(\n#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru)
|
55
|
+
else
|
56
|
+
require ru
|
57
|
+
Object.const_get(File.basename(ru, '.rb').capitalize)
|
58
|
+
end
|
59
|
+
|
60
|
+
if $DEBUG
|
61
|
+
require 'pp'
|
62
|
+
pp({ :inner_app => inner_app })
|
63
|
+
end
|
64
|
+
|
65
|
+
return inner_app unless server.default_middleware
|
66
|
+
|
67
|
+
middleware = { # order matters
|
68
|
+
ContentLength: nil,
|
69
|
+
CommonLogger: [ $stderr ],
|
70
|
+
ShowExceptions: nil,
|
71
|
+
Lint: nil,
|
72
|
+
TempfileReaper: nil,
|
73
|
+
}
|
74
|
+
|
75
|
+
# return value, matches rackup defaults based on env
|
76
|
+
# Unicorn does not support persistent connections, but Rainbows!
|
77
|
+
# does. Users accustomed to the Rack::Server default
|
78
|
+
# middlewares will need ContentLength middleware.
|
79
|
+
case ENV["RACK_ENV"]
|
80
|
+
when "development"
|
81
|
+
when "deployment"
|
82
|
+
middleware.delete(:ShowExceptions)
|
83
|
+
middleware.delete(:Lint)
|
84
|
+
else
|
85
|
+
return inner_app
|
86
|
+
end
|
87
|
+
Rack::Builder.new do
|
88
|
+
middleware.each do |m, args|
|
89
|
+
use(Rack.const_get(m), *args) if Rack.const_defined?(m)
|
90
|
+
end
|
91
|
+
run inner_app
|
92
|
+
end.to_app
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# returns an array of strings representing TCP listen socket addresses
|
97
|
+
# and Unix domain socket paths. This is useful for use with
|
98
|
+
# Raindrops::Middleware under Linux: https://yhbt.net/raindrops/
|
99
|
+
def self.listener_names
|
100
|
+
Unicorn::HttpServer::LISTENERS.map do |io|
|
101
|
+
Unicorn::SocketHelper.sock_name(io)
|
102
|
+
end + Unicorn::HttpServer::NEW_LISTENERS
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.log_error(logger, prefix, exc)
|
106
|
+
message = exc.message
|
107
|
+
message = message.dump if /[[:cntrl:]]/ =~ message
|
108
|
+
logger.error "#{prefix}: #{message} (#{exc.class})"
|
109
|
+
exc.backtrace.each { |line| logger.error(line) }
|
110
|
+
end
|
111
|
+
|
112
|
+
F_SETPIPE_SZ = 1031 if RUBY_PLATFORM =~ /linux/
|
113
|
+
|
114
|
+
def self.pipe # :nodoc:
|
115
|
+
IO.pipe.each do |io|
|
116
|
+
# shrink pipes to minimize impact on /proc/sys/fs/pipe-user-pages-soft
|
117
|
+
# limits.
|
118
|
+
if defined?(F_SETPIPE_SZ)
|
119
|
+
begin
|
120
|
+
io.fcntl(F_SETPIPE_SZ, Raindrops::PAGE_SIZE)
|
121
|
+
rescue Errno::EINVAL
|
122
|
+
# old kernel
|
123
|
+
rescue Errno::EPERM
|
124
|
+
# resizes fail if Linux is close to the pipe limit for the user
|
125
|
+
# or if the user does not have permissions to resize
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
# :startdoc:
|
131
|
+
end
|
132
|
+
# :enddoc:
|
133
|
+
|
134
|
+
%w(const socket_helper stream_input tee_input http_request configurator
|
135
|
+
tmpio util http_response worker http_server).each do |s|
|
136
|
+
require_relative "unicorn/#{s}"
|
137
|
+
end
|
data/man/man1/unicorn.1
ADDED
@@ -0,0 +1,222 @@
|
|
1
|
+
.TH "UNICORN" "1" "September 15, 2009" "Unicorn User Manual" ""
|
2
|
+
.hy
|
3
|
+
.SH NAME
|
4
|
+
.PP
|
5
|
+
unicorn \- a rackup\-like command to launch the Unicorn HTTP server
|
6
|
+
.SH SYNOPSIS
|
7
|
+
.PP
|
8
|
+
unicorn [\-c CONFIG_FILE] [\-E RACK_ENV] [\-D] [RACKUP_FILE]
|
9
|
+
.SH DESCRIPTION
|
10
|
+
.PP
|
11
|
+
A rackup(1)\-like command to launch Rack applications using Unicorn.
|
12
|
+
It is expected to be started in your application root (APP_ROOT),
|
13
|
+
but the "working_directory" directive may be used in the CONFIG_FILE.
|
14
|
+
.PP
|
15
|
+
While unicorn takes a myriad of command\-line options for
|
16
|
+
compatibility with ruby(1) and rackup(1), it is recommended to stick
|
17
|
+
to the few command\-line options specified in the SYNOPSIS and use
|
18
|
+
the CONFIG_FILE as much as possible.
|
19
|
+
.SH RACKUP FILE
|
20
|
+
.PP
|
21
|
+
This defaults to "config.ru" in APP_ROOT. It should be the same
|
22
|
+
file used by rackup(1) and other Rack launchers, it uses the
|
23
|
+
\f[I]Rack::Builder\f[] DSL.
|
24
|
+
.PP
|
25
|
+
Embedded command\-line options are mostly parsed for compatibility
|
26
|
+
with rackup(1) but strongly discouraged.
|
27
|
+
.SH UNICORN OPTIONS
|
28
|
+
.TP
|
29
|
+
.B \-c, \-\-config\-file CONFIG_FILE
|
30
|
+
Path to the Unicorn\-specific config file. The config file is
|
31
|
+
implemented as a Ruby DSL, so Ruby code may executed.
|
32
|
+
See the RDoc/ri for the \f[I]Unicorn::Configurator\f[] class for the full
|
33
|
+
list of directives available from the DSL.
|
34
|
+
Using an absolute path for for CONFIG_FILE is recommended as it
|
35
|
+
makes multiple instances of Unicorn easily distinguishable when
|
36
|
+
viewing ps(1) output.
|
37
|
+
.RS
|
38
|
+
.RE
|
39
|
+
.TP
|
40
|
+
.B \-D, \-\-daemonize
|
41
|
+
Run daemonized in the background. The process is detached from
|
42
|
+
the controlling terminal and stdin is redirected to "/dev/null".
|
43
|
+
Unlike many common UNIX daemons, we do not chdir to "/"
|
44
|
+
upon daemonization to allow more control over the startup/upgrade
|
45
|
+
process.
|
46
|
+
Unless specified in the CONFIG_FILE, stderr and stdout will
|
47
|
+
also be redirected to "/dev/null".
|
48
|
+
.RS
|
49
|
+
.RE
|
50
|
+
.TP
|
51
|
+
.B \-E, \-\-env RACK_ENV
|
52
|
+
Run under the given RACK_ENV. See the RACK ENVIRONMENT section
|
53
|
+
for more details.
|
54
|
+
.RS
|
55
|
+
.RE
|
56
|
+
.TP
|
57
|
+
.B \-l, \-\-listen ADDRESS
|
58
|
+
Listens on a given ADDRESS. ADDRESS may be in the form of
|
59
|
+
HOST:PORT or PATH, HOST:PORT is taken to mean a TCP socket
|
60
|
+
and PATH is meant to be a path to a UNIX domain socket.
|
61
|
+
Defaults to "0.0.0.0:8080" (all addresses on TCP port 8080)
|
62
|
+
For production deployments, specifying the "listen" directive in
|
63
|
+
CONFIG_FILE is recommended as it allows fine\-tuning of socket
|
64
|
+
options.
|
65
|
+
.RS
|
66
|
+
.RE
|
67
|
+
.TP
|
68
|
+
.B \-N, \-\-no\-default\-middleware
|
69
|
+
Disables loading middleware implied by RACK_ENV. This bypasses the
|
70
|
+
configuration documented in the RACK ENVIRONMENT section, but still
|
71
|
+
allows RACK_ENV to be used for application/framework\-specific purposes.
|
72
|
+
.RS
|
73
|
+
.RE
|
74
|
+
.SH RACKUP COMPATIBILITY OPTIONS
|
75
|
+
.TP
|
76
|
+
.B \-o, \-\-host HOST
|
77
|
+
Listen on a TCP socket belonging to HOST, default is
|
78
|
+
"0.0.0.0" (all addresses).
|
79
|
+
If specified multiple times on the command\-line, only the
|
80
|
+
last\-specified value takes effect.
|
81
|
+
This option only exists for compatibility with the rackup(1) command,
|
82
|
+
use of "\-l"/"\-\-listen" switch is recommended instead.
|
83
|
+
.RS
|
84
|
+
.RE
|
85
|
+
.TP
|
86
|
+
.B \-p, \-\-port PORT
|
87
|
+
Listen on the specified TCP PORT, default is 8080.
|
88
|
+
If specified multiple times on the command\-line, only the last\-specified
|
89
|
+
value takes effect.
|
90
|
+
This option only exists for compatibility with the rackup(1) command,
|
91
|
+
use of "\-l"/"\-\-listen" switch is recommended instead.
|
92
|
+
.RS
|
93
|
+
.RE
|
94
|
+
.TP
|
95
|
+
.B \-s, \-\-server SERVER
|
96
|
+
No\-op, this exists only for compatibility with rackup(1).
|
97
|
+
.RS
|
98
|
+
.RE
|
99
|
+
.SH RUBY OPTIONS
|
100
|
+
.TP
|
101
|
+
.B \-e, \-\-eval LINE
|
102
|
+
Evaluate a LINE of Ruby code. This evaluation happens
|
103
|
+
immediately as the command\-line is being parsed.
|
104
|
+
.RS
|
105
|
+
.RE
|
106
|
+
.TP
|
107
|
+
.B \-d, \-\-debug
|
108
|
+
Turn on debug mode, the $DEBUG variable is set to true.
|
109
|
+
.RS
|
110
|
+
.RE
|
111
|
+
.TP
|
112
|
+
.B \-w, \-\-warn
|
113
|
+
Turn on verbose warnings, the $VERBOSE variable is set to true.
|
114
|
+
.RS
|
115
|
+
.RE
|
116
|
+
.TP
|
117
|
+
.B \-I, \-\-include PATH
|
118
|
+
specify $LOAD_PATH. PATH will be prepended to $LOAD_PATH.
|
119
|
+
The \[aq]:\[aq] character may be used to delimit multiple directories.
|
120
|
+
This directive may be used more than once. Modifications to
|
121
|
+
$LOAD_PATH take place immediately and in the order they were
|
122
|
+
specified on the command\-line.
|
123
|
+
.RS
|
124
|
+
.RE
|
125
|
+
.TP
|
126
|
+
.B \-r, \-\-require LIBRARY
|
127
|
+
require a specified LIBRARY before executing the application. The
|
128
|
+
"require" statement will be executed immediately and in the order
|
129
|
+
they were specified on the command\-line.
|
130
|
+
.RS
|
131
|
+
.RE
|
132
|
+
.SH SIGNALS
|
133
|
+
.PP
|
134
|
+
The following UNIX signals may be sent to the master process:
|
135
|
+
.IP \[bu] 2
|
136
|
+
HUP \- reload config file, app, and gracefully restart all workers
|
137
|
+
.IP \[bu] 2
|
138
|
+
INT/TERM \- quick shutdown, kills all workers immediately
|
139
|
+
.IP \[bu] 2
|
140
|
+
QUIT \- graceful shutdown, waits for workers to finish their
|
141
|
+
current request before finishing.
|
142
|
+
.IP \[bu] 2
|
143
|
+
USR1 \- reopen all logs owned by the master and all workers
|
144
|
+
See Unicorn::Util.reopen_logs for what is considered a log.
|
145
|
+
.IP \[bu] 2
|
146
|
+
USR2 \- reexecute the running binary. A separate QUIT
|
147
|
+
should be sent to the original process once the child is verified to
|
148
|
+
be up and running.
|
149
|
+
.IP \[bu] 2
|
150
|
+
WINCH \- gracefully stops workers but keep the master running.
|
151
|
+
This will only work for daemonized processes.
|
152
|
+
.IP \[bu] 2
|
153
|
+
TTIN \- increment the number of worker processes by one
|
154
|
+
.IP \[bu] 2
|
155
|
+
TTOU \- decrement the number of worker processes by one
|
156
|
+
.PP
|
157
|
+
See the SIGNALS (https://yhbt.net/unicorn/SIGNALS.html) document for
|
158
|
+
full description of all signals used by Unicorn.
|
159
|
+
.SH RACK ENVIRONMENT
|
160
|
+
.PP
|
161
|
+
Accepted values of RACK_ENV and the middleware they automatically load
|
162
|
+
(outside of RACKUP_FILE) are exactly as those in rackup(1):
|
163
|
+
.IP \[bu] 2
|
164
|
+
development \- loads Rack::CommonLogger, Rack::ShowExceptions, and
|
165
|
+
Rack::Lint middleware
|
166
|
+
.IP \[bu] 2
|
167
|
+
deployment \- loads Rack::CommonLogger middleware
|
168
|
+
.IP \[bu] 2
|
169
|
+
none \- loads no middleware at all, relying entirely on RACKUP_FILE
|
170
|
+
.PP
|
171
|
+
All unrecognized values for RACK_ENV are assumed to be
|
172
|
+
"none". Production deployments are strongly encouraged to use
|
173
|
+
"deployment" or "none" for maximum performance.
|
174
|
+
.PP
|
175
|
+
As of Unicorn 0.94.0, RACK_ENV is exported as a process\-wide environment
|
176
|
+
variable as well. While not current a part of the Rack specification as
|
177
|
+
of Rack 1.0.1, this has become a de facto standard in the Rack world.
|
178
|
+
.PP
|
179
|
+
Note the Rack::ContentLength middleware is also
|
180
|
+
loaded by "deployment" and "development", but no other values of
|
181
|
+
RACK_ENV. If needed, they must be individually specified in the
|
182
|
+
RACKUP_FILE, some frameworks do not require them.
|
183
|
+
.SH ENVIRONMENT VARIABLES
|
184
|
+
.PP
|
185
|
+
The RACK_ENV variable is set by the aforementioned \-E switch.
|
186
|
+
All application or library\-specific environment variables (e.g. TMPDIR)
|
187
|
+
may always be set in the Unicorn CONFIG_FILE in addition to the spawning
|
188
|
+
shell. When transparently upgrading Unicorn, all environment variables
|
189
|
+
set in the old master process are inherited by the new master process.
|
190
|
+
Unicorn only uses (and will overwrite) the UNICORN_FD environment
|
191
|
+
variable internally when doing transparent upgrades.
|
192
|
+
.PP
|
193
|
+
UNICORN_FD is a comma\-delimited list of one or more file descriptors
|
194
|
+
used to implement USR2 upgrades. Init systems may bind listen sockets
|
195
|
+
itself and spawn unicorn with UNICORN_FD set to the file descriptor
|
196
|
+
numbers of the listen socket(s).
|
197
|
+
.PP
|
198
|
+
As of unicorn 5.0, LISTEN_PID and LISTEN_FDS are used for socket
|
199
|
+
activation as documented in the sd_listen_fds(3) manpage. Users
|
200
|
+
relying on this feature do not need to specify a listen socket in
|
201
|
+
the unicorn config file.
|
202
|
+
.SH SEE ALSO
|
203
|
+
.IP \[bu] 2
|
204
|
+
\f[I]Rack::Builder\f[] ri/RDoc
|
205
|
+
.IP \[bu] 2
|
206
|
+
\f[I]Unicorn::Configurator\f[] ri/RDoc
|
207
|
+
.UR https://yhbt.net/unicorn/Unicorn/Configurator.html
|
208
|
+
.UE
|
209
|
+
.IP \[bu] 2
|
210
|
+
unicorn RDoc
|
211
|
+
.UR https://yhbt.net/unicorn/
|
212
|
+
.UE
|
213
|
+
.IP \[bu] 2
|
214
|
+
Rack RDoc
|
215
|
+
.UR https://www.rubydoc.info/github/rack/rack/
|
216
|
+
.UE
|
217
|
+
.IP \[bu] 2
|
218
|
+
Rackup HowTo
|
219
|
+
.UR https://github.com/rack/rack/wiki/(tutorial)-rackup-howto
|
220
|
+
.UE
|
221
|
+
.SH AUTHORS
|
222
|
+
The Unicorn Community <unicorn-public@yhbt.net>.
|