Class: ThreeScale::Backend::Server::Puma

Inherits:
Object
  • Object
show all
Extended by:
Utils
Defined in:
lib/3scale/backend/server/puma.rb

Constant Summary collapse

CONFIG =
'config/puma.rb'
CONTROL_SOCKET =
'3scale_backend.sock'
STATE =
'3scale_backend.state'
EXPANDED_ROOT_PATH =
File.expand_path(File.join(*Array.new(5, '..')),
__FILE__)

Class Method Summary collapse

Methods included from Utils

argv_add

Class Method Details

.help(global_options, options, args) ⇒ Object



53
54
55
# File 'lib/3scale/backend/server/puma.rb', line 53

def self.help(global_options, options, args)
  system('puma --help')
end

.restart(global_options, options, args) ⇒ Object



43
44
45
# File 'lib/3scale/backend/server/puma.rb', line 43

def self.restart(global_options, options, args)
  build_pumactl_cmdline(options[:'phased-restart'] ? 'phased-restart' : 'restart', global_options, options, args)
end

.socket_state_dir(env, default_dir) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/3scale/backend/server/puma.rb', line 14

def self.socket_state_dir(env, default_dir)
  if ['development', 'test'].include?(env) && File.writable?(default_dir)
    default_dir
  else
    File.join('', 'tmp')
  end
end

.start(global_options, options, args) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/3scale/backend/server/puma.rb', line 22

def self.start(global_options, options, args)
  manifest = global_options[:manifest]
  return unless manifest
  argv = ['puma']
  argv_add argv, options[:daemonize], '-d'
  argv_add argv, options[:port], '-p', options[:port]
  argv_add argv, options[:logfile], '--redirect-stdout', options[:logfile]
  argv_add argv, options[:errorfile], '--redirect-stderr', options[:errorfile]
  argv << '--redirect-append' if [options[:logfile], options[:errorfile]].any?
  argv_add argv, options[:pidfile], '--pidfile', options[:pidfile]
  # workaround Puma bug not phase-restarting correctly if no --dir is specified
  argv_add argv, true, '--dir', global_options[:directory] ? global_options[:directory] : EXPANDED_ROOT_PATH
  argv_add argv, true, '-C', CONFIG
  ss_dir = socket_state_dir(global_options[:environment], global_options[:directory] || EXPANDED_ROOT_PATH)
  argv_add argv, true, '-S', File.join(ss_dir, STATE)
  argv_add argv, true, '--control', "unix://#{File.join(ss_dir, CONTROL_SOCKET)}"
  server_model = manifest[:server_model]
  argv_add argv, true, '-w', server_model[:workers].to_s
  argv_add argv, true, '-t', "#{server_model[:min_threads]}:#{server_model[:max_threads]}"
end