Method: Yast2::Systemd::UnitProperties#initialize

Defined in:
library/systemd/src/lib/yast2/systemd/unit_properties.rb

#initialize(systemd_unit, property_text) ⇒ UnitProperties

Returns a new instance of UnitProperties.

Parameters:

  • systemd_unit (Yast2::Systemd::Unit)
  • property_text (String, nil)

    if provided, use it instead of calling systemctl show



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'library/systemd/src/lib/yast2/systemd/unit_properties.rb', line 31

def initialize(systemd_unit, property_text)
  super()
  self[:systemd_unit] = systemd_unit
  if property_text.nil?
    raw_output   = load_systemd_properties
    self[:raw]   = raw_output.stdout
    self[:error] = raw_output.stderr
    self[:exit]  = raw_output.exit
  else
    self[:raw]   = property_text
    self[:error] = ""
    self[:exit]  = 0
  end

  if !exit.zero? || !error.empty?
    message = "Failed to get properties for unit '#{systemd_unit.unit_name}' ; "
    message << "Command `#{raw_output.command}` returned error: #{error}"
    log.error(message)
    self[:not_found?] = true
    return
  end

  extract_properties
  self[:active?]         = ACTIVE_STATES.include?(active_state)
  self[:running?]        = sub_state  == "running"
  self[:loaded?]         = load_state == "loaded"
  self[:not_found?]      = load_state == "not-found"
  self[:static?]         = unit_file_state == "static"
  self[:preset_enabled?] = read_preset_enabled_state
  self[:enabled?]        = read_enabled_state
  self[:supported?]      = SUPPORTED_STATES.include?(unit_file_state)
  self[:can_reload?]     = can_reload == "yes"
end