service resource for solaris 10 and 11

This commit is contained in:
Christoph Hartmann 2016-01-28 14:25:49 +01:00
parent 913191fb9e
commit bd1e5e4085

View file

@ -88,6 +88,8 @@ class Service < Inspec.resource(1)
Systemd.new(inspec, service_ctl)
elsif %w{aix}.include?(family)
SrcMstr.new(inspec)
elsif os.solaris?
Svcs.new(inspec)
end
end
@ -185,6 +187,8 @@ class SrcMstr < ServiceManager
}
end
private
def status?
status_cmd = inspec.command("lssrc -s #{@name}")
return nil if status_cmd.exit_status.to_i != 0
@ -195,8 +199,6 @@ class SrcMstr < ServiceManager
enabled_rc_tcpip? || enabled_inittab?
end
private
# #rubocop:disable Style/TrailingComma
def enabled_rc_tcpip?
inspec.command(
@ -480,6 +482,41 @@ class WindowsSrv < ServiceManager
end
end
# Solaris services
class Svcs < ServiceManager
def initialize(service_name, service_ctl = nil)
@service_ctl ||= 'svcs'
super
end
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_re: /^(\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
end
# specific resources for specific service managers
class SystemdService < Service
name 'systemd_service'
desc 'Use the systemd_service InSpec audit resource to test if the named service (controlled by systemd) is installed, running and/or enabled.'