Class: Yast::ServiceClass
- Inherits:
-
Module
- Object
- Module
- Yast::ServiceClass
- Includes:
- Logger
- Defined in:
- ../../src/modules/Service.rb
Instance Attribute Summary (collapse)
-
- (Object) error
readonly
Returns the value of attribute error.
Instance Method Summary (collapse)
-
- (Object) Active(service_name)
(also: #active?)
Check if service is active/running.
-
- (Boolean) Adjust(name, action)
deprecated
Deprecated.
Use the specific methods:
Enable
orDisable
-
- (Boolean) call(command_name, service_name)
Send whatever systemd command you need to call for a specific service If the command fails, log entry with output from systemctl is created in y2log.
-
- (Object) checkExists(name)
deprecated
Deprecated.
Use SystemdService.find
-
- (Object) Disable(service_name)
(also: #disable)
Disable service Logs error with output from systemctl if the command fails.
-
- (Object) Enable(service_name)
(also: #enable)
Enable service Logs error with output from systemctl if the command fails.
-
- (Object) Enabled(name)
(also: #enabled?)
Check if service is enabled (in any runlevel).
-
- (Array<String>) EnabledServices(_runlevel)
deprecated
Deprecated.
Runlevel features are not supported by systemd
-
- (Object) Error
Error Message.
-
- (String) Find(services)
deprecated
Deprecated.
Use SystemdService.find instead
-
- (Object) Finetune(name, rl)
deprecated
Deprecated.
Use
Enable
orDisable
instead -
- (Object) FullInfo(name)
deprecated
Deprecated.
Not supported by systemd
-
- (resolved) GetServiceId(name)
deprecated
Deprecated.
Use SystemdService.find('service_name').name
-
- (resolved) GetUnitId(unit)
deprecated
Deprecated.
Use SystemdService.find('service_name').id
-
- (Object) Info(name)
deprecated
Deprecated.
Not supported by systemd
-
- (ServiceClass) initialize
constructor
A new instance of ServiceClass.
-
- (Object) Reload(service_name)
(also: #reload)
Reload service Logs error with output from systemctl if the command fails.
-
- (Object) Restart(service_name)
(also: #restart)
Restart service Logs error with output from systemctl if the command fails.
-
- (Fixnum) RunInitScript(name, param)
deprecated
Deprecated.
Use specific method for service configuration
-
- (Object) RunInitScriptOutput(name, param)
deprecated
Deprecated.
Use a specific method instread
-
- (Fixnum) RunInitScriptWithTimeOut(name, param)
deprecated
Deprecated.
Use specific unit methods for service configuration
-
- (Object) serviceDisable(name, _force)
deprecated
Deprecated.
Use
Disable
instead -
- (Object) Start(service_name)
(also: #start)
Start service Logs error with output from systemctl if the command fails.
-
- (Object) Status(name)
deprecated
Deprecated.
Use
Active
instead -
- (Object) Stop(service_name)
(also: #stop)
Stop service Logs error with output from systemctl if the command fails.
Constructor Details
- (ServiceClass) initialize
Returns a new instance of ServiceClass
49 50 51 52 |
# File '../../src/modules/Service.rb', line 49 def initialize textdomain "base" @error = "" end |
Instance Attribute Details
- (Object) error
Returns the value of attribute error
47 48 49 |
# File '../../src/modules/Service.rb', line 47 def error @error end |
Instance Method Details
- (Object) Active(service_name) Also known as: active?
Check if service is active/running
87 88 89 90 |
# File '../../src/modules/Service.rb', line 87 def Active(service_name) service = SystemdService.find(service_name) !!(service && service.active?) end |
- (Boolean) Adjust(name, action)
Use the specific methods: Enable
or Disable
Adjusts runlevels in which the service runs.
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File '../../src/modules/Service.rb', line 306 def Adjust(name, action) deprecate("use `enable` or `disable` instead") service = SystemdService.find(name) return failure(:not_found, name) unless service case action when "disable" service.disable when "enable", "default" service.enable else log.error "Unknown action '#{action}' for service '#{name}'" false end end |
- (Boolean) call(command_name, service_name)
Send whatever systemd command you need to call for a specific service If the command fails, log entry with output from systemctl is created in y2log
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File '../../src/modules/Service.rb', line 58 def call(command_name, service_name) service = SystemdService.find(service_name) return failure(:not_found, service_name) unless service systemd_command = case command_name when "show" then :show when "status" then :status when "start" then :start when "stop" then :stop when "enable" then :enable when "disable" then :disable when "restart" then :restart when "reload" then :reload when "try-restart" then :try_restart when "reload-or-restart" then :reload_or_restart when "reload-or-try-restart" then :reload_or_try_restart else raise "Command '#{command_name}' not supported" end result = service.send(systemd_command) failure(command_name, service_name, service.error) unless result result end |
- (Object) checkExists(name)
Use SystemdService.find
Check that a service exists. If not, set error_msg.
206 207 208 209 210 211 |
# File '../../src/modules/Service.rb', line 206 def checkExists(name) deprecate("use `SystemdService.find` instead") return failure(:not_found, name) unless SystemdService.find(name) true end |
- (Object) Disable(service_name) Also known as: disable
Disable service Logs error with output from systemctl if the command fails
125 126 127 128 129 130 131 |
# File '../../src/modules/Service.rb', line 125 def Disable(service_name) log.info "Disabling service '#{service_name}'" service = SystemdService.find(service_name) return failure(:not_found, service_name) unless service return failure(:disable, service_name, service.error) unless service.disable true end |
- (Object) Enable(service_name) Also known as: enable
Enable service Logs error with output from systemctl if the command fails
111 112 113 114 115 116 117 |
# File '../../src/modules/Service.rb', line 111 def Enable(service_name) log.info "Enabling service '#{service_name}'" service = SystemdService.find(service_name) return failure(:not_found, service_name) unless service return failure(:enable, service_name, service.error) unless service.enable true end |
- (Object) Enabled(name) Also known as: enabled?
Check if service is enabled (in any runlevel)
Forwards to chkconfig -l which decides between init and systemd
100 101 102 103 |
# File '../../src/modules/Service.rb', line 100 def Enabled(name) service = SystemdService.find(name) !!(service && service.enabled?) end |
- (Array<String>) EnabledServices(_runlevel)
Runlevel features are not supported by systemd
Get list of enabled services in a runlevel
417 418 419 420 421 |
# File '../../src/modules/Service.rb', line 417 def EnabledServices(_runlevel) deprecate("use `SystemdService.all.select(&:enabled?)`") SystemdService.all.select(&:enabled?).map(&:name) end |
- (Object) Error
Error Message
If a Service function returns an error, this function would return an error message, including insserv stderr and possibly containing newlines.
197 198 199 |
# File '../../src/modules/Service.rb', line 197 def Error error end |
- (String) Find(services)
Use SystemdService.find instead
Return the first of the list of services which is available (has init script) or “” if none is.
428 429 430 431 432 |
# File '../../src/modules/Service.rb', line 428 def Find(services) deprecate("use `SystemdService.find` instead") services.find { |service_name| SystemdService.find(service_name) } end |
- (Object) Finetune(name, rl)
Use Enable
or Disable
instead
Set service to run in selected runlevels. Obsoleted - enables or disables the given service depending on the list of runlevels to start. If any runlevel is present, service is enabled, otherwise disabled.
332 333 334 335 336 337 338 339 340 341 342 343 344 |
# File '../../src/modules/Service.rb', line 332 def Finetune(name, rl) deprecate("use `enable` or `disable` instead") service = SystemdService.find(name) return failure(:not_found, name) unless service if rl.empty? service.disable else log.warn "Cannot enable service '#{name}' in selected runlevels, enabling for all" service.enable end end |
- (Object) FullInfo(name)
Not supported by systemd
Get service info and find out whether service is running.
277 278 279 280 281 282 |
# File '../../src/modules/Service.rb', line 277 def FullInfo(name) deprecate("not supported by systemd") return {} if !checkExists(name) Builtins.add(Info(name), "started", Status(name)) end |
- (resolved) GetServiceId(name)
Use SystemdService.find('service_name').name
Get the name from a systemd service unit id without the .service suffix
250 251 252 253 254 255 256 |
# File '../../src/modules/Service.rb', line 250 def GetServiceId(name) deprecate("use SystemdService.find('service_name').name") unit = SystemdService.find(name) return nil unless unit unit.name end |
- (resolved) GetUnitId(unit)
Use SystemdService.find('service_name').id
Get complete systemd unit id
238 239 240 241 242 243 244 |
# File '../../src/modules/Service.rb', line 238 def GetUnitId(unit) deprecate("use SystemdService.find('service_name').id") unit = SystemdService.find(unit) return nil unless unit unit.id end |
- (Object) Info(name)
Not supported by systemd
Get service info without peeking if service runs.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
# File '../../src/modules/Service.rb', line 217 def Info(name) deprecate("not supported by systemd") unit = SystemdService.find(name) return {} unless unit read = Convert.to_map(SCR.Read(path(".init.scripts.runlevel"), name)) detail = Ops.get_map(read, name, {}) read = Convert.to_map(SCR.Read(path(".init.scripts.comment"), name)) service = Ops.get_map(read, name, {}) Builtins.add( Builtins.add(service, "start", Ops.get_list(detail, "start", [])), "stop", Ops.get_list(detail, "stop", []) ) end |
- (Object) Reload(service_name) Also known as: reload
Reload service Logs error with output from systemctl if the command fails
167 168 169 170 171 172 173 |
# File '../../src/modules/Service.rb', line 167 def Reload(service_name) log.info "Reloading service '#{service_name}'" service = SystemdService.find(service_name) return failure(:not_found, service_name) unless service return failure(:reload, service_name, service.error) unless service.reload true end |
- (Object) Restart(service_name) Also known as: restart
Restart service Logs error with output from systemctl if the command fails
153 154 155 156 157 158 159 |
# File '../../src/modules/Service.rb', line 153 def Restart(service_name) log.info "Restarting service '#{service_name}'" service = SystemdService.find(service_name) return failure(:not_found, service_name) unless service return failure(:restart, service_name, service.error) unless service.restart true end |
- (Fixnum) RunInitScript(name, param)
Use specific method for service configuration
Run init script.
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File '../../src/modules/Service.rb', line 351 def RunInitScript(name, param) deprecate("use the specific unit command instead") service = SystemdService.find(name) if !service failure(:not_found, name) return -1 end result = case param when "start", "stop", "status", "reload", "restart", "enable", "disable" service.send(param) when "try-restart" service.try_restart when "reload-or-restart" service.reload_or_restart when "reload-or-try-restart" service.reload_or_try_restart else log.error "Unknown action '#{param}' for service '#{name}'" false end result ? 0 : -1 end |
- (Object) RunInitScriptOutput(name, param)
Use a specific method instread
Run init script and also return its output (stdout and stderr merged).
399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File '../../src/modules/Service.rb', line 399 def RunInitScriptOutput(name, param) deprecate("use `start` or `stop` instead") service = SystemdService.find(name) if !service failure(:not_found, name) success = false else success = service.send(param) self.error = service.error end { "stdout" => "", "stderr" => error, "exit" => success ? 0 : 1 } end |
- (Fixnum) RunInitScriptWithTimeOut(name, param)
Use specific unit methods for service configuration
Run init script with a time-out.
383 384 385 386 387 388 389 390 391 392 |
# File '../../src/modules/Service.rb', line 383 def RunInitScriptWithTimeOut(name, param) deprecate("use `start` or `stop` instead") service = SystemdService.find(name) if !service failure(:not_found, name) return 1 end service.send(param) ? 0 : 1 end |
- (Object) serviceDisable(name, _force)
Use Disable
instead
Disables a given service and records errors. Does not check if it exists.
291 292 293 294 295 296 |
# File '../../src/modules/Service.rb', line 291 def serviceDisable(name, _force) deprecate("use `disable` instead") unit = SystemdService.find(name) !!(unit && unit.disable) end |
- (Object) Start(service_name) Also known as: start
Start service Logs error with output from systemctl if the command fails
139 140 141 142 143 144 145 |
# File '../../src/modules/Service.rb', line 139 def Start(service_name) log.info "Starting service '#{service_name}'" service = SystemdService.find(service_name) return failure(:not_found, service_name) unless service return failure(:start, service_name, service.error) unless service.start true end |
- (Object) Status(name)
Use Active
instead
Get service status. The status is the output from “service status”. It should conform to LSB. 0 means the service is running.
264 265 266 267 268 269 270 271 |
# File '../../src/modules/Service.rb', line 264 def Status(name) deprecate("use `active?` instead") unit = SystemdService.find(name) failure(:not_found, name) unless unit unit && unit.active? ? 0 : -1 end |
- (Object) Stop(service_name) Also known as: stop
Stop service Logs error with output from systemctl if the command fails
181 182 183 184 185 186 187 |
# File '../../src/modules/Service.rb', line 181 def Stop(service_name) log.info "Stopping service '#{service_name}'" service = SystemdService.find(service_name) return failure(:not_found, service_name) unless service return failure(:stop, service_name, service.error) unless service.stop true end |