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, #matches?, #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
|
# 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 skip_enablement && %w[enable disable].include?(action)
return skip_enablement_message(action, @name)
end
cmd = "systemctl #{action} #{@name}"
cmd += ' --all' if all
cmd
end
|
#disable ⇒ Object
44
45
46
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 44
def disable
execute('disable')
end
|
#enable ⇒ Object
40
41
42
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 40
def enable
execute('enable')
end
|
#enabled? ⇒ Boolean
60
61
62
63
64
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 60
def enabled?
if @sys.systemd_installed?
service_enabled_status == 'enabled'
end
end
|
#exist? ⇒ Boolean
52
53
54
55
56
57
58
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 52
def exist?
if @sys.systemd_installed?
['enabled', 'disabled'].include?(service_enabled_status)
else
File.exist?("/etc/init.d/#{@name}")
end
end
|
#restart ⇒ Object
36
37
38
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 36
def restart
execute('restart')
end
|
#running? ⇒ Boolean
48
49
50
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 48
def running?
status.first == 0
end
|
#start ⇒ Object
28
29
30
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 28
def start
execute('start')
end
|
#status ⇒ Object
24
25
26
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 24
def status
execute('status')
end
|
#stop ⇒ Object
32
33
34
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 32
def stop
execute('stop')
end
|