yahns 1.11.0 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.gitattributes +5 -0
  3. data/.gitignore +2 -2
  4. data/Documentation/.gitignore +5 -2
  5. data/Documentation/GNUmakefile +25 -6
  6. data/Documentation/yahns-rackup.pod +178 -0
  7. data/Documentation/yahns.pod +96 -0
  8. data/Documentation/yahns_config.pod +658 -0
  9. data/GIT-VERSION-GEN +6 -5
  10. data/GNUmakefile +3 -3
  11. data/HACKING +2 -2
  12. data/README +6 -6
  13. data/Rakefile +7 -2
  14. data/bin/yahns +3 -2
  15. data/bin/yahns-rackup +3 -2
  16. data/examples/yahns_rack_basic.conf.rb +7 -2
  17. data/extras/README +2 -2
  18. data/extras/autoindex.rb +3 -2
  19. data/extras/exec_cgi.rb +3 -2
  20. data/extras/proxy_pass.rb +6 -5
  21. data/extras/try_gzip_static.rb +4 -3
  22. data/lib/yahns.rb +15 -9
  23. data/lib/yahns/acceptor.rb +4 -3
  24. data/lib/yahns/cap_input.rb +2 -1
  25. data/lib/yahns/client_expire_generic.rb +3 -2
  26. data/lib/yahns/client_expire_tcpi.rb +3 -2
  27. data/lib/yahns/config.rb +23 -18
  28. data/lib/yahns/daemon.rb +3 -2
  29. data/lib/yahns/fdmap.rb +3 -2
  30. data/lib/yahns/http_client.rb +4 -7
  31. data/lib/yahns/http_context.rb +13 -10
  32. data/lib/yahns/http_response.rb +8 -5
  33. data/lib/yahns/log.rb +3 -2
  34. data/lib/yahns/max_body.rb +2 -1
  35. data/lib/yahns/max_body/rewindable_wrapper.rb +3 -2
  36. data/lib/yahns/max_body/wrapper.rb +10 -5
  37. data/lib/yahns/openssl_client.rb +3 -2
  38. data/lib/yahns/openssl_server.rb +3 -2
  39. data/lib/yahns/proxy_http_response.rb +8 -7
  40. data/lib/yahns/proxy_pass.rb +7 -5
  41. data/lib/yahns/queue.rb +3 -2
  42. data/lib/yahns/queue_egg.rb +3 -2
  43. data/lib/yahns/queue_epoll.rb +4 -3
  44. data/lib/yahns/queue_kqueue.rb +4 -3
  45. data/lib/yahns/queue_quitter.rb +3 -2
  46. data/lib/yahns/queue_quitter_pipe.rb +3 -2
  47. data/lib/yahns/rack.rb +5 -4
  48. data/lib/yahns/rackup_handler.rb +4 -2
  49. data/lib/yahns/sendfile_compat.rb +5 -8
  50. data/lib/yahns/server.rb +14 -3
  51. data/lib/yahns/server_mp.rb +4 -2
  52. data/lib/yahns/sigevent.rb +3 -2
  53. data/lib/yahns/sigevent_efd.rb +3 -2
  54. data/lib/yahns/sigevent_pipe.rb +3 -2
  55. data/lib/yahns/socket_helper.rb +4 -2
  56. data/lib/yahns/stream_file.rb +3 -2
  57. data/lib/yahns/stream_input.rb +5 -4
  58. data/lib/yahns/tcp_server.rb +3 -2
  59. data/lib/yahns/tee_input.rb +4 -2
  60. data/lib/yahns/tmpio.rb +2 -1
  61. data/lib/yahns/unix_server.rb +3 -2
  62. data/lib/yahns/wbuf.rb +3 -2
  63. data/lib/yahns/wbuf_common.rb +4 -2
  64. data/lib/yahns/wbuf_str.rb +3 -2
  65. data/lib/yahns/worker.rb +3 -2
  66. data/test/covshow.rb +3 -2
  67. data/test/helper.rb +3 -2
  68. data/test/server_helper.rb +3 -2
  69. data/test/test_bin.rb +3 -2
  70. data/test/test_buffer_tmpdir.rb +3 -2
  71. data/test/test_client_expire.rb +5 -4
  72. data/test/test_client_max_body_size.rb +4 -3
  73. data/test/test_config.rb +3 -2
  74. data/test/test_expect_100.rb +5 -4
  75. data/test/test_extras_autoindex.rb +3 -2
  76. data/test/test_extras_exec_cgi.rb +4 -3
  77. data/test/test_extras_exec_cgi.sh +2 -2
  78. data/test/test_extras_proxy_pass.rb +3 -2
  79. data/test/test_extras_try_gzip_static.rb +3 -2
  80. data/test/test_fdmap.rb +3 -2
  81. data/test/test_input.rb +4 -3
  82. data/test/test_mt_accept.rb +3 -2
  83. data/test/test_output_buffering.rb +4 -3
  84. data/test/test_proxy_pass.rb +15 -14
  85. data/test/test_rack.rb +3 -2
  86. data/test/test_rack_hijack.rb +3 -2
  87. data/test/test_reopen_logs.rb +3 -2
  88. data/test/test_response.rb +3 -2
  89. data/test/test_serve_static.rb +2 -2
  90. data/test/test_server.rb +15 -14
  91. data/test/test_ssl.rb +60 -9
  92. data/test/test_stream_file.rb +3 -2
  93. data/test/test_tmpio.rb +3 -2
  94. data/test/test_unix_socket.rb +3 -2
  95. data/test/test_wbuf.rb +3 -2
  96. data/yahns.gemspec +5 -2
  97. metadata +21 -6
  98. data/Documentation/yahns-rackup.txt +0 -152
  99. data/Documentation/yahns.txt +0 -72
  100. data/Documentation/yahns_config.txt +0 -584
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 147b339e7cb3eec02dc6e6e482fe8a08bf5d2ad0
4
- data.tar.gz: 56e54e9e277aaa32b642a6f7680d5b899ed208d2
3
+ metadata.gz: 0200645323cf0450da2a840cea7660fa17470606
4
+ data.tar.gz: 85b6a4bb94c485538c4f9ed715985072a7409321
5
5
  SHA512:
6
- metadata.gz: d8427b2bdb6a6ae2d0b8bfd445b6bac230cf40e0675d43365e689896aac769d0cafd201a61215ab1075a91e7e8e09ef6797ae7ae9132ae1da20c48f199350622
7
- data.tar.gz: 9e015af7565846e6a913d02fed38ff7ebc040779acb53caf6a7fd417c31e9ebe3a054105ecf1c3a19e9671b7ba7d08ecfe53a20adf15fa1fa26cc46fdded23c4
6
+ metadata.gz: 5bdda8b713ed199f2ffce4bcc455f5805eb9f31143ac6bdefc87794426904e577bd7da0867097ac5e4c32434ce0c43250cadf7b0583d6c5913e907ae457e9511
7
+ data.tar.gz: 3bd31164da8bbb367c8db649b470c7b64edb71dfde446901923d3f63e6eef0e4d555f27b28459db9ca12a1a916dfbd7e2de3070cab335c5262f93ac32c5a19f9
@@ -0,0 +1,5 @@
1
+ *.gemspec diff=ruby
2
+ *.rb diff=ruby
3
+ *.ru diff=ruby
4
+ Rakefile diff=ruby
5
+ bin/* diff=ruby
data/.gitignore CHANGED
@@ -1,5 +1,5 @@
1
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
3
  /GIT-VERSION-FILE
4
4
  /NEWS
5
5
  /NEWS.atom.xml
@@ -1,5 +1,8 @@
1
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
3
  *.1
4
4
  *.5
5
5
  *.7
6
+ yahns_config.txt
7
+ yahns.txt
8
+ yahns-rackup.txt
@@ -1,11 +1,17 @@
1
- # Copyright (C) 2013-2015 all contributors <yahns-public@yhbt.net>
2
- # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
1
+ # Copyright (C) 2013-2016 all contributors <yahns-public@yhbt.net>
2
+ # License: GPL-3.0+ (https://www.gnu.org/licenses/gpl-3.0.txt)
3
3
  all::
4
4
 
5
5
  INSTALL = install
6
- PANDOC = pandoc
6
+ POD2MAN = pod2man
7
+ -include ../GIT-VERSION-FILE
8
+ release := yahns $(VERSION)
7
9
  PANDOC_OPTS = -f markdown --email-obfuscation=none
8
- pandoc = $(PANDOC) $(PANDOC_OPTS)
10
+ POD2MAN_OPTS = -v -r '$(release)' --stderr -d 1994-10-02 -c 'yahns user manual'
11
+ pod2man = $(POD2MAN) $(POD2MAN_OPTS)
12
+ POD2TEXT = pod2text
13
+ POD2TEXT_OPTS = --stderr
14
+ pod2text = $(POD2TEXT) $(POD2TEXT_OPTS)
9
15
 
10
16
  m1 =
11
17
  m1 += yahns
@@ -43,8 +49,21 @@ install-man: man
43
49
  $(INSTALL) -m 644 $(man1) $(DESTDIR)$(man1dir)
44
50
  $(INSTALL) -m 644 $(man5) $(DESTDIR)$(man5dir)
45
51
  test -z "$(man7)" || $(INSTALL) -m 644 $(man7) $(DESTDIR)$(man7dir)
46
- %.1 %.5 %.7 : %.txt
47
- $(pandoc) -s -t man < $< > $@+ && mv $@+ $@
52
+
53
+ %.1 %.5 %.7 : %.pod
54
+ $(pod2man) -s $(subst .,,$(suffix $@)) $< $@+ && mv $@+ $@
55
+
56
+ mantxt = $(addsuffix .txt, $(m1) $(m5) $(m7))
57
+
58
+ txt :: $(mantxt)
59
+
60
+ all :: txt
61
+
62
+ %.txt : %.pod
63
+ $(pod2text) $< $@+
64
+ -touch -r $< $@+ 2>/dev/null # GNU-ism
65
+ mv $@+ $@
48
66
 
49
67
  clean::
50
68
  $(RM) $(man1) $(man5) $(man7)
69
+ $(RM) $(addsuffix .txt.gz, $(m1) $(m5) $(m7))
@@ -0,0 +1,178 @@
1
+ =head1 NAME
2
+
3
+ yahns-rackup - a rackup-like command to launch yahns
4
+
5
+ =head1 SYNOPSIS
6
+
7
+ yahns-rackup [-E RACK_ENV] [-O worker_threads=NUM] [RACKUP_FILE]
8
+
9
+ =head1 DESCRIPTION
10
+
11
+ A L<rackup(1)>-like command to launch Rack applications using yahns.
12
+ It is expected to start in your application root (APP_ROOT).
13
+
14
+ =head1 RACKUP FILE
15
+
16
+ This defaults to "config.ru" in APP_ROOT. It should be the same
17
+ file used by L<rackup(1)> and other Rack launchers, it uses the
18
+ *Rack::Builder* DSL documented at:
19
+
20
+ L<http://www.rubydoc.info/github/rack/rack/Rack/Builder>
21
+
22
+ =head1 YAHNS OPTIONS
23
+
24
+ =over
25
+
26
+ =item -O client_timeout=SECONDS
27
+
28
+ Defines the timeout expiring idle connections.
29
+
30
+ Increase this if your application takes longer to run than the
31
+ default timeout. Lower this if you run out of FDs.
32
+
33
+ Default: 15 (seconds)
34
+
35
+ =item -O listen=ADDRESS[,ADDRESS...]
36
+
37
+ Listens on a given ADDRESS. ADDRESS may be in the form of
38
+ HOST:PORT or PATH, HOST:PORT is taken to mean a TCP socket
39
+ and PATH is meant to be a path to a UNIX domain socket.
40
+ Defaults to "0.0.0.0:9292" (all addresses on TCP port 9292).
41
+ Multiple addresses may be separated with commas.
42
+
43
+ =item -O stderr_path=PATHNAME
44
+
45
+ Allow redirecting $stderr to a given path. Unlike doing this from
46
+ the shell, this allows the yahns process to know the path its
47
+ writing to and rotate the file if it is used for logging. The
48
+ file will be opened with the O_APPEND flag and writes
49
+ synchronized to the kernel (but not necessarily to _disk_) so
50
+ multiple processes can safely append to it.
51
+
52
+ If you are daemonizing and using the default logger, it is important
53
+ to specify this as errors will otherwise be lost to /dev/null.
54
+ Some applications/libraries may also triggering warnings that go to
55
+ stderr, and they will end up here.
56
+
57
+ Default: /dev/null if daemonized, controlling terminal if not
58
+
59
+ =item -O stdout_path=PATH
60
+
61
+ Same as stderr_path, except for $stdout. Not many applications
62
+ write to $stdout, but any that do will have their output written here.
63
+ It is safe to point this to the same location a stderr_path.
64
+ Like stderr_path, this defaults to /dev/null when daemonized.
65
+
66
+ Default: /dev/null if daemonized, controlling terminal if not
67
+
68
+ =item -O worker_threads=INTEGER
69
+
70
+ This controls the number of threads for application processing.
71
+ Each queue has its own thread pool. Increase this number if your
72
+ applications are able to use more threads effectively or if either
73
+ (or both) input/output buffering are disabled. Lower this number if
74
+ you do not need multi-thread concurrency at all.
75
+
76
+ Default: 7
77
+
78
+ =back
79
+
80
+ =head1 RACKUP OPTIONS
81
+
82
+ =over
83
+
84
+ =item -D, --daemonize
85
+
86
+ Run daemonized in the background. The process is detached from
87
+ the controlling terminal and stdin is redirected to /dev/null.
88
+ Unless specified via stderr_path and stdout_path, stderr and stdout will
89
+ also be redirected to "/dev/null".
90
+
91
+ =item -E, --env RACK_ENV
92
+
93
+ Run under the given RACK_ENV. See the L</RACK ENVIRONMENT> section
94
+ for more details.
95
+
96
+ =item -o, --host HOST
97
+
98
+ Listen on a TCP socket belonging to HOST, default is
99
+ "0.0.0.0" (all addresses).
100
+ If specified multiple times on the command-line, only the
101
+ last-specified value takes effect.
102
+ This option only exists for compatibility with the L<rackup(1)> command,
103
+ use of "-l"/"--listen" switch is recommended instead.
104
+
105
+ =item -p, --port PORT
106
+
107
+ Listen on the specified TCP PORT, default is 9292.
108
+ If specified multiple times on the command-line, only the last-specified
109
+ value takes effect.
110
+ This option only exists for compatibility with the L<rackup(1)> command,
111
+ use of "-l"/"--listen" switch is recommended instead.
112
+
113
+ =back
114
+
115
+ =head1 RUBY OPTIONS
116
+
117
+ =over
118
+
119
+ =item -e, --eval LINE
120
+
121
+ Evaluate a LINE of Ruby code. This evaluation happens
122
+ immediately as the command-line is being parsed.
123
+
124
+ =item -d, --debug
125
+
126
+ Turn on debug mode, the $DEBUG variable is set to true.
127
+
128
+ =item -w, --warn
129
+
130
+ Turn on verbose warnings, the $VERBOSE variable is set to true.
131
+
132
+ =item -I, --include PATH
133
+
134
+ Specify $LOAD_PATH. PATH will be prepended to $LOAD_PATH.
135
+ The ':' character may be used to delimit multiple directories.
136
+ This directive may be used more than once. Modifications to
137
+ $LOAD_PATH take place immediately and in the order they were
138
+ specified on the command-line.
139
+
140
+ =item -r, --require LIBRARY
141
+
142
+ Require a specified LIBRARY before executing the application. The
143
+ "require" statement will be executed immediately and in the order
144
+ they were specified on the command-line.
145
+
146
+ =back
147
+
148
+ =head1 SIGNALS
149
+
150
+ See L<yahns(1)>
151
+
152
+ =head1 FILES
153
+
154
+ See Rack documentation for a description of the rackup file format.
155
+
156
+ =head1 ENVIRONMENT VARIABLES
157
+
158
+ The RACK_ENV variable is set by the aforementioned -E switch.
159
+ If RACK_ENV is already set, it will be used unless -E is used.
160
+ See rackup documentation for more details.
161
+
162
+ =head1 CONTACT
163
+
164
+ All feedback welcome via plain-text mail to L<mailto:yahns-public@yhbt.net>
165
+ No subscription is necessary to post to the mailing list.
166
+ List archives are available at L<http://yhbt.net/yahns-public/>
167
+
168
+ =head1 COPYRIGHT
169
+
170
+ Copyright (C) 2013-2016 all contributors L<mailto:yahns-public@yhbt.net>
171
+ License: GPL-3.0+ L<http://www.gnu.org/licenses/gpl-3.0.txt>
172
+
173
+ =head1 SEE ALSO
174
+
175
+ L<yahns(1)>, L<yahns_config(5)>,
176
+ L<Rack::Builder RDoc|http://www.rubydoc.info/github/rack/rack/Rack/Builder>,
177
+ L<Rack RDoc|http://www.rubydoc.info/github/rack/rack/>,
178
+ L<Rackup HowTo|https://github.com/rack/rack/wiki/tutorial-rackup-howto>
@@ -0,0 +1,96 @@
1
+ =head1 NAME
2
+
3
+ yahns - multi-threaded, non-blocking application server for Ruby
4
+
5
+ =head1 SYNOPSYS
6
+
7
+ yahns -c CONFIG_FILE [-D|--daemonize]
8
+
9
+ =head1 DESCRIPTION
10
+
11
+ L<yahns(1)> is the primary interface for launching a yahns application
12
+ server. The configuration file is documented in L<yahns_config(5)>.
13
+ yahns hosts Rack HTTP applications, but may support others in the
14
+ future such as DRb.
15
+
16
+ =head1 SIGNALS
17
+
18
+ The following UNIX signals may be sent to the running yahns process.
19
+ If yahns is configured for worker_processes (optional), signals should
20
+ only be sent to the master process.
21
+
22
+ =over
23
+
24
+ =item INT/TERM/QUIT
25
+
26
+ Graceful shutdown. If repeated (any of these signals
27
+ is sent twice), shutdown occurs immediately.
28
+
29
+ =item USR1
30
+
31
+ Reopen all logs owned by the master and all workers.
32
+ This scans the Ruby ObjectSpace for all open File objects with the
33
+ O_APPEND file flag and buffering disabled (IO#sync==false)
34
+
35
+ =item USR2
36
+
37
+ Reexecute the running binary. A separate QUIT should be sent to
38
+ the original process once the child is verified to
39
+ be up and running.
40
+
41
+ =item HUP
42
+
43
+ If worker_processes are not used, this will reexecute the running
44
+ binary and gracefully exit the running process. If worker_processes are
45
+ used, this will reload config file, app, and gracefully restart all workers
46
+
47
+ =item WINCH
48
+
49
+ Gracefully stops workers but keep the master running.
50
+ This will only work for daemonized processes and only if the
51
+ worker_processes configuration directive is used.
52
+
53
+ =item TTIN
54
+
55
+ Increment the number of worker processes by one
56
+ (only if the worker_processes directive is used)
57
+
58
+ =item TTOU
59
+
60
+ Decrement the number of worker processes by one
61
+ (only if the worker_processes directive is used)
62
+
63
+ =back
64
+
65
+ =head1 ENVIRONMENT
66
+
67
+ L<yahns(1)> itself requires no special environment variables. However,
68
+ environment variables such as RACK_ENV and RAILS_ENV can affect Rack and
69
+ Rails applications it hosts. Ruby and C library implementation-specific
70
+ environment variables will also affect it.
71
+
72
+ yahns will update the PWD (current working directory) env if the
73
+ working_directory directive is set (see L<yahns_config(5)>).
74
+
75
+ LISTEN_FDS and LISTEN_PID variables are used in our emulation
76
+ of L<sd_listen_fds(3)> function. See L<sd_listen_fds(3)> manpage
77
+ for more details.
78
+
79
+ =head1 FILES
80
+
81
+ See L<yahns_config(5)> for documentation on the configuration file format.
82
+
83
+ =head1 CONTACT
84
+
85
+ All feedback welcome via plain-text mail to L<mailto:yahns-public@yhbt.net>
86
+ No subscription is necessary to post to the mailing list.
87
+ Mail archives are available at L<http://yhbt.net/yahns-public/>
88
+
89
+ =head1 COPYRIGHT
90
+
91
+ Copyright (C) 2013-2016 all contributors L<mailto:yahns-public@yhbt.net>
92
+ License: GPL-3.0+ L<http://www.gnu.org/licenses/gpl-3.0.txt>
93
+
94
+ =head1 SEE ALSO
95
+
96
+ L<yahns-rackup(1)>, L<yahns_config(5)>, L<sd_listen_fds(3)>
@@ -0,0 +1,658 @@
1
+ =head1 NAME
2
+
3
+ yahns_config - configuration file description for L<yahns(1)>
4
+
5
+ =head1 DESCRIPTION
6
+
7
+ Since yahns is a Ruby application server, its configuration file is
8
+ implemented in Ruby syntax, making it dependent on the version of
9
+ Ruby it is running under.
10
+
11
+ =head1 TOP-LEVEL DIRECTIVES
12
+
13
+ =over
14
+
15
+ =item app :TYPE, *APP_ARGUMENTS, &BLOCK
16
+
17
+ This defines an application context for yahns to run. :TYPE defines
18
+ the type of application it runs. yahns will eventually support
19
+ application types other than :rack, but for now, only :rack is
20
+ supported.
21
+
22
+ The &BLOCK given configures the which sockets the app listens on,
23
+ buffering and logging settings.
24
+
25
+ An app with the same :TYPE and APP_ARGUMENTS may be defined multiple
26
+ times with different &BLOCK contents (with different listeners and
27
+ buffering settings).
28
+
29
+ See the L</APP-LEVEL DIRECTIVES> section for details on what goes into
30
+ the &BLOCK.
31
+
32
+ This directive may be specified multiple times for different or
33
+ identical applications.
34
+
35
+ If the "working_directory" directive is used, all app directives may
36
+ only be specified after setting "working_directory".
37
+
38
+ For Rack HTTP applications, see L</RACK APP ARGUMENTS> for more
39
+ information.
40
+
41
+ =item before_exec &BLOCK
42
+
43
+ This runs &BLOCK before Kernel#exec (L<execve(2)> wrapper). The command
44
+ array to be passed to Kernel#exec may be modified within this hook:
45
+
46
+ before_exec do |cmd|
47
+ # you may modify ENV here inside the child process
48
+ ENV["MALLOC_ARENA_MAX"] = ENV["MALLOC_ARENA_TEST"] = "1"
49
+
50
+ # You may change to a different installation of Ruby or yahns
51
+ # by doing an in-place modification of cmd:
52
+ cmd.replace(%W(/another/install/of/yahns -c cfg.rb))
53
+ end
54
+
55
+ Default: (none)
56
+
57
+ =item client_expire_threshold {INTEGER|FLOAT}
58
+
59
+ yahns will start expiring idle clients when it hits this threshold.
60
+ If the threshold is a floating point number, it is that fraction of
61
+ the soft open file limit (RLIMIT_NOFILE ir `ulimit -S -n` in shell).
62
+ Thus if the soft open file limit is 1024 (a typical value) and the
63
+ client_expire_threshold is 0.3, yahns will start expiring clients once
64
+ it hits 307 clients (0.3 * 1024).
65
+
66
+ If given a positive integer, yahns will start expiring clients once it
67
+ its this absolute threshold of connected clients.
68
+
69
+ If given a negative integer, yahns will start expiring clients once it
70
+ reaches N clients away from the the soft file limit. That is, if
71
+ client_expire_threshold is -666 and the soft open file limit is 1024,
72
+ it will start expiring once it hits 358 clients.
73
+
74
+ Clients are expired when the configured client_timeout for their
75
+ app context is hit.
76
+
77
+ Default: 0.5
78
+
79
+ =item logger LOGGER
80
+
81
+ Sets LOGGER as the default logger of the process. The new
82
+ LOGGER must respond to the following methods:
83
+
84
+ debug, info, warn, error, fatal
85
+
86
+ The default logger will log its output to the path specified
87
+ by stderr_path. If you're running yahns daemonized, then
88
+ you must specify a path to prevent error messages from going
89
+ to /dev/null
90
+
91
+ A per-APP &BLOCK logger may also be configured inside an app &BLOCK.
92
+
93
+ Default: Logger.new($stderr)
94
+
95
+ =item pid PATHNAME
96
+
97
+ Sets the path of the PID file for use with management/init scripts.
98
+
99
+ Default: none
100
+
101
+ =item queue [NAME] &BLOCK
102
+
103
+ As a top-level directive, this configures or defines a queue.
104
+ If no NAME is specified, a default queue (named :default) is
105
+ assumed. See the L</QUEUE-LEVEL DIRECTIVES> section for details.
106
+
107
+ A &BLOCK must be given if used as a top-level directive. This
108
+ behaves slightly differently inside an app &BLOCK. This may also
109
+ be given without a block to associate an app block with a named
110
+ queue.
111
+
112
+ Usually, only one queue is necessary. Each queue corresponds to
113
+ an epoll descriptor and worker thread pool.
114
+
115
+ Default: NAME defaults to :default
116
+
117
+ =item stderr_path PATHNAME
118
+
119
+ Allow redirecting $stderr to a given path. Unlike doing this from
120
+ the shell, this allows the yahns process to know the path its
121
+ writing to and rotate the file if it is used for logging. The
122
+ file will be opened with the O_APPEND flag and writes
123
+ synchronized to the kernel (but not necessarily to _disk_) so
124
+ multiple processes can safely append to it.
125
+
126
+ If you are daemonizing and using the default logger, it is important
127
+ to specify this as errors will otherwise be lost to /dev/null.
128
+ Some applications/libraries may also triggering warnings that go to
129
+ stderr, and they will end up here.
130
+
131
+ Default: /dev/null if daemonized, controlling terminal if not
132
+
133
+ =item stdout_path PATHNAME
134
+
135
+ Same as stderr_path, except for $stdout. Not many applications
136
+ write to $stdout, but any that do will have their output written here.
137
+ It is safe to point this to the same location a stderr_path.
138
+ Like stderr_path, this defaults to /dev/null when daemonized.
139
+
140
+ Default: /dev/null if daemonized, controlling terminal if not
141
+
142
+ =item working_directory PATHNAME
143
+
144
+ Sets the working directory for the process. This ensures SIGUSR2 will
145
+ start a new instance of yahns in this directory. This may be
146
+ a symlink, a common scenario for Capistrano users. Unlike
147
+ all other yahns configuration directives, this binds immediately
148
+ for error checking and cannot be undone by unsetting it in the
149
+ configuration file and reloading.
150
+
151
+ This must be specified before any "app" directives
152
+
153
+ Default: / if daemonized, current working directory if not
154
+
155
+ =back
156
+
157
+ =head2 QUEUE-LEVEL DIRECTIVES
158
+
159
+ =over
160
+
161
+ =item max_events INTEGER
162
+
163
+ This controls the number of events a worker thread will fetch at
164
+ once via L<epoll_wait(2)>. There is no good reason to change this
165
+ unless you use very few (e.g. 1) worker_threads. Leaving this at
166
+ 1 will give the fairest load balancing behavior with epoll.
167
+
168
+ Default: 1
169
+
170
+ =item worker_threads INTEGER
171
+
172
+ This controls the number of threads for application processing.
173
+ Each queue has its own thread pool. Increase this number if your
174
+ applications are able to use more threads effectively or if either
175
+ (or both) input/output buffering are disabled. Lower this number if
176
+ you do not need multi-thread concurrency at all.
177
+
178
+ Default: 7
179
+
180
+ =back
181
+
182
+ =head2 APP-LEVEL DIRECTIVES
183
+
184
+ =over
185
+
186
+ =item atfork_prepare, atfork_parent, atfork_child
187
+
188
+ These are identical to the methods defined in WORKER_PROCESSES-LEVEL
189
+ DIRECTIVES, however they are available inside the app blocks for
190
+ convenience in case it is easier to organize per-app hooks.
191
+
192
+ Default: (none)
193
+
194
+ =item check_client_connection BOOLEAN
195
+
196
+ When enabled, yahns will check the client connection by writing
197
+ the beginning of the HTTP headers before calling the application.
198
+
199
+ This can prevent calling the application for clients who have
200
+ disconnected while their connection was waiting for a free
201
+ worker thread.
202
+
203
+ This only affects clients connecting over Unix domain sockets and
204
+ TCP via loopback (127.*.*.*). It is unlikely to detect disconnects
205
+ if the client is on a remote host (even on a fast LAN).
206
+
207
+ This has no effect for (rare) HTTP/0.9 clients.
208
+
209
+ Default: false
210
+
211
+ =item client_body_buffer_size INTEGER
212
+
213
+ This controls the maximum size of a request body before it is
214
+ buffered to the filesystem (instead of memory). This has no effect
215
+ if input_buffering is false. This also governs the size of an
216
+ individual L<read(2)> system call when reading a request body.
217
+
218
+ There is generally no need to change this value and this directive
219
+ may be removed in the future.
220
+
221
+ Default: 8192 bytes (8 kilobytes)
222
+
223
+ =item client_header_buffer_size INTEGER
224
+
225
+ This controls the size of a single L<read(2)> syscall for reading
226
+ client request headers. Increase this as needed if your application
227
+ uses large cookies or long URLs. Lowering this may reduce GC and
228
+ memory allocator overhead.
229
+
230
+ Default: 4000 bytes
231
+
232
+ =item client_max_body_size {INTEGER|nil}
233
+
234
+ This controls the maximum request body size before a client is
235
+ rejected with an HTTP 413 error.
236
+
237
+ Setting this to nil will allow unlimited-sized inputs.
238
+
239
+ Default: 1048576 bytes (one megabyte)
240
+
241
+ =item client_timeout SECONDS
242
+
243
+ Defines the timeout expiring idle connections.
244
+
245
+ If input_buffering is false or :lazy, this defines the maximum
246
+ amount of time a worker thread will wait synchronously for a client
247
+ request body.
248
+
249
+ If output_buffering is false, this defines the maximum amount of
250
+ time a worker thread will wait synchronously for a client socket
251
+ to become writable.
252
+
253
+ It makes sense to lower this to a low value (e.g. 5 seconds) if
254
+ either output or input buffering are disabled. The default value
255
+ of 15 seconds is suitable for configurations with both input and
256
+ output buffering enabled and assumes all application dispatch
257
+ finishes in less than 15 seconds.
258
+
259
+ Default: 15 (seconds)
260
+
261
+ =item errors {IO|PATHNAME}
262
+
263
+ For Rack applications, this controls the env["rack.errors"]
264
+ destination. If given a PATHNAME, it will be a writable file
265
+ opened with O_APPEND without userspace buffering, making it suitable
266
+ for concurrent appends by multiple processes and threads, as well as
267
+ making it eligible for reopening via SIGUSR1 after log rotation.
268
+
269
+ Default: $stderr
270
+
271
+ =item input_buffering {:lazy|true|false}[, OPTIONS]
272
+
273
+ This controls buffering of the HTTP request body.
274
+
275
+ =over
276
+
277
+ =item true
278
+
279
+ Fully buffers the request before application dispatch. This is
280
+ most suitable for slow and untrusted clients which may trickle
281
+ the request to the server.
282
+
283
+ =item :lazy
284
+
285
+ Provides streaming, but rewindable input. This is suitable
286
+ for fast, trusted clients and is fully-compatible with Rack 1.x
287
+ specifications. :lazy buffering may also be suitable for slow and
288
+ untrusted clients if you are able and willing to run a queue with
289
+ many worker threads.
290
+
291
+ =item false
292
+
293
+ Disable input buffering completely. This violates the
294
+ Rack 1.x spec and is only suitable for fast, trusted clients or
295
+ queues with many worker threads.
296
+
297
+ HTTP request headers are always buffered in memory.
298
+
299
+ Do not be tempted to disable any buffering because it improves
300
+ numbers on a synthetic benchmark over a fast connection.
301
+ Slow, real-world clients can easily overwhelm servers without both
302
+ input and output buffering.
303
+
304
+ =back
305
+
306
+ Default: true
307
+
308
+ The following OPTIONS may be specified for input_buffering:
309
+
310
+ =over
311
+
312
+ =item tmpdir: DIRECTORY
313
+
314
+ Specify an alternative temporary directory of input_buffering is
315
+ :lazy or true. This can be used in case the normal temporary
316
+ directory is too small or busy to be used for input buffering.
317
+
318
+ Default: Dir.tmpdir (usually from TMPDIR env or /tmp)
319
+
320
+ =back
321
+
322
+ =item listen ADDRESS [, OPTIONS]
323
+
324
+ Adds an ADDRESS to the existing listener set. May be specified more
325
+ than once. ADDRESS may be an Integer port number for a TCP port, an
326
+ "IP_ADDRESS:PORT" for TCP listeners or a pathname for UNIX domain sockets.
327
+
328
+ # listen to port 3000 on all TCP interfaces
329
+ listen 3000
330
+
331
+ # listen to port 3000 on the loopback interface
332
+ listen "127.0.0.1:3000"
333
+
334
+ # listen on the given Unix domain socket
335
+ listen "/path/to/.unicorn.sock"
336
+
337
+ # listen to port 3000 on the IPv6 loopback interface
338
+ listen "[::1]:3000"
339
+
340
+ When using Unix domain sockets, be sure:
341
+
342
+ =over
343
+
344
+ =item 1. the path matches the one used by nginx
345
+
346
+ =item 2. uses the same filesystem namespace as the nginx process
347
+
348
+ =back
349
+
350
+ For systemd users using PrivateTmp=true (for either nginx or yahns),
351
+ this means Unix domain sockets must not be placed in /tmp
352
+
353
+ The following OPTIONS may be specified (but are generally not needed):
354
+
355
+ =over
356
+
357
+ =item backlog: INTEGER
358
+
359
+ This is the backlog of the L<listen(2)> syscall.
360
+
361
+ Some operating systems allow negative values here to specify the
362
+ maximum allowable value. In most cases, this number is only
363
+ recommendation and there are other OS-specific tunables and
364
+ variables that can affect this number. See the L<listen(2)>
365
+ syscall documentation of your OS for the exact semantics of
366
+ this.
367
+
368
+ If you are running unicorn on multiple machines, lowering this number
369
+ can help your load balancer detect when a machine is overloaded
370
+ and give requests to a different machine.
371
+
372
+ Default: 1024
373
+
374
+ =item ipv6only: BOOLEAN
375
+
376
+ This option makes IPv6-capable TCP listeners IPv6-only and unable
377
+ to receive IPv4 queries on dual-stack systems. A separate IPv4-only
378
+ listener is required if this is true.
379
+
380
+ Enabling this option for the IPv6-only listener and having a
381
+ separate IPv4 listener is recommended if you wish to support IPv6
382
+ on the same TCP port. Otherwise, the value of env["REMOTE_ADDR"]
383
+ will appear as an ugly IPv4-mapped-IPv6 address for IPv4 clients
384
+ (e.g ":ffff:10.0.0.1" instead of just "10.0.0.1").
385
+
386
+ Default: Operating-system dependent
387
+
388
+ =item sndbuf / rcvbuf: INTEGER
389
+
390
+ Maximum receive and send buffer sizes (in bytes) of sockets.
391
+
392
+ These correspond to the SO_RCVBUF and SO_SNDBUF settings which
393
+ can be set via the L<setsockopt(2)> syscall. Some kernels
394
+ (e.g. Linux 2.4+) have intelligent auto-tuning mechanisms and
395
+ there is no need (and it is sometimes detrimental) to specify them.
396
+
397
+ See the socket API documentation of your operating system
398
+ to determine the exact semantics of these settings and
399
+ other operating system-specific knobs where they can be
400
+ specified.
401
+
402
+ Defaults: operating system defaults
403
+
404
+ =item reuseport: BOOLEAN
405
+
406
+ This enables multiple, independently-started yahns instances to
407
+ bind to the same port (as long as all the processes enable this).
408
+
409
+ This option must be used when yahns first binds the listen socket.
410
+ It cannot be enabled when a socket is inherited via SIGUSR2
411
+ (but it will remain on if inherited), and it cannot be enabled
412
+ directly via SIGHUP.
413
+
414
+ Note: there is a chance of connections being dropped if
415
+ one of the yahns instances is stopped while using this.
416
+
417
+ This is supported on *BSD systems and Linux 3.9 or later.
418
+
419
+ ref: L<https://lwn.net/Articles/542629/>
420
+
421
+ Default: false (unset)
422
+
423
+ =item ssl_ctx: OpenSSL::SSL::SSLContext Ruby object
424
+
425
+ To enable TLS connections, you must configure this yourself.
426
+ See documentation for OpenSSL::SSL::SSLContext
427
+ for more information:
428
+
429
+ L<http://docs.ruby-lang.org/en/trunk/OpenSSL/SSL/SSLContext.html>
430
+
431
+ Default: none
432
+
433
+ An example which seems to work is:
434
+
435
+ require 'openssl'
436
+ ssl_ctx = OpenSSL::SSL::SSLContext.new
437
+ ssl_ctx.cert = OpenSSL::X509::Certificate.new(
438
+ IO.read('/etc/ssl/certs/example.crt')
439
+ )
440
+ ssl_ctx.extra_chain_cert = [
441
+ OpenSSL::X509::Certificate.new(
442
+ IO.read('/etc/ssl/certs/chain.crt')
443
+ )
444
+ ]
445
+ ssl_ctx.key = OpenSSL::PKey::RSA.new(
446
+ IO.read('/etc/ssl/private/example.key')
447
+ )
448
+
449
+ app(:rack, "/path/to/my/app/config.ru") do
450
+ listen 443, ssl_ctx: ssl_ctx
451
+ end
452
+
453
+ =item umask: MODE
454
+
455
+ Sets the file mode creation mask for UNIX sockets. If specified,
456
+ this is usually in octal notation.
457
+
458
+ Typically UNIX domain sockets are created with more liberal
459
+ file permissions than the rest of the application. By default,
460
+ we create UNIX domain sockets to be readable and writable by
461
+ all local users to give them the same accessibility as
462
+ locally-bound TCP listeners.
463
+
464
+ This has no effect on TCP listeners.
465
+
466
+ Default: 0000 (world-read/writable)
467
+
468
+ =back
469
+
470
+ =item logger LOGGER
471
+
472
+ Configures a logger within the current app &BLOCK.
473
+ This behaves the same as the logger directive described in
474
+ TOP-LEVEL DIRECTIVES
475
+
476
+ Default: uses the top-level logger
477
+
478
+ =item output_buffering BOOLEAN [, OPTIONS]
479
+
480
+ This enables or disables buffering of the HTTP response. If enabled,
481
+ buffering is only performed lazily. In other words, buffering only
482
+ happens if socket buffers (in the kernel) are filled up, and yahns
483
+ will continously try to flush the buffered data to the socket while
484
+ it is buffering.
485
+
486
+ Disabling output buffering is only recommended if ALL clients
487
+ connecting to this application context are fast, trusted or
488
+ you are willing and able to run many worker threads.
489
+
490
+ Do not be tempted to disable any buffering because it improves
491
+ numbers on a synthetic benchmark over a fast connection.
492
+ Slow, real-world clients can easily overwhelm servers without both
493
+ input and output buffering.
494
+
495
+ If output buffering is disabled, client_timeout controls the maximum
496
+ amount of time a worker thread will wait synchronously.
497
+
498
+ Default: true
499
+
500
+ The following OPTIONS may be specified for output_buffering:
501
+
502
+ =over
503
+
504
+ =item tmpdir: DIRECTORY
505
+
506
+ Specify an alternative temporary directory of output_buffering is
507
+ enabled. This can be used in case the normal temporary directory
508
+ is too small or busy to be used for output buffering.
509
+
510
+ Default: Dir.tmpdir (usually from TMPDIR env or /tmp)
511
+
512
+ =back
513
+
514
+ =item persistent_connections BOOLEAN
515
+
516
+ Enable or disables persistent connections and pipelining for HTTP
517
+ connections. Persistent connections only expire when the global
518
+ client_expire_threshold is hit and a client hits its client_timeout.
519
+
520
+ Default: true
521
+
522
+ =item user USER [,GROUP]
523
+
524
+ Runs application process(es) as the specified USER and GROUP.
525
+
526
+ If using worker_processes, this only affects the workers and the
527
+ master stays running as the user who started it. This switch will
528
+ occur before calling the atfork_child hook(s).
529
+
530
+ GROUP is optional and will not change if unspecified.
531
+
532
+ Default: none (no user switching is done)
533
+
534
+ =item queue [NAME or &BLOCK]
535
+
536
+ If given a NAME-only, this will associate this app &BLOCK with an
537
+ existing queue.
538
+
539
+ If given a &BLOCK-only, this will create an anonymous queue for this
540
+ application context only. If given a &BLOCK, this takes the same
541
+ parameters (worker_threads and max_events) as described in
542
+ L</QUEUE-LEVEL DIRECTIVES>.
543
+
544
+ NAME and &BLOCK may not be combined inside an app &BLOCK.
545
+
546
+ Default: uses the global, :default queue if none is specified
547
+
548
+ =item shutdown_timeout SECONDS
549
+
550
+ This defines the timeout for gracefully exiting the process if there
551
+ are still connected clients. This should generally be higher or equal
552
+ to the app with the highest client_timeout value.
553
+
554
+ Increase this if your application has slow endpoints which may take
555
+ longer than the default timeout.
556
+
557
+ Default: max client_timeout value of all apps in the process
558
+
559
+ =item worker_processes INTEGER [&BLOCK]
560
+
561
+ This directive allows yahns to use a master/worker configuration to
562
+ use multiple processes. Specifying any numeric value (including 1)
563
+ here means yahns will enable yahns to use a master/worker process
564
+ model instead of a single process.
565
+
566
+ If an optional &BLOCK is given, it may be used to configure
567
+ L<pthread_atfork(3)>-style hooks.
568
+ See L</WORKER_PROCESSES-LEVEL DIRECTIVES> for details.
569
+
570
+ Using worker_processes is strongly recommended if your application
571
+ relies on using a SIGCHLD handler for reaping forked processes.
572
+ Without worker_processes, yahns must reserve SIGCHLD for rolling
573
+ back SIGUSR2 upgrades, leading to conflicts if the appplication
574
+ expects to handle SIGCHLD.
575
+
576
+ Default: nil (single process, no master/worker separation)
577
+
578
+ =back
579
+
580
+ =head2 WORKER_PROCESSES-LEVEL DIRECTIVES
581
+
582
+ Note: all of the atfork_* hooks described here are available inside the
583
+ "app" blocks, too.
584
+
585
+ =over
586
+
587
+ =item atfork_prepare &BLOCK
588
+
589
+ This &BLOCK is executed in the parent before L<fork(2)> operation.
590
+ This may be useful for app directives which specify "preload: true"
591
+ to disconnect from databases or otherwise close open file descriptors
592
+ to prevent them from being shared with the children.
593
+
594
+ Default: none
595
+
596
+ =item atfork_parent &BLOCK
597
+
598
+ This &BLOCK is executed in the parent after the L<fork(2)> operation.
599
+
600
+ Default: none
601
+
602
+ =item atfork_child &BLOCK
603
+
604
+ This &BLOCK is executed in the child after the L<fork(2)> operation.
605
+
606
+ This may be useful for app directives which specify "preload: true"
607
+ to reconnect to databases or reopen closed file descriptors which
608
+ were closed in the atfork_prepare hook.
609
+
610
+ Default: none
611
+
612
+ =back
613
+
614
+ =head1 RACK APP ARGUMENTS
615
+
616
+ Rack applications take a PATHNAME to the L<rackup(1)> config file
617
+ (e.g. "config.ru") as its first argument.
618
+
619
+ The only supported keyword argument is:
620
+
621
+ =over
622
+
623
+ =item preload: BOOLEAN
624
+
625
+ preload: only makes sense if worker_processes are configured.
626
+ Preloading an app allows memory to be saved under a copy-on-write GC,
627
+ but will often require atfork_* hooks to be registered when configuring
628
+ worker_processes. preload: defaults to false for maximum out-of-the-box
629
+ compatibility.
630
+
631
+ =back
632
+
633
+ =head2 RACK APP EXAMPLE
634
+
635
+ app(:rack, "/path/to/config.ru", preload: false) do
636
+ # APP-LEVEL DIRECTIVES GO HERE
637
+ end
638
+
639
+ =head1 EXAMPLES
640
+
641
+ See the examples/ directory in the git source tree.
642
+
643
+ git clone git://yhbt.net/yahns.git
644
+
645
+ =head1 CONTACT
646
+
647
+ All feedback welcome via plain-text mail to L<mailto:yahns-public@yhbt.net>
648
+ No subscription is necessary to post to the mailing list.
649
+ List archives are available at L<http://yhbt.net/yahns-public/>
650
+
651
+ =head1 COPYRIGHT
652
+
653
+ Copyright (C) 2013-2016 all contributors L<mailto:yahns-public@yhbt.net>
654
+ License: GPL-3.0+ L<http://www.gnu.org/licenses/gpl-3.0.txt>
655
+
656
+ =head1 SEE ALSO
657
+
658
+ L<yahns(1)>