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
- #compiled_template_puma(from, role) ⇒ Object
- #puma_bind ⇒ Object
- #puma_binds ⇒ Object
- #puma_switch_user(role, &block) ⇒ Object
- #puma_user(role) ⇒ Object
- #service_unit_type ⇒ Object
- #template_puma(from, to, role) ⇒ Object
Instance Method Details
#compiled_template_puma(from, role) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/capistrano/puma.rb', line 40 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.("../templates/#{from}.erb", __FILE__), File.("../templates/#{from}.rb.erb", __FILE__) ].detect { |path| File.file?(path) } erb = File.read(file) if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.6') StringIO.new(ERB.new(erb, nil, '-').result(binding)) else StringIO.new(ERB.new(erb, trim_mode: '-').result(binding)) end end |
#puma_bind ⇒ Object
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_binds ⇒ Object
99 100 101 102 103 104 |
# File 'lib/capistrano/puma.rb', line 99 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 14 15 |
# File 'lib/capistrano/puma.rb', line 6 def puma_switch_user(role, &block) user = puma_user(role) if user == role.user block.call else backend.as user do block.call end end end |
#puma_user(role) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/capistrano/puma.rb', line 17 def puma_user(role) properties = role.properties properties.fetch(:puma_user) || # local property for puma only fetch(:puma_user) || properties.fetch(:run_as) || # global property across multiple capistrano gems role.user end |
#service_unit_type ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/capistrano/puma.rb', line 31 def service_unit_type ## Jruby don't support notify return "simple" if RUBY_ENGINE == "jruby" fetch(:puma_service_unit_type, ## Check if sd_notify is available in the bundle Gem::Specification.find_all_by_name("sd_notify").any? ? "notify" : "simple") end |
#template_puma(from, to, role) ⇒ Object
63 64 65 |
# File 'lib/capistrano/puma.rb', line 63 def template_puma(from, to, role) backend.upload! compiled_template_puma(from, role), to end |