Class: ForemanMaintain::Utils::Service::Systemd

Inherits:
Abstract
  • Object
show all
Defined in:
lib/foreman_maintain/utils/service/systemd.rb

Instance Attribute Summary collapse

Attributes inherited from Abstract

#name, #priority

Instance Method Summary collapse

Methods inherited from Abstract

#<=>, #inspect, #matches?, #socket, #to_s

Constructor Details

#initialize(name, priority, options = {}) ⇒ Systemd

Returns a new instance of Systemd.



5
6
7
8
9
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 5

def initialize(name, priority, options = {})
  super
  @sys = SystemHelpers.new
  @instance_parent_unit = options.fetch(:instance_parent_unit, nil)
end

Instance Attribute Details

#instance_parent_unitObject (readonly)

Returns the value of attribute instance_parent_unit.



4
5
6
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 4

def instance_parent_unit
  @instance_parent_unit
end

Instance Method Details

#command(action) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 11

def command(action)
  all = @options.fetch(:all, false)
  skip_enablement = @options.fetch(:skip_enablement, false)
  if skip_enablement && %w[enable disable].include?(action)
    return skip_enablement_message(action, @name)
  end

  cmd = "systemctl #{action} #{@name}"
  cmd += ' --all' if all
  cmd
end

#disableObject



39
40
41
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 39

def disable
  execute('disable')
end

#enableObject



35
36
37
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 35

def enable
  execute('enable')
end

#enabled?Boolean

Returns:

  • (Boolean)


56
57
58
59
60
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 56

def enabled?
  if @sys.systemd_installed?
    service_enabled_status == 'enabled'
  end
end

#exist?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
54
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 47

def exist?
  if @sys.systemd_installed?
    systemd = service_enabled_status
    systemd == 'enabled' || systemd == 'disabled'
  else
    File.exist?("/etc/init.d/#{@name}")
  end
end

#running?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 43

def running?
  status.first == 0
end

#startObject



27
28
29
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 27

def start
  execute('start')
end

#statusObject



23
24
25
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 23

def status
  execute('status')
end

#stopObject



31
32
33
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 31

def stop
  execute('stop')
end