Skip to content

Instantly share code, notes, and snippets.

@hh
Created May 8, 2012 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hh/77208d31bf9335fa2e56 to your computer and use it in GitHub Desktop.
Save hh/77208d31bf9335fa2e56 to your computer and use it in GitHub Desktop.
not_if in powershell resource fails
[Wed, 09 May 2012 07:38:58 +1200] DEBUG: Processing powershell[Creating service TEST_SERVICE from C:\Path\To\MyService.exe] on mybox
[Wed, 09 May 2012 07:38:58 +1200] INFO: Processing powershell[Creating service TEST_SERVICE from C:\Path\To\MyService.exe] action run (c line /chef/cache/cookbooks/on_windows/libraries/service.rb)
[Wed, 09 May 2012 07:38:58 +1200] DEBUG: sh(powershell Get-Service "TEST_SERVICE") - hangs
def create_and_start_service(svc_name,svc_path)
powershell "Creating service #{svc_name} from #{svc_path}" do
code "New-Service -name \"#{svc_name}\" -BinaryPathName \"#{svc_path}\""
not_if "powershell Get-Service \"#{svc_name}\""
end
service svc_name do
action :start
end
end
create_and_start_service("TEST_SERVICE","C:\Path\To\MyService.exe")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment