class ForemanMaintain::Utils::Service::Systemd

Public Class Methods

new(name, priority, _options = {}) click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 4
def initialize(name, priority, _options = {})
  super
  @sys = SystemHelpers.new
end

Public Instance Methods

command(action, options = {}) click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 9
def command(action, options = {})
  do_wait = options.fetch(:wait, true) # wait for service to start
  if do_wait && File.exist?('/usr/sbin/service-wait')
    "service-wait #{@name} #{action}"
  else
    "systemctl #{action} #{@name}"
  end
end
disable() click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 34
def disable
  execute('disable', :wait => false)
end
enable() click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 30
def enable
  execute('enable', :wait => false)
end
exist?() click to toggle source
# 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/#{@name}")
  end
end
running?() click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 38
def running?
  status.first == 0
end
start() click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 22
def start
  execute('start')
end
status() click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 18
def status
  execute('status')
end
stop() click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 26
def stop
  execute('stop')
end

Private Instance Methods

execute(action, options = {}) click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 53
def execute(action, options = {})
  @sys.execute_with_status(command(action, options))
end