class ForemanMaintain::Utils::Service::Systemd
Public Class Methods
new(name, priority, options = {})
click to toggle source
Calls superclass method
ForemanMaintain::Utils::Service::Abstract.new
# 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 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()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 43 def disable execute('disable', :wait => false) end
enable()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 39 def enable execute('enable', :wait => false) end
exist?()
click to toggle source
# 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?()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 47 def running? status.first == 0 end
start()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 31 def start execute('start') end
status()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 27 def status execute('status') end
stop()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 35 def stop execute('stop') end
Private Instance Methods
execute(action, options = {})
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 62 def execute(action, options = {}) @sys.execute_with_status(command(action, options)) end
skip_enablement_message(action, name)
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 66 def skip_enablement_message(action, name) # Enable and disable does not work well with globs since they treat them literally. # We are skipping the pulpcore-workers@* for these actions until they are configured in # a more managable way with systemd # rubocop:disable Layout/IndentAssignment msg = " \nWARNING: Skipping #{action} for #{name} as there are a variable amount of services to manage and this command will not respond to glob operators. These services have been configured by the installer and it is recommended to keep them enabled to prevent misconfiguration.\n " # rubocop:enable Layout/IndentAssignment puts msg end