Class: Inspec::Resources::FreeBSD10Init

Inherits:
ServiceManager show all
Defined in:
lib/inspec/resources/service.rb

Overview

Instance Attribute Summary

Attributes inherited from ServiceManager

#inspec, #service_ctl

Instance Method Summary collapse

Constructor Details

#initialize(service_name, service_ctl = nil) ⇒ FreeBSD10Init

Returns a new instance of FreeBSD10Init.



564
565
566
567
# File 'lib/inspec/resources/service.rb', line 564

def initialize(service_name, service_ctl = nil)
  @service_ctl = service_ctl || "service"
  super
end

Instance Method Details

#info(service_name) ⇒ Object



569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/inspec/resources/service.rb', line 569

def info(service_name)
  # `service -l` lists all files in /etc/rc.d and the local startup directories
  # % service -l
  # accounting
  # addswap
  # adjkerntz
  # apm
  # archdep
  cmd = inspec.command("#{service_ctl} -l")
  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?

  # check if service is enabled
  cmd = inspec.command("#{service_ctl} #{service_name} enabled")
  enabled = cmd.exit_status == 0

  # 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