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 = 'default', options) ⇒ Openrc

Returns a new instance of Openrc.



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

def initialize(service, runlevel='default', options)
  @service  = service
  @runlevel = runlevel
  @options  = options
  cleanup_runlevels
end

Instance Method Details

#disableObject



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

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

#enableObject



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

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

#reloadObject



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

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



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

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

#startObject



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

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



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

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



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

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