Class: Services

Inherits:
Object
  • Object
show all
Defined in:
lib/sos/services.rb

Instance Method Summary collapse

Constructor Details

#initialize(selector, run_level, filters, loglist) ⇒ Services

Returns a new instance of Services.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sos/services.rb', line 20

def initialize(selector, run_level, filters, loglist)
  @services = []

  list = %x{chkconfig --list | awk '#{selector} {print $1":"$#{run_level+2}}'}

  if filters != []
    filtered = ''
    list.each { |line|
      filters.each { |filter| filtered << line if line =~ /#{filter}/ }
    }
    list = filtered
  end

  list.each  { |line|
    line_tab = line.chop.split(':')
    name = line_tab[0]
    state = line_tab[2]
    log = loglist[name] ? loglist[name] : ''
    @services << Service.new(name, state, log)
  }
end

Instance Method Details

#enabledObject



53
54
55
56
57
58
59
# File 'lib/sos/services.rb', line 53

def enabled
  list = []
  @services.each { |service|
    list << service if service.state
  }
  list
end

#get_by_name(filters) ⇒ Object



42
43
44
45
46
47
48
49
50
51
# File 'lib/sos/services.rb', line 42

def get_by_name(filters)
  return @services
  list = []
  filters.each { |filter|
    @services.each { |service|
      list << service if @service.has?(filter)
    }
  }
  list
end