Class: DanarchyDeploy::Services::Init::Openrc

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

Instance Method Summary collapse

Constructor Details

#initialize(service, runlevel, options) ⇒ Openrc

Returns a new instance of Openrc.



6
7
8
9
10
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 6

def initialize(service, runlevel, options)
  @service  = service
  @runlevel = runlevel
  @options  = options
end

Instance Method Details

#disableObject



66
67
68
69
70
71
72
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 66

def disable
  Dir["/etc/runlevels/*/#{@service}"].each do |svc|
    runlevel, service = svc.split('/')[3,4]
    cmd = "rc-update del #{service} #{runlevel}"
    DanarchyDeploy::Helpers.run_command(cmd, @options)
  end
end

#enableObject



61
62
63
64
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 61

def enable
  cmd = "rc-update add #{@service} #{@runlevel}"
  DanarchyDeploy::Helpers.run_command(cmd, @options)
end

#reloadObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 40

def reload
  status = self.status

  cmd = if status[:stderr]
          # status[:stdout].include?('running')
          # This used to check for status "running"; and previously "started".
          # Too specific so I've disabled it since I don't remember what this exception was for, originally.
          puts "        |! Service: #{@service} is not running. Starting it up instead."
          "rc-service #{@service} start"
        else
          "rc-service #{@service} reload"
        end

  DanarchyDeploy::Helpers.run_command(cmd, @options)
end

#restartObject



56
57
58
59
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 56

def restart
  cmd = "rc-service #{@service} restart"
  DanarchyDeploy::Helpers.run_command(cmd, @options)
end

#startObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 18

def start
  cmd = "rc-service #{@service} start"
  status = self.status

  if status[:stdout].include?('started')
    return status
  else
    DanarchyDeploy::Helpers.run_command(cmd, @options)
  end
end

#statusObject



12
13
14
15
16
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 12

def status
  cmd = "rc-service #{@service} status"
  return { stdout: "Fake run: started", stderr: nil } if @options[:pretend]
  DanarchyDeploy::Helpers.run_command(cmd, @options)
end

#stopObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/danarchy_deploy/services/init/openrc.rb', line 29

def stop
  cmd = "rc-service #{@service} stop"
  status = self.status

  if status[:stdout].include?('stopped')
    return status
  else
    DanarchyDeploy::Helpers.run_command(cmd, @options)
  end
end