Class: Yast2::Systemd::UnitProperties

Inherits:
OpenStruct
  • Object
show all
Includes:
Yast::Logger
Defined in:
library/systemd/src/lib/yast2/systemd/unit_properties.rb

Overview

Structure holding properties of systemd unit

Constant Summary collapse

SUPPORTED_STATES =
%w[enabled disabled].freeze
ACTIVE_STATES =

Values of #active_state fow which we consider a unit "active".

systemctl.c:check_unit_active uses (active, reloading) For bsc#884756 we also consider "activating" to be active. (The remaining states are "deactivating", "inactive", "failed".)

Yes, depending on systemd states that are NOT covered by their interface stability promise is fragile. But: 10 to 50ms per call of systemctl is-active, times 100 to 300 services (depending on hardware and software installed, VM or not) is a 1 to 15 second delay (bsc#1045658). That is why we try hard to avoid many systemctl calls.

["active", "activating", "reloading"].freeze

Instance Method Summary collapse

Constructor Details

#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


27
28
29
30
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
# File 'library/systemd/src/lib/yast2/systemd/unit_properties.rb', line 27

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