Class: Services
- Inherits:
-
Object
- Object
- Services
- Defined in:
- lib/sos/services.rb
Class Method Summary collapse
Instance Method Summary collapse
- #by_name ⇒ Object
- #enabled ⇒ Object
-
#initialize(service_list, services_logs) ⇒ Services
constructor
A new instance of Services.
Constructor Details
#initialize(service_list, services_logs) ⇒ Services
Returns a new instance of Services.
50 51 52 53 54 55 56 57 58 |
# File 'lib/sos/services.rb', line 50 def initialize(service_list, services_logs) @services = [] service_list.each_line { |line| name, state = line.chop.split(':') log = services_logs[name] ? services_logs[name] : '' @services << Service.new(name, state, log) } @services end |
Class Method Details
.build_list(selectors, run_level, filters) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sos/services.rb', line 21 def self.build_list(selectors, run_level, filters) # Returns each service on a line with # name:state selector = selectors.split(',').join('|') list='' redhat = %x{cat /etc/redhat-release} case redhat when /Red Hat Enterprise Linux/ if redhat =~ /release 6/ list = %x{ chkconfig --list | awk '/#{selector}/ {print $1":"$#{run_level+2}}'} list.gsub!(/:\d:/,':') end when /Fedora/ list = %x{ systemctl list-unit-files | awk '/#{selector}/ {print}'} list.gsub!(/\.service[\s]*/,':') end if filters != [] filtered = '' list.each_line { |line| filters.each { |filter| filtered << line if line =~ /#{filter}/ } } list = filtered end list end |
Instance Method Details
#by_name ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/sos/services.rb', line 60 def by_name list = [] @services.each { |service| list << service } list end |
#enabled ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/sos/services.rb', line 68 def enabled list = [] @services.each { |service| list << service if service.state } list end |