unicorn-maintained 6.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) 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 +149 -0
  8. data/.olddoc.yml +25 -0
  9. data/Application_Timeouts +77 -0
  10. data/CONTRIBUTORS +39 -0
  11. data/COPYING +674 -0
  12. data/DESIGN +99 -0
  13. data/Documentation/.gitignore +3 -0
  14. data/Documentation/unicorn.1 +222 -0
  15. data/Documentation/unicorn_rails.1 +207 -0
  16. data/FAQ +70 -0
  17. data/GIT-VERSION-FILE +1 -0
  18. data/GIT-VERSION-GEN +39 -0
  19. data/GNUmakefile +317 -0
  20. data/HACKING +112 -0
  21. data/ISSUES +102 -0
  22. data/KNOWN_ISSUES +79 -0
  23. data/LATEST +1 -0
  24. data/LICENSE +67 -0
  25. data/Links +58 -0
  26. data/NEWS +1 -0
  27. data/PHILOSOPHY +139 -0
  28. data/README +156 -0
  29. data/Rakefile +16 -0
  30. data/SIGNALS +123 -0
  31. data/Sandbox +104 -0
  32. data/TODO +3 -0
  33. data/TUNING +119 -0
  34. data/archive/.gitignore +3 -0
  35. data/archive/slrnpull.conf +4 -0
  36. data/bin/unicorn +128 -0
  37. data/bin/unicorn_rails +209 -0
  38. data/examples/big_app_gc.rb +2 -0
  39. data/examples/echo.ru +26 -0
  40. data/examples/init.sh +102 -0
  41. data/examples/logger_mp_safe.rb +25 -0
  42. data/examples/logrotate.conf +44 -0
  43. data/examples/nginx.conf +156 -0
  44. data/examples/unicorn.conf.minimal.rb +13 -0
  45. data/examples/unicorn.conf.rb +110 -0
  46. data/examples/unicorn.socket +11 -0
  47. data/examples/unicorn@.service +40 -0
  48. data/ext/unicorn_http/CFLAGS +13 -0
  49. data/ext/unicorn_http/c_util.h +116 -0
  50. data/ext/unicorn_http/common_field_optimization.h +128 -0
  51. data/ext/unicorn_http/epollexclusive.h +128 -0
  52. data/ext/unicorn_http/ext_help.h +38 -0
  53. data/ext/unicorn_http/extconf.rb +39 -0
  54. data/ext/unicorn_http/global_variables.h +97 -0
  55. data/ext/unicorn_http/httpdate.c +91 -0
  56. data/ext/unicorn_http/unicorn_http.c +4334 -0
  57. data/ext/unicorn_http/unicorn_http.rl +1040 -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 +748 -0
  63. data/lib/unicorn/const.rb +21 -0
  64. data/lib/unicorn/http_request.rb +201 -0
  65. data/lib/unicorn/http_response.rb +93 -0
  66. data/lib/unicorn/http_server.rb +859 -0
  67. data/lib/unicorn/launcher.rb +62 -0
  68. data/lib/unicorn/oob_gc.rb +81 -0
  69. data/lib/unicorn/preread_input.rb +33 -0
  70. data/lib/unicorn/select_waiter.rb +6 -0
  71. data/lib/unicorn/socket_helper.rb +185 -0
  72. data/lib/unicorn/stream_input.rb +151 -0
  73. data/lib/unicorn/tee_input.rb +131 -0
  74. data/lib/unicorn/tmpio.rb +33 -0
  75. data/lib/unicorn/util.rb +90 -0
  76. data/lib/unicorn/version.rb +1 -0
  77. data/lib/unicorn/worker.rb +165 -0
  78. data/lib/unicorn.rb +136 -0
  79. data/man/man1/unicorn.1 +222 -0
  80. data/man/man1/unicorn_rails.1 +207 -0
  81. data/setup.rb +1586 -0
  82. data/t/.gitignore +4 -0
  83. data/t/GNUmakefile +5 -0
  84. data/t/README +49 -0
  85. data/t/active-unix-socket.t +117 -0
  86. data/t/bin/unused_listen +40 -0
  87. data/t/broken-app.ru +12 -0
  88. data/t/client_body_buffer_size.ru +14 -0
  89. data/t/client_body_buffer_size.t +80 -0
  90. data/t/detach.ru +11 -0
  91. data/t/env.ru +3 -0
  92. data/t/fails-rack-lint.ru +5 -0
  93. data/t/heartbeat-timeout.ru +12 -0
  94. data/t/heartbeat-timeout.t +62 -0
  95. data/t/integration.ru +115 -0
  96. data/t/integration.t +356 -0
  97. data/t/lib.perl +258 -0
  98. data/t/listener_names.ru +4 -0
  99. data/t/my-tap-lib.sh +201 -0
  100. data/t/oob_gc.ru +17 -0
  101. data/t/oob_gc_path.ru +17 -0
  102. data/t/pid.ru +3 -0
  103. data/t/preread_input.ru +22 -0
  104. data/t/reload-bad-config.t +54 -0
  105. data/t/reopen-logs.ru +13 -0
  106. data/t/reopen-logs.t +39 -0
  107. data/t/t0008-back_out_of_upgrade.sh +110 -0
  108. data/t/t0009-broken-app.sh +56 -0
  109. data/t/t0010-reap-logging.sh +55 -0
  110. data/t/t0012-reload-empty-config.sh +86 -0
  111. data/t/t0013-rewindable-input-false.sh +24 -0
  112. data/t/t0013.ru +12 -0
  113. data/t/t0014-rewindable-input-true.sh +24 -0
  114. data/t/t0014.ru +12 -0
  115. data/t/t0015-configurator-internals.sh +25 -0
  116. data/t/t0020-at_exit-handler.sh +49 -0
  117. data/t/t0021-process_detach.sh +29 -0
  118. data/t/t0022-listener_names-preload_app.sh +32 -0
  119. data/t/t0300-no-default-middleware.sh +20 -0
  120. data/t/t0301-no-default-middleware-ignored-in-config.sh +25 -0
  121. data/t/t0301.ru +13 -0
  122. data/t/t9001-oob_gc.sh +47 -0
  123. data/t/t9002-oob_gc-path.sh +75 -0
  124. data/t/test-lib.sh +125 -0
  125. data/t/winch_ttin.t +67 -0
  126. data/t/working_directory.t +94 -0
  127. data/test/aggregate.rb +15 -0
  128. data/test/benchmark/README +60 -0
  129. data/test/benchmark/dd.ru +18 -0
  130. data/test/benchmark/ddstream.ru +50 -0
  131. data/test/benchmark/readinput.ru +40 -0
  132. data/test/benchmark/stack.ru +8 -0
  133. data/test/benchmark/uconnect.perl +66 -0
  134. data/test/exec/README +5 -0
  135. data/test/exec/test_exec.rb +1029 -0
  136. data/test/test_helper.rb +306 -0
  137. data/test/unit/test_ccc.rb +91 -0
  138. data/test/unit/test_configurator.rb +175 -0
  139. data/test/unit/test_droplet.rb +28 -0
  140. data/test/unit/test_http_parser.rb +884 -0
  141. data/test/unit/test_http_parser_ng.rb +714 -0
  142. data/test/unit/test_request.rb +169 -0
  143. data/test/unit/test_server.rb +244 -0
  144. data/test/unit/test_signals.rb +188 -0
  145. data/test/unit/test_socket_helper.rb +159 -0
  146. data/test/unit/test_stream_input.rb +210 -0
  147. data/test/unit/test_tee_input.rb +303 -0
  148. data/test/unit/test_util.rb +131 -0
  149. data/test/unit/test_waiter.rb +34 -0
  150. data/unicorn.gemspec +48 -0
  151. metadata +275 -0
@@ -0,0 +1,90 @@
1
+ # -*- encoding: binary -*-
2
+
3
+ require 'fcntl'
4
+ module Unicorn::Util # :nodoc:
5
+
6
+ # :stopdoc:
7
+ def self.is_log?(fp)
8
+ append_flags = File::WRONLY | File::APPEND
9
+
10
+ ! fp.closed? &&
11
+ fp.stat.file? &&
12
+ fp.sync &&
13
+ (fp.fcntl(Fcntl::F_GETFL) & append_flags) == append_flags
14
+ rescue IOError, Errno::EBADF
15
+ false
16
+ end
17
+
18
+ def self.chown_logs(uid, gid)
19
+ ObjectSpace.each_object(File) do |fp|
20
+ fp.chown(uid, gid) if is_log?(fp)
21
+ end
22
+ end
23
+ # :startdoc:
24
+
25
+ # This reopens ALL logfiles in the process that have been rotated
26
+ # using logrotate(8) (without copytruncate) or similar tools.
27
+ # A +File+ object is considered for reopening if it is:
28
+ # 1) opened with the O_APPEND and O_WRONLY flags
29
+ # 2) the current open file handle does not match its original open path
30
+ # 3) unbuffered (as far as userspace buffering goes, not O_SYNC)
31
+ # Returns the number of files reopened
32
+ #
33
+ # In Unicorn 3.5.x and earlier, files must be opened with an absolute
34
+ # path to be considered a log file.
35
+ def self.reopen_logs
36
+ to_reopen = []
37
+ nr = 0
38
+ ObjectSpace.each_object(File) { |fp| is_log?(fp) and to_reopen << fp }
39
+
40
+ to_reopen.each do |fp|
41
+ orig_st = begin
42
+ fp.stat
43
+ rescue IOError, Errno::EBADF # race
44
+ next
45
+ end
46
+
47
+ begin
48
+ b = File.stat(fp.path)
49
+ next if orig_st.ino == b.ino && orig_st.dev == b.dev
50
+ rescue Errno::ENOENT
51
+ end
52
+
53
+ begin
54
+ # stdin, stdout, stderr are special. The following dance should
55
+ # guarantee there is no window where `fp' is unwritable in MRI
56
+ # (or any correct Ruby implementation).
57
+ #
58
+ # Fwiw, GVL has zero bearing here. This is tricky because of
59
+ # the unavoidable existence of stdio FILE * pointers for
60
+ # std{in,out,err} in all programs which may use the standard C library
61
+ if fp.fileno <= 2
62
+ # We do not want to hit fclose(3)->dup(2) window for std{in,out,err}
63
+ # MRI will use freopen(3) here internally on std{in,out,err}
64
+ fp.reopen(fp.path, "a")
65
+ else
66
+ # We should not need this workaround, Ruby can be fixed:
67
+ # https://bugs.ruby-lang.org/issues/9036
68
+ # MRI will not call call fclose(3) or freopen(3) here
69
+ # since there's no associated std{in,out,err} FILE * pointer
70
+ # This should atomically use dup3(2) (or dup2(2)) syscall
71
+ File.open(fp.path, "a") { |tmpfp| fp.reopen(tmpfp) }
72
+ end
73
+
74
+ fp.sync = true
75
+ fp.flush # IO#sync=true may not implicitly flush
76
+ new_st = fp.stat
77
+
78
+ # this should only happen in the master:
79
+ if orig_st.uid != new_st.uid || orig_st.gid != new_st.gid
80
+ fp.chown(orig_st.uid, orig_st.gid)
81
+ end
82
+
83
+ nr += 1
84
+ rescue IOError, Errno::EBADF
85
+ # not much we can do...
86
+ end
87
+ end
88
+ nr
89
+ end
90
+ end
@@ -0,0 +1 @@
1
+ Unicorn::Const::UNICORN_VERSION = '6.2.0'
@@ -0,0 +1,165 @@
1
+ # -*- encoding: binary -*-
2
+ require "raindrops"
3
+
4
+ # This class and its members can be considered a stable interface
5
+ # and will not change in a backwards-incompatible fashion between
6
+ # releases of unicorn. Knowledge of this class is generally not
7
+ # not needed for most users of unicorn.
8
+ #
9
+ # Some users may want to access it in the before_fork/after_fork hooks.
10
+ # See the Unicorn::Configurator RDoc for examples.
11
+ class Unicorn::Worker
12
+ # :stopdoc:
13
+ attr_accessor :nr, :switched
14
+ attr_reader :to_io # IO.select-compatible
15
+ attr_reader :master
16
+
17
+ PER_DROP = Raindrops::PAGE_SIZE / Raindrops::SIZE
18
+ DROPS = []
19
+
20
+ def initialize(nr, pipe=nil)
21
+ drop_index = nr / PER_DROP
22
+ @raindrop = DROPS[drop_index] ||= Raindrops.new(PER_DROP)
23
+ @offset = nr % PER_DROP
24
+ @raindrop[@offset] = 0
25
+ @nr = nr
26
+ @switched = false
27
+ @to_io, @master = pipe || Unicorn.pipe
28
+ end
29
+
30
+ def atfork_child # :nodoc:
31
+ # we _must_ close in child, parent just holds this open to signal
32
+ @master = @master.close
33
+ end
34
+
35
+ # master fakes SIGQUIT using this
36
+ def quit # :nodoc:
37
+ @master = @master.close if @master
38
+ end
39
+
40
+ # parent does not read
41
+ def atfork_parent # :nodoc:
42
+ @to_io = @to_io.close
43
+ end
44
+
45
+ # call a signal handler immediately without triggering EINTR
46
+ # We do not use the more obvious Process.kill(sig, $$) here since
47
+ # that signal delivery may be deferred. We want to avoid signal delivery
48
+ # while the Rack app.call is running because some database drivers
49
+ # (e.g. ruby-pg) may cancel pending requests.
50
+ def fake_sig(sig) # :nodoc:
51
+ old_cb = trap(sig, "IGNORE")
52
+ old_cb.call
53
+ ensure
54
+ trap(sig, old_cb)
55
+ end
56
+
57
+ # master sends fake signals to children
58
+ def soft_kill(sig) # :nodoc:
59
+ case sig
60
+ when Integer
61
+ signum = sig
62
+ else
63
+ signum = Signal.list[sig.to_s] or
64
+ raise ArgumentError, "BUG: bad signal: #{sig.inspect}"
65
+ end
66
+ # writing and reading 4 bytes on a pipe is atomic on all POSIX platforms
67
+ # Do not care in the odd case the buffer is full, here.
68
+ @master.write_nonblock([signum].pack('l'), exception: false)
69
+ rescue Errno::EPIPE
70
+ # worker will be reaped soon
71
+ end
72
+
73
+ # this only runs when the Rack app.call is not running
74
+ # act like Socket#accept_nonblock(exception: false)
75
+ def accept_nonblock(*_unused) # :nodoc:
76
+ case buf = @to_io.read_nonblock(4, exception: false)
77
+ when String
78
+ # unpack the buffer and trigger the signal handler
79
+ signum = buf.unpack('l')
80
+ fake_sig(signum[0])
81
+ # keep looping, more signals may be queued
82
+ when nil # EOF: master died, but we are at a safe place to exit
83
+ fake_sig(:QUIT)
84
+ when :wait_readable # keep waiting
85
+ return :wait_readable
86
+ end while true # loop, as multiple signals may be sent
87
+ end
88
+
89
+ # worker objects may be compared to just plain Integers
90
+ def ==(other_nr) # :nodoc:
91
+ @nr == other_nr
92
+ end
93
+
94
+ # called in the worker process
95
+ def tick=(value) # :nodoc:
96
+ @raindrop[@offset] = value
97
+ end
98
+
99
+ # called in the master process
100
+ def tick # :nodoc:
101
+ @raindrop[@offset]
102
+ end
103
+
104
+ # called in both the master (reaping worker) and worker (SIGQUIT handler)
105
+ def close # :nodoc:
106
+ @master.close if @master
107
+ @to_io.close if @to_io
108
+ end
109
+
110
+ # :startdoc:
111
+
112
+ # In most cases, you should be using the Unicorn::Configurator#user
113
+ # directive instead. This method should only be used if you need
114
+ # fine-grained control of exactly when you want to change permissions
115
+ # in your after_fork or after_worker_ready hooks, or if you want to
116
+ # use the chroot support.
117
+ #
118
+ # Changes the worker process to the specified +user+ and +group+,
119
+ # and chroots to the current working directory if +chroot+ is set.
120
+ # This is only intended to be called from within the worker
121
+ # process from the +after_fork+ hook. This should be called in
122
+ # the +after_fork+ hook after any privileged functions need to be
123
+ # run (e.g. to set per-worker CPU affinity, niceness, etc)
124
+ #
125
+ # +group+ can be specified as a string, or as an array of two
126
+ # strings. If an array of two strings is given, the first string
127
+ # is used as the primary group of the process, and the second is
128
+ # used as the group of the log files.
129
+ #
130
+ # Any and all errors raised within this method will be propagated
131
+ # directly back to the caller (usually the +after_fork+ hook.
132
+ # These errors commonly include ArgumentError for specifying an
133
+ # invalid user/group and Errno::EPERM for insufficient privileges.
134
+ #
135
+ # chroot support is only available in unicorn 5.3.0+
136
+ # user and group switching appeared in unicorn 0.94.0 (2009-11-05)
137
+ def user(user, group = nil, chroot = false)
138
+ # we do not protect the caller, checking Process.euid == 0 is
139
+ # insufficient because modern systems have fine-grained
140
+ # capabilities. Let the caller handle any and all errors.
141
+ uid = Etc.getpwnam(user).uid
142
+
143
+ if group
144
+ if group.is_a?(Array)
145
+ group, log_group = group
146
+ log_gid = Etc.getgrnam(log_group).gid
147
+ end
148
+ gid = Etc.getgrnam(group).gid
149
+ log_gid ||= gid
150
+ end
151
+
152
+ Unicorn::Util.chown_logs(uid, log_gid)
153
+ if gid && Process.egid != gid
154
+ Process.initgroups(user, gid)
155
+ Process::GID.change_privilege(gid)
156
+ end
157
+ if chroot
158
+ chroot = Dir.pwd if chroot == true
159
+ Dir.chroot(chroot)
160
+ Dir.chdir('/')
161
+ end
162
+ Process.euid != uid and Process::UID.change_privilege(uid)
163
+ @switched = true
164
+ end
165
+ end
data/lib/unicorn.rb ADDED
@@ -0,0 +1,136 @@
1
+ # -*- encoding: binary -*-
2
+ require 'etc'
3
+ require 'stringio'
4
+ require 'raindrops'
5
+ require 'io/wait'
6
+
7
+ begin
8
+ require 'rack'
9
+ rescue LoadError
10
+ warn 'rack not available, functionality reduced'
11
+ end
12
+
13
+ # :stopdoc:
14
+ # Unicorn module containing all of the classes (include C extensions) for
15
+ # running a Unicorn web server. It contains a minimalist HTTP server with just
16
+ # enough functionality to service web application requests fast as possible.
17
+ # :startdoc:
18
+
19
+ # unicorn exposes very little of an user-visible API and most of its
20
+ # internals are subject to change. unicorn is designed to host Rack
21
+ # applications, so applications should be written against the Rack SPEC
22
+ # and not unicorn internals.
23
+ module Unicorn
24
+
25
+ # Raised inside TeeInput when a client closes the socket inside the
26
+ # application dispatch. This is always raised with an empty backtrace
27
+ # since there is nothing in the application stack that is responsible
28
+ # for client shutdowns/disconnects. This exception is visible to Rack
29
+ # applications unless PrereadInput middleware is loaded. This
30
+ # is a subclass of the standard EOFError class and applications should
31
+ # not rescue it explicitly, but rescue EOFError instead.
32
+ ClientShutdown = Class.new(EOFError)
33
+
34
+ # :stopdoc:
35
+
36
+ # This returns a lambda to pass in as the app, this does not "build" the
37
+ # app (which we defer based on the outcome of "preload_app" in the
38
+ # Unicorn config). The returned lambda will be called when it is
39
+ # time to build the app.
40
+ def self.builder(ru, op)
41
+ # allow Configurator to parse cli switches embedded in the ru file
42
+ op = Unicorn::Configurator::RACKUP.merge!(:file => ru, :optparse => op)
43
+ if ru =~ /\.ru$/ && !defined?(Rack::Builder)
44
+ abort "rack and Rack::Builder must be available for processing #{ru}"
45
+ end
46
+
47
+ # always called after config file parsing, may be called after forking
48
+ lambda do |_, server|
49
+ inner_app = case ru
50
+ when /\.ru$/
51
+ raw = File.read(ru)
52
+ raw.sub!(/^__END__\n.*/, '')
53
+ eval("Rack::Builder.new {(\n#{raw}\n)}.to_app", TOPLEVEL_BINDING, ru)
54
+ else
55
+ require ru
56
+ Object.const_get(File.basename(ru, '.rb').capitalize)
57
+ end
58
+
59
+ if $DEBUG
60
+ require 'pp'
61
+ pp({ :inner_app => inner_app })
62
+ end
63
+
64
+ return inner_app unless server.default_middleware
65
+
66
+ middleware = { # order matters
67
+ ContentLength: nil,
68
+ CommonLogger: [ $stderr ],
69
+ ShowExceptions: nil,
70
+ Lint: nil,
71
+ TempfileReaper: nil,
72
+ }
73
+
74
+ # return value, matches rackup defaults based on env
75
+ # Unicorn does not support persistent connections, but Rainbows!
76
+ # does. Users accustomed to the Rack::Server default
77
+ # middlewares will need ContentLength middleware.
78
+ case ENV["RACK_ENV"]
79
+ when "development"
80
+ when "deployment"
81
+ middleware.delete(:ShowExceptions)
82
+ middleware.delete(:Lint)
83
+ else
84
+ return inner_app
85
+ end
86
+ Rack::Builder.new do
87
+ middleware.each do |m, args|
88
+ use(Rack.const_get(m), *args) if Rack.const_defined?(m)
89
+ end
90
+ run inner_app
91
+ end.to_app
92
+ end
93
+ end
94
+
95
+ # returns an array of strings representing TCP listen socket addresses
96
+ # and Unix domain socket paths. This is useful for use with
97
+ # Raindrops::Middleware under Linux: https://yhbt.net/raindrops/
98
+ def self.listener_names
99
+ Unicorn::HttpServer::LISTENERS.map do |io|
100
+ Unicorn::SocketHelper.sock_name(io)
101
+ end + Unicorn::HttpServer::NEW_LISTENERS
102
+ end
103
+
104
+ def self.log_error(logger, prefix, exc)
105
+ message = exc.message
106
+ message = message.dump if /[[:cntrl:]]/ =~ message
107
+ logger.error "#{prefix}: #{message} (#{exc.class})"
108
+ exc.backtrace.each { |line| logger.error(line) }
109
+ end
110
+
111
+ F_SETPIPE_SZ = 1031 if RUBY_PLATFORM =~ /linux/
112
+
113
+ def self.pipe # :nodoc:
114
+ IO.pipe.each do |io|
115
+ # shrink pipes to minimize impact on /proc/sys/fs/pipe-user-pages-soft
116
+ # limits.
117
+ if defined?(F_SETPIPE_SZ)
118
+ begin
119
+ io.fcntl(F_SETPIPE_SZ, Raindrops::PAGE_SIZE)
120
+ rescue Errno::EINVAL
121
+ # old kernel
122
+ rescue Errno::EPERM
123
+ # resizes fail if Linux is close to the pipe limit for the user
124
+ # or if the user does not have permissions to resize
125
+ end
126
+ end
127
+ end
128
+ end
129
+ # :startdoc:
130
+ end
131
+ # :enddoc:
132
+
133
+ %w(const socket_helper stream_input tee_input http_request configurator
134
+ tmpio util http_response worker http_server).each do |s|
135
+ require_relative "unicorn/#{s}"
136
+ end
@@ -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>.