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
82 83 84 85 86 87 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 82 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
64 65 66 67 68 69 70 71 72 73 74 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 64 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
77 78 79 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 77 def find!(target_name, propmap = {}) find(target_name, propmap) || raise(Systemd::TargetNotFound, target_name) end |
.get_default ⇒ Object
rubocop:disable Naming/AccessorMethodName
89 90 91 92 93 94 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 89 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
96 97 98 99 100 101 102 103 104 105 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 96 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
108 109 110 111 112 113 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 108 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
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'library/systemd/src/lib/yast2/systemd/target.rb', line 115 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 |