From 4041f1898e6b4bd8e0dc72c4c38ffab0ae3639cf Mon Sep 17 00:00:00 2001 From: Anirudh Gupta Date: Wed, 24 Aug 2016 02:01:10 +0530 Subject: [PATCH] can check windows service startup mode now --- lib/resources/service.rb | 9 +++++++++ test/unit/resources/service_test.rb | 1 + 2 files changed, 10 insertions(+) diff --git a/lib/resources/service.rb b/lib/resources/service.rb index 980b74451..0a8c9668a 100644 --- a/lib/resources/service.rb +++ b/lib/resources/service.rb @@ -77,6 +77,7 @@ module Inspec::Resources it { should be_enabled } it { should be_running } its('type') { should be 'systemd' } + its ('startmode') { should be 'Auto'} end describe service('service_name').runlevels(3, 5) do @@ -210,6 +211,12 @@ module Inspec::Resources info[:description] end + # returns the service start up mode from info + def startmode + return nil if info.nil? + info[:startmode] + end + def to_s "Service #{@service_name}" end @@ -547,6 +554,7 @@ module Inspec::Resources # # Until StartMode is not added to Get-Service, we need to do a workaround # @see: https://connect.microsoft.com/PowerShell/feedback/details/424948/i-would-like-to-see-the-property-starttype-added-to-get-services + # Also see: https://msdn.microsoft.com/en-us/library/aa384896(v=vs.85).aspx # Use the following powershell to determine the start mode # PS: Get-WmiObject -Class Win32_Service | Where-Object {$_.Name -eq $name -or $_.DisplayName -eq $name} | Select-Object -Prop # erty Name, StartMode, State, Status | ConvertTo-Json @@ -587,6 +595,7 @@ module Inspec::Resources installed: true, running: service_running?(service), enabled: service_enabled?(service), + startmode: service['WMI']['StartMode'], type: 'windows', } end diff --git a/test/unit/resources/service_test.rb b/test/unit/resources/service_test.rb index b1b91cfdf..3f80fd936 100644 --- a/test/unit/resources/service_test.rb +++ b/test/unit/resources/service_test.rb @@ -19,6 +19,7 @@ describe 'Inspec::Resources::Service' do _(resource.installed?).must_equal true _(resource.enabled?).must_equal true _(resource.running?).must_equal true + _(resource.startmode). must_equal 'Auto' _(resource.params).must_equal params end