Class: Yast2::Systemd::Target
- Includes:
- Yast::Logger
- Defined in:
- library/systemd/src/lib/yast2/systemd/target.rb
Overview
API to manage a systemd.target unit
Constant Summary collapse
- UNIT_SUFFIX =
".target".freeze
- DEFAULT_TARGET =
"default.target".freeze
- PROPMAP =
{ allow_isolate: "AllowIsolate" }.freeze
Constants inherited from Unit
Instance Attribute Summary
Attributes inherited from Unit
#error, #name, #properties, #propmap, #unit_name, #unit_type
Class Method Summary collapse
- .all(propmap = {}) ⇒ Object
- .find(target_name, propmap = {}) ⇒ Object
- .find!(target_name, propmap = {}) ⇒ Object
-
.get_default ⇒ Object
rubocop:disable Naming/AccessorMethodName.
-
.set_default(target) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
Instance Method Summary collapse
Methods inherited from Unit
#command, #disable, #enable, #initialize, #refresh!, #reload, #reload_or_restart, #reload_or_try_restart, #restart, #show, #start, #status, #stop, #try_restart
Constructor Details
This class inherits a constructor from Yast2::Systemd::Unit
Class Method Details
.all(propmap = {}) ⇒ Object
74 75 76 77 78 79 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 74 def all(propmap = {}) targets = Systemctl.target_units.map do |target_unit_name| find(target_unit_name, propmap) end targets.compact end |
.find(target_name, propmap = {}) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 56 def find(target_name, propmap = {}) target_name += UNIT_SUFFIX unless target_name.end_with?(UNIT_SUFFIX) target = new(target_name, PROPMAP.merge(propmap)) if target.properties.not_found? log.error "Target #{target_name} not found: #{target.properties.inspect}" return nil end target end |
.find!(target_name, propmap = {}) ⇒ Object
69 70 71 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 69 def find!(target_name, propmap = {}) find(target_name, propmap) || raise(Systemd::TargetNotFound, target_name) end |
.get_default ⇒ Object
rubocop:disable Naming/AccessorMethodName
81 82 83 84 85 86 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 81 def get_default # rubocop:disable Naming/AccessorMethodName result = Systemctl.execute("get-default") raise(SystemctlError, result) unless result.exit.zero? find(result.stdout.strip) end |
.set_default(target) ⇒ Object
rubocop:disable Naming/AccessorMethodName
88 89 90 91 92 93 94 95 96 97 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 88 def set_default(target) # rubocop:disable Naming/AccessorMethodName target_unit = target.is_a?(Systemd::Target) ? target : find(target) unless target_unit log.error "Cannot find target #{target.inspect}" return false end target_unit.set_default end |
Instance Method Details
#allow_isolate? ⇒ Boolean
100 101 102 103 104 105 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 100 def allow_isolate? # We cannot find out a target properties from /mnt in inst-sys # systemctl doesn't return any properties in chroot # See bnc#889323 ["yes", nil].include?(properties.allow_isolate) end |
#set_default ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 107 def set_default unless allow_isolate? log.error "Cannot set #{id.inspect} as default target: Cannot be isolated (#{properties.allow_isolate})" return false end # Constructing a fallback target ID if we can't get it from systemctl target_name = id || "#{name}.target" result = Systemctl.execute("set-default --force #{target_name}") result.exit.zero? end |