Class: Yast::SystemdUnit::Properties

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

Overview

Structure holding properties of systemd unit

Instance Method Summary collapse

Constructor Details

#initialize(systemd_unit, property_text) ⇒ Properties

Returns a new instance of Properties

Parameters:

  • systemd_unit (SystemdUnit)
  • property_text (String, nil)

    if provided, use it instead of calling `systemctl show`



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'library/systemd/src/lib/yast2/systemd_unit.rb', line 192

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[:enabled?]   = read_enabled_state
  self[:supported?] = SUPPORTED_STATES.include?(unit_file_state)
end