Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can check windows service startup mode now #968

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/resources/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Service < Inspec.resource(1) # rubocop:disable ClassLength
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
Expand Down Expand Up @@ -210,6 +211,12 @@ def description
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
Expand Down Expand Up @@ -547,6 +554,7 @@ class WindowsSrv < ServiceManager
#
# 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
Expand Down Expand Up @@ -587,6 +595,7 @@ def info(service_name)
installed: true,
running: service_running?(service),
enabled: service_enabled?(service),
startmode: service['WMI']['StartMode'],
type: 'windows',
}
end
Expand Down
1 change: 1 addition & 0 deletions test/unit/resources/service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
_(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

Expand Down