Module: Capistrano::PumaCommon

Included in:
Puma, Capistrano::Puma::Nginx, Capistrano::Puma::Systemd
Defined in:
lib/capistrano/puma.rb

Defined Under Namespace

Classes: PumaBind

Instance Method Summary collapse

Instance Method Details

#compiled_template_puma(from, role) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/capistrano/puma.rb', line 38

def compiled_template_puma(from, role)
  @role = role
  file = [
      "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
      "lib/capistrano/templates/#{from}-#{role.hostname}.rb",
      "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb",
      "lib/capistrano/templates/#{from}.rb.erb",
      "lib/capistrano/templates/#{from}.rb",
      "lib/capistrano/templates/#{from}.erb",
      "config/deploy/templates/#{from}.rb.erb",
      "config/deploy/templates/#{from}.rb",
      "config/deploy/templates/#{from}.erb",
      File.expand_path("../templates/#{from}.erb", __FILE__),
      File.expand_path("../templates/#{from}.rb.erb", __FILE__)
  ].detect { |path| File.file?(path) }
  erb = File.read(file)
  StringIO.new(ERB.new(erb, trim_mode: '-').result(binding))
end

#expanded_bundle_commandObject



100
101
102
# File 'lib/capistrano/puma.rb', line 100

def expanded_bundle_command
  backend.capture(:echo, SSHKit.config.command_map[:bundle]).strip
end

#puma_bindObject



25
26
27
28
29
# File 'lib/capistrano/puma.rb', line 25

def puma_bind
  Array(fetch(:puma_bind)).collect do |bind|
    "bind '#{bind}'"
  end.join("\n")
end

#puma_bindsObject



93
94
95
96
97
98
# File 'lib/capistrano/puma.rb', line 93

def puma_binds
  Array(fetch(:puma_bind)).map do |m|
    etype, address  = /(tcp|unix|ssl):\/{1,2}(.+)/.match(m).captures
    PumaBind.new(m, etype.to_sym, address)
  end
end

#puma_switch_user(role, &block) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/capistrano/puma.rb', line 6

def puma_switch_user(role, &block)
  user = puma_user(role)
  if user == role.user
    yield
  else
    backend.as(user, &block)
  end
end

#puma_user(role) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/capistrano/puma.rb', line 15

def puma_user(role)
  properties = role.properties
  return role.user unless properties

  properties.fetch(:puma_user) || # local property for puma only
      fetch(:puma_user, nil) ||
      properties.fetch(:run_as) || # global property across multiple capistrano gems
      role.user
end

#service_unit_typeObject



31
32
33
34
35
36
# File 'lib/capistrano/puma.rb', line 31

def service_unit_type
  ## Jruby don't support notify
  return "simple" if RUBY_ENGINE == "jruby"
  ## Puma 6.1+ has built-in sd_notify support
  fetch(:puma_service_unit_type, "notify")
end

#template_puma(from, to, role) ⇒ Object



57
58
59
# File 'lib/capistrano/puma.rb', line 57

def template_puma(from, to, role)
  backend.upload! compiled_template_puma(from, role), to
end