Class: BoringServices::Installer

Inherits:
Object
  • Object
show all
Defined in:
lib/boring_services/installer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Installer

Returns a new instance of Installer.



5
6
7
8
# File 'lib/boring_services/installer.rb', line 5

def initialize(config)
  @config = config
  @ssh_executor = SSHExecutor.new(config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/boring_services/installer.rb', line 3

def config
  @config
end

#ssh_executorObject (readonly)

Returns the value of attribute ssh_executor.



3
4
5
# File 'lib/boring_services/installer.rb', line 3

def ssh_executor
  @ssh_executor
end

Instance Method Details

#install_allObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/boring_services/installer.rb', line 10

def install_all
  puts 'Installing enabled services...'
  credentials_hints = []
  config.enabled_services.each do |service|
    result = install_service_entry(service)
    credentials_hints << result if result.is_a?(Hash)
  end
  puts 'All services installed successfully!'
  print_credentials_summary(credentials_hints) if credentials_hints.any?
end

#install_service(service_name) ⇒ Object

Raises:



21
22
23
24
25
26
27
# File 'lib/boring_services/installer.rb', line 21

def install_service(service_name)
  service = config.service_config(service_name)
  raise Error, "Service #{service_name} not found in configuration" unless service
  raise Error, "Service #{service_name} is disabled" if service['enabled'] == false

  install_service_entry(service)
end

#install_service_entry(service) ⇒ Object

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/boring_services/installer.rb', line 29

def install_service_entry(service)
  service_name = service['name']
  service_label = service['label'] || service['host']
  raise Error, "Service #{service_name} is disabled" if service['enabled'] == false

  puts "\nInstalling #{service_name}..."
  service_class = get_service_class(service_name)
  service_instance = service_class.new(config, ssh_executor, service)
  result = service_instance.install
  puts "#{service_name} installed (#{service_label})"
  result
end

#reconfigure_allObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/boring_services/installer.rb', line 76

def reconfigure_all
  puts 'Reconfiguring enabled services...'
  credentials_hints = []
  config.enabled_services.each do |service|
    result = reconfigure_service_entry(service)
    credentials_hints << result if result.is_a?(Hash)
  end
  puts 'All services reconfigured successfully!'
  print_credentials_summary(credentials_hints) if credentials_hints.any?
end

#reconfigure_service(service_name) ⇒ Object

Raises:



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/boring_services/installer.rb', line 64

def reconfigure_service(service_name)
  service = config.service_config(service_name)
  raise Error, "Service #{service_name} not found in configuration" unless service
  raise Error, "Service #{service_name} is disabled" if service['enabled'] == false

  puts "\nReconfiguring #{service_name}..."
  service_class = get_service_class(service_name)
  service_instance = service_class.new(config, ssh_executor, service)
  service_instance.reconfigure
  puts "#{service_name} reconfigured"
end

#reconfigure_service_entry(service) ⇒ Object

Raises:



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/boring_services/installer.rb', line 87

def reconfigure_service_entry(service)
  service_name = service['name']
  service_label = service['label'] || service['host']
  raise Error, "Service #{service_name} is disabled" if service['enabled'] == false

  puts "\nReconfiguring #{service_name}..."
  service_class = get_service_class(service_name)
  service_instance = service_class.new(config, ssh_executor, service)
  result = service_instance.reconfigure
  puts "#{service_name} reconfigured (#{service_label})"
  result
end

#restart_service(service_name) ⇒ Object

Raises:



53
54
55
56
57
58
59
60
61
62
# File 'lib/boring_services/installer.rb', line 53

def restart_service(service_name)
  service = config.service_config(service_name)
  raise Error, "Service #{service_name} not found in configuration" unless service

  puts "\nRestarting #{service_name}..."
  service_class = get_service_class(service_name)
  service_instance = service_class.new(config, ssh_executor, service)
  service_instance.restart
  puts "#{service_name} restarted"
end

#uninstall_service(service_name) ⇒ Object

Raises:



42
43
44
45
46
47
48
49
50
51
# File 'lib/boring_services/installer.rb', line 42

def uninstall_service(service_name)
  service = config.service_config(service_name)
  raise Error, "Service #{service_name} not found in configuration" unless service

  puts "\nUninstalling #{service_name}..."
  service_class = get_service_class(service_name)
  service_instance = service_class.new(config, ssh_executor, service)
  service_instance.uninstall
  puts "#{service_name} uninstalled"
end