class SystemService

Attributes

active[RW]
descr[RW]
filename_full[RW]
load[RW]
overrides_legacy[RW]
state[RW]
sub[RW]

Public Class Methods

new(str) click to toggle source

default constructor, takes unit name

Calls superclass method
# File lib/yasysdui/system_service.rb, line 117
def initialize(str)
   super(str)
   @overrides_legacy = false
end

Public Instance Methods

each_sentence() { |to_str| ... } click to toggle source

This provides the texts to index (module Indexable)

# File lib/yasysdui/system_service.rb, line 27
def each_sentence
        yield self.to_str
        yield @descr unless  @descr.nil?
end
handle_masked_info() click to toggle source
# File lib/yasysdui/system_service.rb, line 70
def handle_masked_info
     if self.state == 'masked'
         @load = 'masked'
         @active = 'inactive'
         @sub = 'dead'
         true
     else
                     false
     end   
end
native?() click to toggle source
# File lib/yasysdui/system_service.rb, line 131
def native?
   true
end
native_info() click to toggle source
# File lib/yasysdui/system_service.rb, line 121
   def native_info
# yes+   : native and overrides init script
# yes    : native and no init script
# no     : init script
     if    self.native?
        @overrides_legacy ? "yes+" : "yes"
     else
                "no"
     end
   end
parse_status_info() click to toggle source
# File lib/yasysdui/system_service.rb, line 31
   def parse_status_info
        match = nil
                return if self.handle_masked_info
        info_tab = @status_info_raw.lines.reject{|l| @@warning_rgx.match(l) }
        info_tab.map!{|r| r.strip}
        if @@status_read_failed_rgx.match(info_tab[0])
            return nil
        end    
       if @@status_unit_notfound_rgx.match(info_tab[0])
            return nil
        end                
        if match = @@descr_rgx.match(info_tab[0])
            self.descr = match[1]
        else
# masked script/service without description returned
            if match = @@descr_masked_rgx.match(info_tab[0])
            else
                puts info_tab[0]
                raise "Failed parsing line printed above"
            end

        end 
# complete data
        if match
            match = @@loaded_rgx.match(info_tab[1])
            if match 
                self.load = match[1]  
                load_info = match[2].split(';')
                self.filename_full = load_info[0]
                self.state = load_info[1]
            end    
            match = @@active_rgx.match(info_tab[2].strip)
            if match
                self.active = match[1]   
                self.sub = match[2]
            end
        end

   end
read_state() click to toggle source
# File lib/yasysdui/system_service.rb, line 92
def read_state
     return nil if self.end_with?("@")
     match = nil
             stdout_str, status = Open3.capture2("#@@cmd_info #{self.to_s}" )
             if stdout_str.lines.size > 0

         info_tab = stdout_str.lines.reject{|l| @@warning_rgx.match(l) }
         if @@status_read_failed_rgx.match(info_tab[0].strip)
             return nil
         end            
         match = @@loaded_rgx.match(info_tab[1].strip)
         if match 
             load_info = match[2].split(';')
             self.filename_full = load_info[0]
             self.state = load_info[1]
         end    
             

     else
          puts "Failed getting service state info for"
          pp self
           
     end
end
read_status_info() click to toggle source
# File lib/yasysdui/system_service.rb, line 80
   def read_status_info
        return nil if self.end_with?("@")
        return if self.handle_masked_info
                @status_info_raw, status = Open3.capture2("#@@cmd_info #{self.to_s}" )
                if @status_info_raw.lines.size > 0
            self.parse_status_info
        else
# TODO: a more decent error handling...
             puts "Failed getting service status info for"
             pp self
        end
   end
set_status_info_from_output( action_output ) click to toggle source
# File lib/yasysdui/system_service.rb, line 22
def set_status_info_from_output( action_output )
     @status_info_raw = action_output
     self.parse_status_info
end