class ServiceCatalog

Attributes

idx[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/yasysdui/service_catalog.rb, line 8
def initialize
    super
    @idx = SimpleIndex.new
    @config = YSConfig.instance
    @config.load 
    self.get_requested_services
    self.build_index
end

Public Instance Methods

add_init_d_scripts() click to toggle source

get all legacy init.d scripts

# File lib/yasysdui/service_catalog.rb, line 95
    def add_init_d_scripts
        flist = Dir.glob("#@@initd/*").reject{|f| @@initd_ignore.match(f) }.map{|f| File.basename(f)}
        flist.each{|f| 
# only try to add an init script if it does not exist as an native systemd unit,
# as these have precedence
# these assumes we have to read native service before
            if self.has_key?(f)
                srv = self[f]
                srv.overrides_legacy = true
                srv.read_state
            else
                srv = SystemServiceLegacy.new( f )
                self[srv] = srv if srv
            end
        }
    end
add_units_from_file_list() click to toggle source

add all know systemd units files from systemctl list-unit-files

# File lib/yasysdui/service_catalog.rb, line 67
def add_units_from_file_list
        
    match = nil; srv = nil
            stdout_str, status = Open3.capture2( @@cmd_list_unit_files )
            if status.success?
                    stdout_str.each_line{|l|
                            match = @@rgx_li.match(l.strip)
                            if match
                f = match[1]
                unless f.end_with?('@')    # ignore template units for now...
                                            unless self.has_key?(f)
                                                    srv = SystemService.new( f )
                                                    srv.state = match[2]
                                                    srv.read_status_info 
                                                    self[srv] = srv if srv
                                            else
                                                    self[f].state = match[2]
                                            end
                end
            else
                                    puts l
                                    raise "Failed parsing line printed above"
                            end
                    }
                    
            end
end
build_index() click to toggle source
# File lib/yasysdui/service_catalog.rb, line 21
def build_index
            print "Building fast search index... "
            self.each_value{|srv|
                    @idx.compile(srv)
            }
            print "done\n"
            
end
get_all_known_units() click to toggle source

get all know systemd native units from systemctl list-units

# File lib/yasysdui/service_catalog.rb, line 44
def get_all_known_units
        
    match = nil; srv = nil
            stdout_str, status = Open3.capture2( @@cmd_know_units )
            if status.success?
                    stdout_str.each_line{|l|
                            match = @@rgx_ku.match(l.strip)
                            if match
                srv = SystemService.new(match[1] )
                srv.load = match[2]
                srv.active = match[3]
                srv.sub = match[4]
                srv.descr = match[5]
                                    self[srv] = srv
                            else
                                    puts l
                                    raise "Failed parsing line printed above"
                            end
                    }
                    
            end
end
get_managed_services() click to toggle source

get all maanged services as sepcified in config file

# File lib/yasysdui/service_catalog.rb, line 112
    def get_managed_services
        @config.managed_services.each{|f| 
# only try to add an init script if it does not exist already in the catlog
            unless self.has_key?(f)
                srv = SystemService.new( f )
                srv.read_status_info 
                srv.read_state
                        self[srv] = srv if srv
            end
        }
    end
get_requested_services() click to toggle source

get either

all available units/scripts    OR
 the  anaged services only (as specified in the config file)
# File lib/yasysdui/service_catalog.rb, line 126
def get_requested_services
            if @config.managed_services
                    pp :getting_managed_services
                    get_managed_services
            else
                    pp :getting_all_services
                    get_all_known_units; pp :got_all_known_units
                    add_units_from_file_list; pp :got_all_units_from_file
                    add_init_d_scripts; pp :got_all_init_scripts
                    puts "Built service catalog with #{self.size} item(s)" 
            end
            self
    end
rebuild() click to toggle source
# File lib/yasysdui/service_catalog.rb, line 16
def rebuild
  clear
  self.get_requested_services
  self.build_index
end