Class: Yast2::CompoundService
- Inherits:
-
Object
- Object
- Yast2::CompoundService
- Includes:
- Yast::Logger
- Defined in:
- library/systemd/src/lib/yast2/compound_service.rb
Overview
Class that represents several related services that need to be synchronized. It mimics behavior of single SystemService, but it adds possible states.
Constant Summary collapse
- AUTOSTART_OPTIONS =
[:on_boot, :on_demand, :manual, :inconsistent].freeze
Instance Attribute Summary collapse
-
#services ⇒ Array<Yast2::SystemService>
readonly
Managed services.
Instance Method Summary collapse
-
#action ⇒ :start, ...
Action to perform over all services.
-
#current_start_mode ⇒ :on_boot, ...
Current start mode in the system.
-
#currently_active? ⇒ true, ...
Whether the services are currently active.
-
#errors ⇒ Hash<Symbol, Object>
Errors when trying to write changes to the underlying system.
-
#initialize(*services) ⇒ CompoundService
constructor
Creates a new service composed by several services.
-
#keywords ⇒ Array<String>
Keywords that can be used to search for involved underlying units.
-
#reload ⇒ Object
Sets all services to be reloaded after calling #save.
-
#reset(exclude: []) ⇒ Object
Resets changes.
-
#restart ⇒ Object
Sets all services to be restarted after calling #save.
-
#save(keep_state: false) ⇒ Boolean
Saves all services.
-
#start ⇒ Object
Sets all services to be started after calling #save.
-
#start_mode ⇒ :on_boot, ...
Target start mode.
-
#start_mode=(configuration) ⇒ Object
Sets the target start mode.
-
#start_modes ⇒ Array<Symbol>
Possible start modes taking into account all services.
-
#stop ⇒ Object
Sets all services to be stopped after calling #save.
-
#support_reload? ⇒ Boolean
Whether any service supports reload.
-
#support_start_on_boot? ⇒ Boolean
Whether the service supports :on_boot start mode.
-
#support_start_on_demand? ⇒ Boolean
Whether any service allows to start on demand.
Constructor Details
#initialize(*services) ⇒ CompoundService
Creates a new service composed by several services
42 43 44 45 46 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 42 def initialize(*services) raise ArgumentError, "Services can be only System Service - #{services.inspect}" if services.any? { |s| !s.is_a?(Yast2::SystemService) } @services = services end |
Instance Attribute Details
#services ⇒ Array<Yast2::SystemService> (readonly)
Managed services
32 33 34 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 32 def services @services end |
Instance Method Details
#action ⇒ :start, ...
Action to perform over all services
125 126 127 128 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 125 def action # TODO: check for inconsistencies? services.first.action end |
#current_start_mode ⇒ :on_boot, ...
It offers an additional state :inconsistent
that is not in SystemService
Current start mode in the system
146 147 148 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 146 def current_start_mode @current_start_mode ||= services_mode(method(:current_mode?)) end |
#currently_active? ⇒ true, ...
It offers an additional value :inconsistent
that is not in SystemService
Whether the services are currently active
70 71 72 73 74 75 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 70 def currently_active? return true if services.all?(&:currently_active?) return false if services.none?(&:currently_active?) :inconsistent end |
#errors ⇒ Hash<Symbol, Object>
Errors when trying to write changes to the underlying system
214 215 216 217 218 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 214 def errors services.each_with_object({}) do |s, result| result.merge!(s.errors) end end |
#keywords ⇒ Array<String>
Keywords that can be used to search for involved underlying units
104 105 106 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 104 def keywords services.map(&:keywords).reduce(:+).uniq end |
#reload ⇒ Object
Sets all services to be reloaded after calling #save
259 260 261 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 259 def reload services.each(&:reload) end |
#reset(exclude: []) ⇒ Object
Resets changes
226 227 228 229 230 231 232 233 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 226 def reset(exclude: []) old_action = action old_start_mode = start_mode services.each(&:reset) @current_start_mode = nil public_send(old_action) if !old_action.nil? && exclude.include?(:action) self.start_mode = old_start_mode if old_start_mode != :inconsistent && exclude.include?(:start_mode) end |
#restart ⇒ Object
Sets all services to be restarted after calling #save
252 253 254 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 252 def restart services.each(&:restart) end |
#save(keep_state: false) ⇒ Boolean
Saves all services
53 54 55 56 57 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 53 def save(keep_state: false) services.each { |s| s.save(keep_state: keep_state) } errors.empty? end |
#start ⇒ Object
Sets all services to be started after calling #save
238 239 240 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 238 def start services.each(&:start) end |
#start_mode ⇒ :on_boot, ...
It offers and additional start mode :inconsistent
that is not in SystemService
Target start mode
166 167 168 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 166 def start_mode services_mode(method(:mode?)) end |
#start_mode=(configuration) ⇒ Object
It offers and additional start mode :inconsistent
that is not in SystemService
Sets the target start mode
177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 177 def start_mode=(configuration) raise ArgumentError, "Invalid parameter #{configuration.inspect}" if !AUTOSTART_OPTIONS.include?(configuration) case configuration when :inconsistent reset(exclude: [:action]) when :on_demand services_with_socket.each { |s| s.start_mode = :on_demand } services_without_socket.each { |s| s.start_mode = :on_boot } else services.each { |s| s.start_mode = configuration } end end |
#start_modes ⇒ Array<Symbol>
Possible start modes taking into account all services
If a service supports :on_boot and :manual start modes, but another service supports :on_demand too, the possible start modes will the all of them: :on_boot, on_demand and :manual.
95 96 97 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 95 def start_modes @start_modes ||= services.map(&:start_modes).reduce(:+).uniq end |
#stop ⇒ Object
Sets all services to be stopped after calling #save
245 246 247 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 245 def stop services.each(&:stop) end |
#support_reload? ⇒ Boolean
Whether any service supports reload
82 83 84 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 82 def support_reload? services.any?(&:support_reload?) end |
#support_start_on_boot? ⇒ Boolean
Whether the service supports :on_boot start mode
205 206 207 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 205 def support_start_on_boot? services.any?(&:support_start_on_boot?) end |
#support_start_on_demand? ⇒ Boolean
Whether any service allows to start on demand
196 197 198 |
# File 'library/systemd/src/lib/yast2/compound_service.rb', line 196 def support_start_on_demand? services.any?(&:support_start_on_demand?) end |