jun-puma 1.0.0-java
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/History.md +2897 -0
- data/LICENSE +29 -0
- data/README.md +475 -0
- data/bin/puma +10 -0
- data/bin/puma-wild +25 -0
- data/bin/pumactl +12 -0
- data/docs/architecture.md +74 -0
- data/docs/compile_options.md +55 -0
- data/docs/deployment.md +102 -0
- data/docs/fork_worker.md +35 -0
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/jungle/README.md +9 -0
- data/docs/jungle/rc.d/README.md +74 -0
- data/docs/jungle/rc.d/puma +61 -0
- data/docs/jungle/rc.d/puma.conf +10 -0
- data/docs/kubernetes.md +78 -0
- data/docs/nginx.md +80 -0
- data/docs/plugins.md +38 -0
- data/docs/rails_dev_mode.md +28 -0
- data/docs/restart.md +65 -0
- data/docs/signals.md +98 -0
- data/docs/stats.md +142 -0
- data/docs/systemd.md +253 -0
- data/docs/testing_benchmarks_local_files.md +150 -0
- data/docs/testing_test_rackup_ci_files.md +36 -0
- data/ext/puma_http11/PumaHttp11Service.java +17 -0
- data/ext/puma_http11/ext_help.h +15 -0
- data/ext/puma_http11/extconf.rb +80 -0
- data/ext/puma_http11/http11_parser.c +1057 -0
- data/ext/puma_http11/http11_parser.h +65 -0
- data/ext/puma_http11/http11_parser.java.rl +145 -0
- data/ext/puma_http11/http11_parser.rl +149 -0
- data/ext/puma_http11/http11_parser_common.rl +54 -0
- data/ext/puma_http11/mini_ssl.c +842 -0
- data/ext/puma_http11/no_ssl/PumaHttp11Service.java +15 -0
- data/ext/puma_http11/org/jruby/puma/Http11.java +228 -0
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +455 -0
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +509 -0
- data/ext/puma_http11/puma_http11.c +495 -0
- data/lib/puma/app/status.rb +96 -0
- data/lib/puma/binder.rb +502 -0
- data/lib/puma/cli.rb +247 -0
- data/lib/puma/client.rb +682 -0
- data/lib/puma/cluster/worker.rb +180 -0
- data/lib/puma/cluster/worker_handle.rb +96 -0
- data/lib/puma/cluster.rb +616 -0
- data/lib/puma/commonlogger.rb +115 -0
- data/lib/puma/configuration.rb +390 -0
- data/lib/puma/const.rb +307 -0
- data/lib/puma/control_cli.rb +316 -0
- data/lib/puma/detect.rb +45 -0
- data/lib/puma/dsl.rb +1425 -0
- data/lib/puma/error_logger.rb +113 -0
- data/lib/puma/events.rb +57 -0
- data/lib/puma/io_buffer.rb +46 -0
- data/lib/puma/jruby_restart.rb +11 -0
- data/lib/puma/json_serialization.rb +96 -0
- data/lib/puma/launcher/bundle_pruner.rb +104 -0
- data/lib/puma/launcher.rb +488 -0
- data/lib/puma/log_writer.rb +147 -0
- data/lib/puma/minissl/context_builder.rb +96 -0
- data/lib/puma/minissl.rb +459 -0
- data/lib/puma/null_io.rb +84 -0
- data/lib/puma/plugin/systemd.rb +90 -0
- data/lib/puma/plugin/tmp_restart.rb +36 -0
- data/lib/puma/plugin.rb +111 -0
- data/lib/puma/puma_http11.jar +0 -0
- data/lib/puma/rack/builder.rb +297 -0
- data/lib/puma/rack/urlmap.rb +93 -0
- data/lib/puma/rack_default.rb +24 -0
- data/lib/puma/reactor.rb +125 -0
- data/lib/puma/request.rb +688 -0
- data/lib/puma/runner.rb +213 -0
- data/lib/puma/sd_notify.rb +149 -0
- data/lib/puma/server.rb +680 -0
- data/lib/puma/single.rb +69 -0
- data/lib/puma/state_file.rb +68 -0
- data/lib/puma/thread_pool.rb +434 -0
- data/lib/puma/util.rb +141 -0
- data/lib/puma.rb +78 -0
- data/lib/rack/handler/puma.rb +144 -0
- data/tools/Dockerfile +16 -0
- data/tools/trickletest.rb +44 -0
- metadata +153 -0
data/lib/puma/runner.rb
ADDED
@@ -0,0 +1,213 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'server'
|
4
|
+
require_relative 'const'
|
5
|
+
|
6
|
+
module Puma
|
7
|
+
# Generic class that is used by `Puma::Cluster` and `Puma::Single` to
|
8
|
+
# serve requests. This class spawns a new instance of `Puma::Server` via
|
9
|
+
# a call to `start_server`.
|
10
|
+
class Runner
|
11
|
+
def initialize(launcher)
|
12
|
+
@launcher = launcher
|
13
|
+
@log_writer = launcher.log_writer
|
14
|
+
@events = launcher.events
|
15
|
+
@config = launcher.config
|
16
|
+
@options = launcher.options
|
17
|
+
@app = nil
|
18
|
+
@control = nil
|
19
|
+
@started_at = Time.now
|
20
|
+
@wakeup = nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the hash of configuration options.
|
24
|
+
# @return [Puma::UserFileDefaultOptions]
|
25
|
+
attr_reader :options
|
26
|
+
|
27
|
+
def wakeup!
|
28
|
+
return unless @wakeup
|
29
|
+
|
30
|
+
@wakeup.write Puma::Const::PipeRequest::WAKEUP unless @wakeup.closed?
|
31
|
+
|
32
|
+
rescue SystemCallError, IOError
|
33
|
+
Puma::Util.purge_interrupt_queue
|
34
|
+
end
|
35
|
+
|
36
|
+
def development?
|
37
|
+
@options[:environment] == "development"
|
38
|
+
end
|
39
|
+
|
40
|
+
def test?
|
41
|
+
@options[:environment] == "test"
|
42
|
+
end
|
43
|
+
|
44
|
+
def log(str)
|
45
|
+
@log_writer.log str
|
46
|
+
end
|
47
|
+
|
48
|
+
# @version 5.0.0
|
49
|
+
def stop_control
|
50
|
+
@control&.stop true
|
51
|
+
end
|
52
|
+
|
53
|
+
def error(str)
|
54
|
+
@log_writer.error str
|
55
|
+
end
|
56
|
+
|
57
|
+
def debug(str)
|
58
|
+
@log_writer.log "- #{str}" if @options[:debug]
|
59
|
+
end
|
60
|
+
|
61
|
+
def start_control
|
62
|
+
str = @options[:control_url]
|
63
|
+
return unless str
|
64
|
+
|
65
|
+
require_relative 'app/status'
|
66
|
+
|
67
|
+
if token = @options[:control_auth_token]
|
68
|
+
token = nil if token.empty? || token == 'none'
|
69
|
+
end
|
70
|
+
|
71
|
+
app = Puma::App::Status.new @launcher, token
|
72
|
+
|
73
|
+
# A Reactor is not created and nio4r is not loaded when 'queue_requests: false'
|
74
|
+
# Use `nil` for events, no hooks in control server
|
75
|
+
control = Puma::Server.new app, nil,
|
76
|
+
{ min_threads: 0, max_threads: 1, queue_requests: false, log_writer: @log_writer }
|
77
|
+
|
78
|
+
begin
|
79
|
+
control.binder.parse [str], nil, 'Starting control server'
|
80
|
+
rescue Errno::EADDRINUSE, Errno::EACCES => e
|
81
|
+
raise e, "Error: Control server address '#{str}' is already in use. Original error: #{e.message}"
|
82
|
+
end
|
83
|
+
|
84
|
+
control.run thread_name: 'ctl'
|
85
|
+
@control = control
|
86
|
+
end
|
87
|
+
|
88
|
+
# @version 5.0.0
|
89
|
+
def close_control_listeners
|
90
|
+
@control.binder.close_listeners if @control
|
91
|
+
end
|
92
|
+
|
93
|
+
# @!attribute [r] ruby_engine
|
94
|
+
def ruby_engine
|
95
|
+
if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
|
96
|
+
"ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
97
|
+
else
|
98
|
+
if defined?(RUBY_ENGINE_VERSION)
|
99
|
+
"#{RUBY_ENGINE} #{RUBY_ENGINE_VERSION} - ruby #{RUBY_VERSION}"
|
100
|
+
else
|
101
|
+
"#{RUBY_ENGINE} #{RUBY_VERSION}"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def output_header(mode)
|
107
|
+
min_t = @options[:min_threads]
|
108
|
+
max_t = @options[:max_threads]
|
109
|
+
environment = @options[:environment]
|
110
|
+
|
111
|
+
log "Puma starting in #{mode} mode..."
|
112
|
+
log "* Puma version: #{Puma::Const::PUMA_VERSION} (#{ruby_engine}) (\"#{Puma::Const::CODE_NAME}\")"
|
113
|
+
log "* Min threads: #{min_t}"
|
114
|
+
log "* Max threads: #{max_t}"
|
115
|
+
log "* Environment: #{environment}"
|
116
|
+
|
117
|
+
if mode == "cluster"
|
118
|
+
log "* Master PID: #{Process.pid}"
|
119
|
+
else
|
120
|
+
log "* PID: #{Process.pid}"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def redirected_io?
|
125
|
+
@options[:redirect_stdout] || @options[:redirect_stderr]
|
126
|
+
end
|
127
|
+
|
128
|
+
def redirect_io
|
129
|
+
stdout = @options[:redirect_stdout]
|
130
|
+
stderr = @options[:redirect_stderr]
|
131
|
+
append = @options[:redirect_append]
|
132
|
+
|
133
|
+
if stdout
|
134
|
+
ensure_output_directory_exists(stdout, 'STDOUT')
|
135
|
+
|
136
|
+
STDOUT.reopen stdout, (append ? "a" : "w")
|
137
|
+
STDOUT.puts "=== puma startup: #{Time.now} ==="
|
138
|
+
STDOUT.flush unless STDOUT.sync
|
139
|
+
end
|
140
|
+
|
141
|
+
if stderr
|
142
|
+
ensure_output_directory_exists(stderr, 'STDERR')
|
143
|
+
|
144
|
+
STDERR.reopen stderr, (append ? "a" : "w")
|
145
|
+
STDERR.puts "=== puma startup: #{Time.now} ==="
|
146
|
+
STDERR.flush unless STDERR.sync
|
147
|
+
end
|
148
|
+
|
149
|
+
if @options[:mutate_stdout_and_stderr_to_sync_on_write]
|
150
|
+
STDOUT.sync = true
|
151
|
+
STDERR.sync = true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
def load_and_bind
|
156
|
+
unless @config.app_configured?
|
157
|
+
error "No application configured, nothing to run"
|
158
|
+
exit 1
|
159
|
+
end
|
160
|
+
|
161
|
+
begin
|
162
|
+
@app = @config.app
|
163
|
+
rescue Exception => e
|
164
|
+
log "! Unable to load application: #{e.class}: #{e.message}"
|
165
|
+
raise e
|
166
|
+
end
|
167
|
+
|
168
|
+
@launcher.binder.parse @options[:binds]
|
169
|
+
end
|
170
|
+
|
171
|
+
# @!attribute [r] app
|
172
|
+
def app
|
173
|
+
@app ||= @config.app
|
174
|
+
end
|
175
|
+
|
176
|
+
def start_server
|
177
|
+
server = Puma::Server.new(app, @events, @options)
|
178
|
+
server.inherit_binder(@launcher.binder)
|
179
|
+
server
|
180
|
+
end
|
181
|
+
|
182
|
+
private
|
183
|
+
def ensure_output_directory_exists(path, io_name)
|
184
|
+
unless Dir.exist?(File.dirname(path))
|
185
|
+
raise "Cannot redirect #{io_name} to #{path}"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def utc_iso8601(val)
|
190
|
+
"#{val.utc.strftime '%FT%T'}Z"
|
191
|
+
end
|
192
|
+
|
193
|
+
def stats
|
194
|
+
{
|
195
|
+
versions: {
|
196
|
+
puma: Puma::Const::PUMA_VERSION,
|
197
|
+
ruby: {
|
198
|
+
engine: RUBY_ENGINE,
|
199
|
+
version: RUBY_VERSION,
|
200
|
+
patchlevel: RUBY_PATCHLEVEL
|
201
|
+
}
|
202
|
+
}
|
203
|
+
}
|
204
|
+
end
|
205
|
+
|
206
|
+
# this method call should always be guarded by `@log_writer.debug?`
|
207
|
+
def debug_loaded_extensions(str)
|
208
|
+
@log_writer.debug "────────────────────────────────── #{str}"
|
209
|
+
re_ext = /\.#{RbConfig::CONFIG['DLEXT']}\z/i
|
210
|
+
$LOADED_FEATURES.grep(re_ext).each { |f| @log_writer.debug(" #{f}") }
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,149 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "socket"
|
4
|
+
|
5
|
+
module Puma
|
6
|
+
# The MIT License
|
7
|
+
#
|
8
|
+
# Copyright (c) 2017-2022 Agis Anastasopoulos
|
9
|
+
#
|
10
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
11
|
+
# this software and associated documentation files (the "Software"), to deal in
|
12
|
+
# the Software without restriction, including without limitation the rights to
|
13
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
14
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
15
|
+
# subject to the following conditions:
|
16
|
+
#
|
17
|
+
# The above copyright notice and this permission notice shall be included in all
|
18
|
+
# copies or substantial portions of the Software.
|
19
|
+
#
|
20
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
22
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
23
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
24
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
25
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
26
|
+
#
|
27
|
+
# This is a copy of https://github.com/agis/ruby-sdnotify as of commit cca575c
|
28
|
+
# The only changes made was "rehoming" it within the Puma module to avoid
|
29
|
+
# namespace collisions and applying standard's code formatting style.
|
30
|
+
#
|
31
|
+
# SdNotify is a pure-Ruby implementation of sd_notify(3). It can be used to
|
32
|
+
# notify systemd about state changes. Methods of this package are no-op on
|
33
|
+
# non-systemd systems (eg. Darwin).
|
34
|
+
#
|
35
|
+
# The API maps closely to the original implementation of sd_notify(3),
|
36
|
+
# therefore be sure to check the official man pages prior to using SdNotify.
|
37
|
+
#
|
38
|
+
# @see https://www.freedesktop.org/software/systemd/man/sd_notify.html
|
39
|
+
module SdNotify
|
40
|
+
# Exception raised when there's an error writing to the notification socket
|
41
|
+
class NotifyError < RuntimeError; end
|
42
|
+
|
43
|
+
READY = "READY=1"
|
44
|
+
RELOADING = "RELOADING=1"
|
45
|
+
STOPPING = "STOPPING=1"
|
46
|
+
STATUS = "STATUS="
|
47
|
+
ERRNO = "ERRNO="
|
48
|
+
MAINPID = "MAINPID="
|
49
|
+
WATCHDOG = "WATCHDOG=1"
|
50
|
+
FDSTORE = "FDSTORE=1"
|
51
|
+
|
52
|
+
def self.ready(unset_env=false)
|
53
|
+
notify(READY, unset_env)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.reloading(unset_env=false)
|
57
|
+
notify(RELOADING, unset_env)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.stopping(unset_env=false)
|
61
|
+
notify(STOPPING, unset_env)
|
62
|
+
end
|
63
|
+
|
64
|
+
# @param status [String] a custom status string that describes the current
|
65
|
+
# state of the service
|
66
|
+
def self.status(status, unset_env=false)
|
67
|
+
notify("#{STATUS}#{status}", unset_env)
|
68
|
+
end
|
69
|
+
|
70
|
+
# @param errno [Integer]
|
71
|
+
def self.errno(errno, unset_env=false)
|
72
|
+
notify("#{ERRNO}#{errno}", unset_env)
|
73
|
+
end
|
74
|
+
|
75
|
+
# @param pid [Integer]
|
76
|
+
def self.mainpid(pid, unset_env=false)
|
77
|
+
notify("#{MAINPID}#{pid}", unset_env)
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.watchdog(unset_env=false)
|
81
|
+
notify(WATCHDOG, unset_env)
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.fdstore(unset_env=false)
|
85
|
+
notify(FDSTORE, unset_env)
|
86
|
+
end
|
87
|
+
|
88
|
+
# @param [Boolean] true if the service manager expects watchdog keep-alive
|
89
|
+
# notification messages to be sent from this process.
|
90
|
+
#
|
91
|
+
# If the $WATCHDOG_USEC environment variable is set,
|
92
|
+
# and the $WATCHDOG_PID variable is unset or set to the PID of the current
|
93
|
+
# process
|
94
|
+
#
|
95
|
+
# @note Unlike sd_watchdog_enabled(3), this method does not mutate the
|
96
|
+
# environment.
|
97
|
+
def self.watchdog?
|
98
|
+
wd_usec = ENV["WATCHDOG_USEC"]
|
99
|
+
wd_pid = ENV["WATCHDOG_PID"]
|
100
|
+
|
101
|
+
return false if !wd_usec
|
102
|
+
|
103
|
+
begin
|
104
|
+
wd_usec = Integer(wd_usec)
|
105
|
+
rescue
|
106
|
+
return false
|
107
|
+
end
|
108
|
+
|
109
|
+
return false if wd_usec <= 0
|
110
|
+
return true if !wd_pid || wd_pid == $$.to_s
|
111
|
+
|
112
|
+
false
|
113
|
+
end
|
114
|
+
|
115
|
+
# Notify systemd with the provided state, via the notification socket, if
|
116
|
+
# any.
|
117
|
+
#
|
118
|
+
# Generally this method will be used indirectly through the other methods
|
119
|
+
# of the library.
|
120
|
+
#
|
121
|
+
# @param state [String]
|
122
|
+
# @param unset_env [Boolean]
|
123
|
+
#
|
124
|
+
# @return [Fixnum, nil] the number of bytes written to the notification
|
125
|
+
# socket or nil if there was no socket to report to (eg. the program wasn't
|
126
|
+
# started by systemd)
|
127
|
+
#
|
128
|
+
# @raise [NotifyError] if there was an error communicating with the systemd
|
129
|
+
# socket
|
130
|
+
#
|
131
|
+
# @see https://www.freedesktop.org/software/systemd/man/sd_notify.html
|
132
|
+
def self.notify(state, unset_env=false)
|
133
|
+
sock = ENV["NOTIFY_SOCKET"]
|
134
|
+
|
135
|
+
return nil if !sock
|
136
|
+
|
137
|
+
ENV.delete("NOTIFY_SOCKET") if unset_env
|
138
|
+
|
139
|
+
begin
|
140
|
+
Addrinfo.unix(sock, :DGRAM).connect do |s|
|
141
|
+
s.close_on_exec = true
|
142
|
+
s.write(state)
|
143
|
+
end
|
144
|
+
rescue StandardError => e
|
145
|
+
raise NotifyError, "#{e.class}: #{e.message}", e.backtrace
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|