From bd1e5e4085943f51b919644764d609b3ba5aa55e Mon Sep 17 00:00:00 2001 From: Christoph Hartmann Date: Thu, 28 Jan 2016 14:25:49 +0100 Subject: [PATCH] service resource for solaris 10 and 11 --- lib/resources/service.rb | 41 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/resources/service.rb b/lib/resources/service.rb index 985f00109..e6e4a13f9 100644 --- a/lib/resources/service.rb +++ b/lib/resources/service.rb @@ -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.'