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
Attributes inherited from Abstract
#name, #priority
Instance Method Summary
collapse
Methods inherited from Abstract
#<=>, #inspect, #matches?, #to_s
Constructor Details
#initialize(name, priority, _options = {}) ⇒ Systemd
Returns a new instance of Systemd.
4
5
6
7
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 4
def initialize(name, priority, _options = {})
super
@sys = SystemHelpers.new
end
|
Instance Method Details
#command(action, options = {}) ⇒ Object
9
10
11
12
13
14
15
16
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 9
def command(action, options = {})
do_wait = options.fetch(:wait, true) if do_wait && File.exist?('/usr/sbin/service-wait')
"service-wait #{@name} #{action}"
else
"systemctl #{action} #{@name}"
end
end
|
#disable ⇒ Object
34
35
36
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 34
def disable
execute('disable', :wait => false)
end
|
#enable ⇒ Object
30
31
32
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 30
def enable
execute('enable', :wait => false)
end
|
#exist? ⇒ Boolean
42
43
44
45
46
47
48
49
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 42
def exist?
if @sys.systemd_installed?
systemd = @sys.execute("systemctl is-enabled #{@name} 2>&1 | tail -1").strip
systemd == 'enabled' || systemd == 'disabled'
else
File.exist?("/etc/init.d/#{service}")
end
end
|
#running? ⇒ Boolean
38
39
40
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 38
def running?
status.first == 0
end
|
#start ⇒ Object
22
23
24
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 22
def start
execute('start')
end
|
#status ⇒ Object
18
19
20
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 18
def status
execute('status')
end
|
#stop ⇒ Object
26
27
28
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 26
def stop
execute('stop')
end
|