Skip to content

Commit

Permalink
Add a Puma launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ekohl committed Oct 2, 2020
1 parent a612c81 commit 288d96c
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/proxy/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,16 @@ def launch

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

require 'proxy/launcher/webrick'
launcher = ::Launcher::Webrick.new(self)
case settings.http_server_type
when 'webrick'
require 'proxy/launcher/webrick'
launcher = ::Launcher::Webrick.new(self)
when 'puma'
require 'proxy/launcher/puma'
launcher = ::Launcher::Puma.new(self)
else
fail "Unknown http_server_type: #{settings.http_server_type}"
end

launcher.launch
rescue SignalException => e
Expand Down
87 changes: 87 additions & 0 deletions lib/proxy/launcher/puma.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
require 'puma'
require 'puma/configuration'
require 'proxy/app'

module Launcher
class Puma
attr_reader :launcher

def initialize(launcher)
@launcher = launcher
end

def launch
::Puma::Launcher.new(conf).run
end

private

def conf
::Puma::Configuration.new do |user_config|
user_config.environment('production')
user_config.app(app)

if launcher.http_enabled?
bind_hosts do |host|
user_config.bind "tcp://#{host}:#{settings.http_port}"
end
end

if launcher.https_enabled?
ssl_options = {
key: settings.ssl_private_key,
cert: settings.ssl_certificate,
ca: settings.ssl_ca_file,
ssl_cipher_filter: launcher.ciphers.join(':'),
verify_mode: 'peer',
no_tlsv1: true,
no_tlsv1_1: true,
}

bind_hosts do |host|
user_config.ssl_bind(host, settings.https_port, ssl_options)
end
end

user_config.on_restart do
::Proxy::LogBuffer::Decorator.instance.roll_log = true
end

begin
user_config.plugin('systemd')
rescue ::Puma::UnknownPlugin
end
end
end

def app
::Proxy::App.new(launcher.plugins)
end

def binds
end

def bind_hosts
settings.bind_host.each do |host|
if host == '*'
yield ipv6_enabled? ? '[::]' : '0.0.0.0'
else
begin
addr = IPAddr.new(host)
yield addr.ipv6? ? "[#{addr}]" : addr.to_s
rescue IPAddr::InvalidAddressError
yield host
end
end
end
end

def settings
launcher.settings
end

def ipv6_enabled?
File.exist?('/proc/net/if_inet6') || (RUBY_PLATFORM =~ /cygwin|mswin|mingw|bccwin|wince|emx/)
end
end
end
1 change: 1 addition & 0 deletions lib/proxy/settings/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module ::Proxy::Settings
class Global < ::OpenStruct
DEFAULT_SETTINGS = {
:settings_directory => Pathname.new(__dir__).join("..", "..", "..", "config", "settings.d").expand_path.to_s,
:http_server_type => 'puma',
:https_port => 8443,
:log_file => "/var/log/foreman-proxy/proxy.log",
:file_rolling_keep => 6,
Expand Down

0 comments on commit 288d96c

Please sign in to comment.