class ForemanMaintain::Utils::Service::Systemd
Attributes
instance_parent_unit[R]
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 6 def initialize(name, priority, options = {}) super @sys = SystemHelpers.new @instance_parent_unit = options.fetch(:instance_parent_unit, nil) end
Public Instance Methods
command(action)
click to toggle source
# 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 %w[enable disable].include?(action) return skip_enablement_message(action, @name) if skip_enablement return if generated? end cmd = "systemctl #{action} #{@name}" cmd += ' --all' if all cmd end
disable()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 45 def disable execute('disable') end
enable()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 41 def enable execute('enable') end
enabled?()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 57 def enabled? if @sys.systemd_installed? ['enabled', 'generated'].include?(service_enabled_status) end end
exist?()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 53 def exist? ['enabled', 'disabled', 'generated'].include?(service_enabled_status) end
generated?()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 63 def generated? service_enabled_status == 'generated' end
matches?(service)
click to toggle source
Calls superclass method
ForemanMaintain::Utils::Service::Abstract#matches?
# File lib/foreman_maintain/utils/service/systemd.rb, line 67 def matches?(service) if service.is_a? String service == @name || File.fnmatch(service, @name) else super end end
restart()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 37 def restart execute('restart') end
running?()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 49 def running? status.first == 0 end
start()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 29 def start execute('start') end
status()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 25 def status execute('status') end
stop()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 33 def stop execute('stop') end
Private Instance Methods
execute(action)
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 77 def execute(action) @sys.execute_with_status(command(action)) end
service_enabled_status()
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 81 def service_enabled_status @sys.execute("systemctl is-enabled #{@name} 2>&1 | tail -1").strip end
skip_enablement_message(action, name)
click to toggle source
# File lib/foreman_maintain/utils/service/systemd.rb, line 85 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 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 " puts msg end