Class: Inspec::Resources::Svcs

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

Overview

Solaris services

Instance Attribute Summary

Attributes inherited from ServiceManager

#inspec, #service_ctl

Instance Method Summary collapse

Constructor Details

#initialize(service_name, service_ctl = nil) ⇒ Svcs

Returns a new instance of Svcs.



658
659
660
661
# File 'lib/inspec/resources/service.rb', line 658

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

Instance Method Details

#info(service_name) ⇒ Object



663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# File 'lib/inspec/resources/service.rb', line 663

def info(service_name)
  # get the status of runit service
  cmd = inspec.command("#{service_ctl} -l #{service_name}")
  return nil if cmd.exit_status != 0

  params = SimpleConfig.new(
    cmd.stdout.chomp,
    assignment_regex: /^(\w+)\s*(.*)$/,
    multiple_values: false
  ).params

  installed = cmd.exit_status == 0
  running = installed && (params["state"] == "online")
  enabled = installed && (params["enabled"] == "true")

  {
    name: service_name,
    description: params["name"],
    installed: installed,
    running: running,
    enabled: enabled,
    type: "svcs",
  }
end