module Luban::Deployment::Applications::Rack::WebServers::Puma::Common

Public Instance Methods

control_socket_file_name() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 56
def control_socket_file_name
  @control_socket_file_name ||= "#{current_web_server}ctl.sock"
end
control_socket_file_path() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 52
def control_socket_file_path
  @control_socket_file_path ||= sockets_path.join(control_socket_file_name)
end
default_web_server_options() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 8
def default_web_server_options
   @default_web_server_options ||= {
     # Server options
     address: "127.0.0.1",
     port: port + 1,
     socket: socket_file_path.to_s,
     directory: release_path.to_s,
     environment: stage,
     rackup: release_path.join('config.ru').to_s,
     # Daemon options
     daemonize: !dockerized?,
     pidfile: pid_file_path.to_s,
     state_path: state_file_path.to_s,
     redirect_stdout: log_file_path.to_s,
     redirect_stderr: error_log_file_path.to_s,
     redirect_append: true,
     quiet: false,
     tag: "#{env_name}:#{release_tag}",
     # Cluster options
     servers: 2,
     threads: "1:1",
     preload: false,
     prune_bundler: true,
     # Control app options
     control_socket: control_socket_file_path.to_s,
     control_opts: { auth_token: port.to_s }
   }
 end
error_log_file_path() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 48
def error_log_file_path
  @error_log_file_path ||= log_path.join("#{current_web_server}_error.log")
end
process_pattern() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 72
def process_pattern
  @process_pattern ||= "^puma .+\\[#{Regexp.escape(env_name)}:.*\\]"
end
puma_command() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 60
def puma_command
  @puma_command ||= "pumactl -F #{control_file_path}"
end
service_entry() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 76
def service_entry
  @serivce_entry ||= "#{super}.#{current_web_server}"
end
start_command() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 64
def start_command
  @start_command ||= bundle_command("#{puma_command} start")
end
state_file_name() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 44
def state_file_name
  @state_file_name ||= "#{current_web_server}.state"
end
state_file_path() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 40
def state_file_path
  @state_file_path ||= pids_path.join(state_file_name)
end
stop_command() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 68
def stop_command
  @stop_command ||= bundle_command("#{puma_command} stop")
end
tcp_socket?() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 37
def tcp_socket?; @tcp_socket; end
unix_socket?() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 38
def unix_socket?; @unix_socket; end

Protected Instance Methods

init_docker_command() click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 82
def init_docker_command
  docker_command ["bundle", "exec", "puma", "-C", control_file_path.to_s]
end
parameterize(*args) click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 147
def parameterize(*args)
  args.map(&:inspect).join(", ")
end
set_control_options(opts) click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 128
def set_control_options(opts)
  control_socket = opts.delete(:control_socket)
  control_socket = "unix://#{control_socket}" unless control_socket == 'auto'
  control_opts = opts.delete(:control_opts)
  opts[:activate_control_app] = [ control_socket, control_opts ]
end
set_stdout_redirect_options(opts) click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 107
def set_stdout_redirect_options(opts)
  redirect_stdout = opts.delete(:redirect_stdout)
  redirect_stderr = opts.delete(:redirect_stderr)
  redirect_append = opts.delete(:redirect_append)
  opts[:stdout_redirect] = [ redirect_stdout, redirect_stderr, redirect_append ]
end
set_threads_options(opts) click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 122
def set_threads_options(opts)
  if opts[:threads].is_a?(String)
    opts[:threads] = opts[:threads].split(":").map(&:to_i)
  end
end
set_tuning_options(opts) click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 135
def set_tuning_options(opts)
  if opts[:prune_bundler]
    opts.delete(:preload)
  elsif opts[:preload]
    opts.delete(:prune_bundler)
    opts[:preload_app!] = opts.delete(:preload)
  else
    opts.delete(:prune_bundler)
    opts.delete(:preload)
  end
end
set_uri_options(opts) click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 94
def set_uri_options(opts)
  socket = opts.delete(:socket)
  address = opts.delete(:address)
  port = opts.delete(:port)
  @unix_socket = !!opts.delete(:unix_socket)
  @tcp_socket = !@unix_socket
  if unix_socket?
    opts[:bind] = "unix://#{socket}"
  else
    opts[:bind] = "tcp://#{address}:#{port}"
  end
end
set_web_server_options() click to toggle source
Calls superclass method
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 86
def set_web_server_options
  super.tap do |opts|
    [:uri, :stdout_redirect, :workers, :threads, :control, :tuning].each do |param|
      send("set_#{param}_options", opts)
    end
  end
end
set_workers_options(opts) click to toggle source
# File lib/luban/deployment/applications/rack/web_servers/puma.rb, line 114
def set_workers_options(opts)
  if dockerized?
    opts.delete(:servers)
  else
    opts[:workers] = opts.delete(:servers)
  end
end