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.
459 460 461 462 |
# File 'lib/inspec/resources/service.rb', line 459 def initialize(service_name, service_ctl = nil) @service_ctl = service_ctl || "service" super end |
Instance Method Details
#info(service_name) ⇒ Object
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/inspec/resources/service.rb', line 464 def info(service_name) # check if service is enabled # services are enabled in /etc/rc.conf and /etc/defaults/rc.conf # via #{service_name}_enable="YES" # service SERVICE status returns the following result if not activated: # Cannot 'status' sshd. Set sshd_enable to YES in /etc/rc.conf or use 'onestatus' instead of 'status'. # gather all enabled services cmd = inspec.command("#{service_ctl} -e") 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? 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 |