Class: ForemanMaintain::Utils::Service::Systemd
- Inherits:
-
Abstract
- Object
- Abstract
- ForemanMaintain::Utils::Service::Systemd
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, #socket, #to_s
Constructor Details
#initialize(name, priority, options = {}) ⇒ Systemd
Returns a new instance of Systemd.
6
7
8
9
10
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 6
def initialize(name, priority, options = {})
super
@sys = SystemHelpers.new
@instance_parent_unit = options.fetch(:instance_parent_unit, nil)
end
|
Instance Attribute Details
#instance_parent_unit ⇒ Object
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
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 12
def command(action)
all = @options.fetch(:all, false)
skip_enablement = @options.fetch(:skip_enablement, false)
if %w[enable disable].include?(action)
return skip_enablement_message(action, @name) if skip_enablement
return if generated?
end
cmd = "systemctl #{action} #{@name}"
cmd += ' --all' if all
cmd
end
|
#disable ⇒ Object
45
46
47
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 45
def disable
execute('disable')
end
|
#enable ⇒ Object
41
42
43
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 41
def enable
execute('enable')
end
|
#enabled? ⇒ Boolean
57
58
59
60
61
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 57
def enabled?
if @sys.systemd_installed?
['enabled', 'generated'].include?(service_enabled_status)
end
end
|
#exist? ⇒ Boolean
53
54
55
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 53
def exist?
['enabled', 'disabled', 'generated'].include?(service_enabled_status)
end
|
#generated? ⇒ Boolean
63
64
65
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 63
def generated?
service_enabled_status == 'generated'
end
|
#matches?(service) ⇒ Boolean
67
68
69
70
71
72
73
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 67
def matches?(service)
if service.is_a? String
service == @name || File.fnmatch(service, @name)
else
super
end
end
|
#restart ⇒ Object
37
38
39
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 37
def restart
execute('restart')
end
|
#running? ⇒ Boolean
49
50
51
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 49
def running?
status.first == 0
end
|
#start ⇒ Object
29
30
31
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 29
def start
execute('start')
end
|
#status ⇒ Object
25
26
27
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 25
def status
execute('status')
end
|
#stop ⇒ Object
33
34
35
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 33
def stop
execute('stop')
end
|