# File lib/foreman_maintain/utils/service/systemd.rb, line 5 def initialize(name, priority, options = {}) super @sys = SystemHelpers.new @instance_parent_unit = options.fetch(:instance_parent_unit, nil) end
# File lib/foreman_maintain/utils/service/systemd.rb, line 11 def command(action) 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 cmd = "systemctl #{action} #{@name}" cmd += ' --all' if all cmd end
# File lib/foreman_maintain/utils/service/systemd.rb, line 39 def disable execute('disable') end
# File lib/foreman_maintain/utils/service/systemd.rb, line 35 def enable execute('enable') end
# File lib/foreman_maintain/utils/service/systemd.rb, line 56 def enabled? if @sys.systemd_installed? service_enabled_status == 'enabled' end end
# File lib/foreman_maintain/utils/service/systemd.rb, line 47 def exist? if @sys.systemd_installed? systemd = service_enabled_status systemd == 'enabled' || systemd == 'disabled' else File.exist?("/etc/init.d/#{@name}") end end
# File lib/foreman_maintain/utils/service/systemd.rb, line 43 def running? status.first == 0 end
# File lib/foreman_maintain/utils/service/systemd.rb, line 27 def start execute('start') end
# File lib/foreman_maintain/utils/service/systemd.rb, line 23 def status execute('status') end
# File lib/foreman_maintain/utils/service/systemd.rb, line 31 def stop execute('stop') end
# File lib/foreman_maintain/utils/service/systemd.rb, line 64 def execute(action) @sys.execute_with_status(command(action)) end
# File lib/foreman_maintain/utils/service/systemd.rb, line 68 def service_enabled_status @sys.execute("systemctl is-enabled #{@name} 2>&1 | tail -1").strip end
# File lib/foreman_maintain/utils/service/systemd.rb, line 72 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