Class: Inspec::Resources::BSDInit
- Inherits:
-
ServiceManager
- Object
- ServiceManager
- Inspec::Resources::BSDInit
- Defined in:
- lib/inspec/resources/service.rb
Overview
Instance Attribute Summary
Attributes inherited from ServiceManager
Instance Method Summary collapse
- #info(service_name) ⇒ Object
-
#initialize(service_name, service_ctl = nil) ⇒ BSDInit
constructor
A new instance of BSDInit.
Constructor Details
#initialize(service_name, service_ctl = nil) ⇒ BSDInit
Returns a new instance of BSDInit.
520 521 522 523 |
# File 'lib/inspec/resources/service.rb', line 520 def initialize(service_name, service_ctl = nil) @service_ctl = service_ctl || "service" super end |
Instance Method Details
#info(service_name) ⇒ Object
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/inspec/resources/service.rb', line 525 def info(service_name) # `service -e` lists all enabled services. Output format: # % service -e # /etc/rc.d/hostid # /etc/rc.d/hostid_save # /etc/rc.d/cleanvar # /etc/rc.d/ip6addrctl # /etc/rc.d/devd cmd = inspec.command("#{service_ctl} -e") return nil if cmd.exit_status != 0 # search for the service srv = %r{^.*/(#{service_name}$)}.match(cmd.stdout) return nil if srv.nil? || srv[0].nil? enabled = true # check if the service is running # if the service is not available or not running, we always get an error code cmd = inspec.command("#{service_ctl} #{service_name} onestatus") running = cmd.exit_status == 0 { name: service_name, description: nil, installed: true, running: running, enabled: enabled, type: "bsd-init", } end |