Class: Yast2::Systemd::Service
- Includes:
- Yast::Logger
- Defined in:
- library/systemd/src/lib/yast2/systemd/service.rb
Overview
API to manage a systemd.service unit
Constant Summary collapse
- UNIT_SUFFIX =
".service".freeze
- START_SERVICE_INSTSYS_COMMAND =
Available only on installation system
"/bin/service_start".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 = UnitPropMap.new) ⇒ Array<Service>
-
.build(service_name, propmap = UnitPropMap.new) ⇒ Service
Instantiate a Systemd::Service object based on the given name.
-
.find(service_name, propmap = UnitPropMap.new) ⇒ Service?
nil
if not found. - .find!(service_name, propmap = UnitPropMap.new) ⇒ Service
-
.find_many(service_names, propmap = UnitPropMap.new) ⇒ Array<Service,nil>
nil
if not found.
Instance Method Summary collapse
- #pid ⇒ String
- #restart ⇒ Object
- #running? ⇒ Boolean
-
#socket ⇒ Yast2::Systemd::Socket?
Returns socket associated with service or nil if there is no such socket.
-
#socket? ⇒ Boolean
Determines whether the service has an associated socket.
- #start ⇒ Object
- #static? ⇒ Boolean
- #stop ⇒ Object
Methods inherited from Unit
#command, #disable, #enable, #initialize, #refresh!, #reload, #reload_or_restart, #reload_or_try_restart, #show, #status, #try_restart
Constructor Details
This class inherits a constructor from Yast2::Systemd::Unit
Class Method Details
.all(propmap = UnitPropMap.new) ⇒ Array<Service>
137 138 139 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 137 def all(propmap = UnitPropMap.new) Systemctl.service_units.map { |s| new(s, propmap) } end |
.build(service_name, propmap = UnitPropMap.new) ⇒ Service
Instantiate a Systemd::Service object based on the given name
Use with caution as the service might exist or not. If you need to react when the service does not exist, use Systemd::Service.find.
149 150 151 152 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 149 def build(service_name, propmap = UnitPropMap.new) service_name += UNIT_SUFFIX unless service_name.end_with?(UNIT_SUFFIX) new(service_name, propmap) end |
.find(service_name, propmap = UnitPropMap.new) ⇒ Service?
Returns nil
if not found.
85 86 87 88 89 90 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 85 def find(service_name, propmap = UnitPropMap.new) service = build(service_name, propmap) return nil if service.properties.not_found? service end |
.find!(service_name, propmap = UnitPropMap.new) ⇒ Service
96 97 98 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 96 def find!(service_name, propmap = UnitPropMap.new) find(service_name, propmap) || raise(Systemd::ServiceNotFound, service_name) end |
.find_many(service_names, propmap = UnitPropMap.new) ⇒ Array<Service,nil>
Returns nil
if not found.
127 128 129 130 131 132 133 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 127 def find_many(service_names, propmap = UnitPropMap.new) services = find_many_at_once(service_names, propmap) return services unless services.empty? log.info "Retrying one by one" service_names.map { |n| find(n, propmap) } end |
Instance Method Details
#pid ⇒ String
161 162 163 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 161 def pid properties.pid end |
#restart ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 183 def restart # Delegate to Systemd::Unit#restart if not within installation return super unless installation_system? stop sleep(1) start end |
#running? ⇒ Boolean
165 166 167 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 165 def running? properties.running? end |
#socket ⇒ Yast2::Systemd::Socket?
Returns socket associated with service or nil if there is no such socket
196 197 198 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 196 def socket @socket ||= Socket.for_service(name) end |
#socket? ⇒ Boolean
Determines whether the service has an associated socket
203 204 205 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 203 def socket? !socket.nil? end |
#start ⇒ Object
173 174 175 176 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 173 def start command = "#{START_SERVICE_INSTSYS_COMMAND} #{unit_name.shellescape}" installation_system? ? run_instsys_command(command) : super end |
#static? ⇒ Boolean
169 170 171 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 169 def static? properties.static? end |
#stop ⇒ Object
178 179 180 181 |
# File 'library/systemd/src/lib/yast2/systemd/service.rb', line 178 def stop command = "#{START_SERVICE_INSTSYS_COMMAND} --stop #{unit_name.shellescape}" installation_system? ? run_instsys_command(command) : super end |