Problem calling Win32::Service from recipe

I’ve got a simple recipe I’m working on to set up some of our custom Windows services. I’m trying to invoke the win32-service gem to check for the existence of a service. I’m using Chef 11.2.0.

When I make the chef-client run, it fails with a “Recipe Compile Error”, “uninitialized constant Chef::Win32::Service”.

The recipe code is below. I’m sure I’m just missing something basic but I’m not sure what. I’ve found other examples of Chef code out there using this syntax. I looked down in the bowels of the omnibus installed ruby and the win32-service gem is there, and I don’t get an error on the require. When I run something like this from the command-line on the client box, it succeeds. The omnibus ruby is the only one on that machine.

Any pointers? Clue stick? Thanks.

require ‘win32/service’

target_service = “BogusServiceName”

if Win32::Service.exists?(target_service)
Chef::Log.info target_service + "Found!"
else
Chef::Log.info target_service + "NOT Found!"
end

Use ::Win32::Service to break out of the Chef namespace

Cheers,

AJ

On 14 March 2013 08:14, Peter Loron peterl@standingwave.org wrote:

I've got a simple recipe I'm working on to set up some of our custom Windows services. I'm trying to invoke the win32-service gem to check for the existence of a service. I'm using Chef 11.2.0.

When I make the chef-client run, it fails with a "Recipe Compile Error", "uninitialized constant Chef::Win32::Service".

The recipe code is below. I'm sure I'm just missing something basic but I'm not sure what. I've found other examples of Chef code out there using this syntax. I looked down in the bowels of the omnibus installed ruby and the win32-service gem is there, and I don't get an error on the require. When I run something like this from the command-line on the client box, it succeeds. The omnibus ruby is the only one on that machine.

Any pointers? Clue stick? Thanks.

require 'win32/service'

target_service = "BogusServiceName"

if Win32::Service.exists?(target_service)
Chef::Log.info target_service + "Found!"
else
Chef::Log.info target_service + "NOT Found!"
end

That was it! Thanks!

-Pete

On Mar 13, 2013, at 1:30 PM, AJ Christensen aj@junglist.gen.nz wrote:

Use ::Win32::Service to break out of the Chef namespace

Cheers,

AJ

On 14 March 2013 08:14, Peter Loron peterl@standingwave.org wrote:

I've got a simple recipe I'm working on to set up some of our custom Windows services. I'm trying to invoke the win32-service gem to check for the existence of a service. I'm using Chef 11.2.0.

When I make the chef-client run, it fails with a "Recipe Compile Error", "uninitialized constant Chef::Win32::Service".

The recipe code is below. I'm sure I'm just missing something basic but I'm not sure what. I've found other examples of Chef code out there using this syntax. I looked down in the bowels of the omnibus installed ruby and the win32-service gem is there, and I don't get an error on the require. When I run something like this from the command-line on the client box, it succeeds. The omnibus ruby is the only one on that machine.

Any pointers? Clue stick? Thanks.

require 'win32/service'

target_service = "BogusServiceName"

if Win32::Service.exists?(target_service)
Chef::Log.info target_service + "Found!"
else
Chef::Log.info target_service + "NOT Found!"
end