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
17
18
19
20
21
22
23
24
25
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 9
def command(action, options = {})
do_wait = options.fetch(:wait, true)
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
if do_wait && File.exist?('/usr/sbin/service-wait')
"service-wait #{@name} #{action}"
else
cmd = "systemctl #{action} #{@name}"
cmd += ' --all' if all
cmd
end
end
|
#disable ⇒ Object
43
44
45
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 43
def disable
execute('disable', :wait => false)
end
|
#enable ⇒ Object
39
40
41
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 39
def enable
execute('enable', :wait => false)
end
|
#exist? ⇒ Boolean
51
52
53
54
55
56
57
58
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 51
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/#{@name}")
end
end
|
#running? ⇒ Boolean
47
48
49
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 47
def running?
status.first == 0
end
|
#start ⇒ Object
31
32
33
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 31
def start
execute('start')
end
|
#status ⇒ Object
27
28
29
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 27
def status
execute('status')
end
|
#stop ⇒ Object
35
36
37
|
# File 'lib/foreman_maintain/utils/service/systemd.rb', line 35
def stop
execute('stop')
end
|