Skip to content

Commit 622413d

Browse files
committed
Add a Puma launcher
1 parent a3c0ed4 commit 622413d

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

lib/proxy/launcher.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,16 @@ def launch
7979

8080
::Proxy::PluginInitializer.new(plugins).initialize_plugins
8181

82-
require 'proxy/launcher/webrick'
83-
launcher = ::Launcher::Webrick.new(self)
82+
case settings.http_server_type
83+
when 'webrick'
84+
require 'proxy/launcher/webrick'
85+
launcher = ::Launcher::Webrick.new(self)
86+
when 'puma'
87+
require 'proxy/launcher/puma'
88+
launcher = ::Launcher::Puma.new(self)
89+
else
90+
fail "Unknown http_server_type: #{settings.http_server_type}"
91+
end
8492

8593
launcher.launch
8694
rescue SignalException => e

lib/proxy/launcher/puma.rb

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
require 'puma'
2+
require 'puma/configuration'
3+
require 'proxy/app'
4+
5+
module Launcher
6+
class Puma
7+
attr_reader :launcher
8+
9+
def initialize(launcher)
10+
@launcher = launcher
11+
end
12+
13+
def launch
14+
::Puma::Launcher.new(conf).run
15+
end
16+
17+
private
18+
19+
def conf
20+
::Puma::Configuration.new do |user_config|
21+
user_config.environment('production')
22+
user_config.app(app)
23+
24+
if launcher.http_enabled?
25+
bind_hosts do |host|
26+
user_config.bind "tcp://#{host}:#{settings.http_port}"
27+
end
28+
end
29+
30+
if launcher.https_enabled?
31+
ssl_options = {
32+
key: settings.ssl_private_key,
33+
cert: settings.ssl_certificate,
34+
ca: settings.ssl_ca_file,
35+
ssl_cipher_filter: launcher.ciphers.join(':'),
36+
verify_mode: 'peer',
37+
no_tlsv1: true,
38+
no_tlsv1_1: true,
39+
}
40+
41+
bind_hosts do |host|
42+
user_config.ssl_bind(host, settings.https_port, ssl_options)
43+
end
44+
end
45+
46+
user_config.on_restart do
47+
::Proxy::LogBuffer::Decorator.instance.roll_log = true
48+
end
49+
50+
begin
51+
user_config.plugin('systemd')
52+
rescue ::Puma::UnknownPlugin
53+
end
54+
end
55+
end
56+
57+
def app
58+
::Proxy::App.new(launcher.plugins)
59+
end
60+
61+
def binds
62+
end
63+
64+
def bind_hosts
65+
settings.bind_host.each do |host|
66+
if host == '*'
67+
yield ipv6_enabled? ? '[::]' : '0.0.0.0'
68+
else
69+
begin
70+
addr = IPAddr.new(host)
71+
yield addr.ipv6? ? "[#{addr}]" : addr.to_s
72+
rescue IPAddr::InvalidAddressError
73+
yield host
74+
end
75+
end
76+
end
77+
end
78+
79+
def settings
80+
launcher.settings
81+
end
82+
83+
def ipv6_enabled?
84+
File.exist?('/proc/net/if_inet6') || (RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
85+
end
86+
end
87+
end

lib/proxy/settings/global.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module ::Proxy::Settings
22
class Global < ::OpenStruct
33
DEFAULT_SETTINGS = {
44
:settings_directory => Pathname.new(__dir__).join("..", "..", "..", "config", "settings.d").expand_path.to_s,
5+
:http_server_type => 'puma',
56
:https_port => 8443,
67
:log_file => "/var/log/foreman-proxy/proxy.log",
78
:file_rolling_keep => 6,

0 commit comments

Comments
 (0)