Class: Capistrano::Puma::Systemd

Inherits:
Capistrano::Plugin
  • Object
show all
Includes:
Capistrano::PumaCommon
Defined in:
lib/capistrano/puma/systemd.rb

Instance Method Summary collapse

Methods included from Capistrano::PumaCommon

#compiled_template_puma, #puma_bind, #puma_binds, #puma_switch_user, #puma_user, #service_unit_type, #template_puma

Instance Method Details

#define_tasksObject



9
10
11
# File 'lib/capistrano/puma/systemd.rb', line 9

def define_tasks
  eval_rakefile File.expand_path('../../tasks/systemd.rake', __FILE__)
end

#execute_systemd(*args) ⇒ Object



59
60
61
# File 'lib/capistrano/puma/systemd.rb', line 59

def execute_systemd(*args)
  sudo_if_needed(*systemd_command(*args))
end

#expanded_bundle_commandObject



28
29
30
# File 'lib/capistrano/puma/systemd.rb', line 28

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

#fetch_systemd_unit_pathObject



32
33
34
35
36
37
38
39
# File 'lib/capistrano/puma/systemd.rb', line 32

def fetch_systemd_unit_path
  if fetch(:puma_systemctl_user) == :system
    "/etc/systemd/system/"
  else
    home_dir = backend.capture :pwd
    File.join(home_dir, ".config", "systemd", "user")
  end
end

#register_hooksObject



5
6
7
# File 'lib/capistrano/puma/systemd.rb', line 5

def register_hooks
  after 'deploy:finished', 'puma:smart_restart'
end

#set_defaultsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/capistrano/puma/systemd.rb', line 13

def set_defaults
  set_if_empty :puma_systemctl_bin, -> { fetch(:systemctl_bin, '/bin/systemctl') }
  set_if_empty :puma_service_unit_name, -> { "#{fetch(:application)}_puma_#{fetch(:stage)}" }
  set_if_empty :puma_enable_socket_service, false

  set_if_empty :puma_service_unit_env_files, -> { fetch(:service_unit_env_files, []) }
  set_if_empty :puma_service_unit_env_vars, -> { fetch(:service_unit_env_vars, []) }

  set_if_empty :puma_systemctl_user, -> { fetch(:systemctl_user, :user) }
  set_if_empty :puma_enable_lingering, -> { fetch(:puma_systemctl_user) != :system }
  set_if_empty :puma_lingering_user, -> { fetch(:lingering_user, fetch(:user)) }

  set_if_empty :puma_service_templates_path, fetch(:service_templates_path, 'config/deploy/templates')
end

#sudo_if_needed(*command) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/capistrano/puma/systemd.rb', line 51

def sudo_if_needed(*command)
  if fetch(:puma_systemctl_user) == :system
    backend.sudo command.map(&:to_s).join(" ")
  else
    backend.execute(*command)
  end
end

#systemd_command(*args) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/capistrano/puma/systemd.rb', line 41

def systemd_command(*args)
  command = [fetch(:puma_systemctl_bin)]

  unless fetch(:puma_systemctl_user) == :system
    command << "--user"
  end

  command + args
end