Class: Inspec::Resources::LaunchCtl
- Inherits:
-
ServiceManager
- Object
- ServiceManager
- Inspec::Resources::LaunchCtl
- Defined in:
- lib/inspec/resources/service.rb
Overview
MacOS / Darwin new launctl on macos 10.10
Instance Attribute Summary
Attributes inherited from ServiceManager
Instance Method Summary collapse
- #info(service_name) ⇒ Object
-
#initialize(service_name, service_ctl = nil) ⇒ LaunchCtl
constructor
A new instance of LaunchCtl.
Constructor Details
#initialize(service_name, service_ctl = nil) ⇒ LaunchCtl
Returns a new instance of LaunchCtl.
535 536 537 538 |
# File 'lib/inspec/resources/service.rb', line 535 def initialize(service_name, service_ctl = nil) @service_ctl = service_ctl || "launchctl" super end |
Instance Method Details
#info(service_name) ⇒ Object
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/inspec/resources/service.rb', line 540 def info(service_name) # get the status of upstart service cmd = inspec.command("#{service_ctl} list") return nil if cmd.exit_status != 0 # search for the service srv = /(^.*#{service_name}.*)/.match(cmd.stdout) return nil if srv.nil? || srv[0].nil? # extract values from service parsed_srv = /^(?<pid>[0-9-]+)\t(?<exit>[0-9]+)\t(?<name>\S*)$/.match(srv[0]) enabled = !parsed_srv["name"].nil? # it's in the list # check if the service is running pid = parsed_srv["pid"] running = pid != "-" # extract service label srv = parsed_srv["name"] || service_name { name: srv, description: nil, installed: true, running: running, enabled: enabled, type: "darwin", } end |