Class: DanarchyDeploy::Services::Init

Inherits:
Object
  • Object
show all
Defined in:
lib/danarchy_deploy/services/init.rb,
lib/danarchy_deploy/services/init/openrc.rb,
lib/danarchy_deploy/services/init/systemd.rb

Defined Under Namespace

Classes: Openrc, Systemd

Class Method Summary collapse

Class Method Details

.init_manager(os, service, action, options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/danarchy_deploy/services/init.rb', line 29

def self.init_manager(os, service, action, options)
  init = if os == 'gentoo'
           DanarchyDeploy::Services::Init::Openrc.new(service, options)
         else
           DanarchyDeploy::Services::Init::Systemd.new(service, options)
         end

  init_result = init.send(action)

  if init_result[:stderr]
    if init_result[:stderr].include?('unknown function')
      puts "       ! Action: #{action} not available for service: #{service}.\n" +
           "          ! A restart may be needed! Otherwise, remove this action from the deployment.\n" +
           "          ! Not taking any action here.\n"
    else
      abort("       ! Action: #{service} #{action} failed!")
    end
  else
    puts "       |+ Action: #{service} #{action} succeeded."
  end
end

.new(deployment, options) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/danarchy_deploy/services/init.rb', line 7

def self.new(deployment, options)
  puts "\n" + self.name

  deployment[:services].each do |service, params|
    next if ! params[:init]
    orig_actions = params[:init]
    puts "\n > Init actions for #{service}: #{params[:init].join(', ')}"
    params[:init].each do |action|
      puts "    |+ Taking action: #{action} on #{service}"
      if options[:pretend]
        puts "       Fake run: #{action} #{service}"
      else
        init_manager(deployment[:os], service, action, options)
      end
    end

    params[:init] = orig_actions
  end

  deployment
end