- From: Seth Chisamore <
>
- To:
- Subject: [chef] Re: Re: managing windows services via chef
- Date: Fri, 28 Oct 2011 00:34:55 -0400
Take a look at the 'Win32::Service.exists?' method in the 'win32-service' gem
[0]. You could easily use this in a 'not_if' block.
As an FYI Chef 0.10.6 will ship with a heavily refactored Windows service
provider:
http://tickets.opscode.com/browse/CHEF-2541
It leverages win32-service heavily and talks directly to the WinAPI vs
shelling out to sc.exe.
--
Seth Chisamore
Software Design Engineer, Opscode, Inc.
IRC, Skype, Twitter, Github: schisamo
[0]
https://github.com/djberg96/win32-service
On Monday, October 24, 2011 at 11:47 AM, Maven User wrote:
>
Well, I got this to work (I think) - more testing now...
>
>
>
only_if 0==`sc query WZCSVC \| find /C /I \"running\"`
>
>
>
>
On Mon, Oct 24, 2011 at 11:25 AM, Maven User
>
<
>
>
(mailto:
)>
>
wrote:
>
> I'm trying this approach, but it seems to wait for user input (and then
>
> doesn't see the whole command):
>
>
>
> ruby_block "first-search" do
>
> block do
>
> puts "the service WZCSV was found"
>
> end
>
> action :create
>
> only_if "sc query WZCSVC \| find /C /I \"running\""
>
> end
>
>
>
> Is there something wrong with how I've phrased the "only_if portion of
>
> this ruby block?
>
>
>
> It halts there and when I hit enter, it's as if something was not sent to
>
> the "sc" command:
>
>
>
> [Mon, 24 Oct 2011 10:58:18 -0400] DEBUG: Executing sc query WZCSVC | find
>
> /C /I "running"
>
> [Mon, 24 Oct 2011 11:00:18 -0400] DEBUG: ---- Begin output of sc query
>
> WZCSVC | find /C /I "running" ----
>
> [Mon, 24 Oct 2011 11:00:18 -0400] DEBUG: STDOUT:
>
> ERROR: Invalid Option
>
> ....
>
> [Mon, 24 Oct 2011 11:00:18 -0400] DEBUG: STDERR:
>
> [Mon, 24 Oct 2011 11:00:18 -0400] DEBUG: ---- End output of sc query
>
> WZCSVC | find /C /I "running" ----
>
> [Mon, 24 Oct 2011 11:00:18 -0400] DEBUG: Ran sc query WZCSVC | find /C /I
>
> "running" returned 0
>
> the service WZCSV was found
>
> [Mon, 24 Oct 2011 11:00:18 -0400] INFO: ruby_block[first-search] called
>
>
>
> But that all looks healthy - any suggestions?
>
>
>
>
>
> On Thu, Oct 20, 2011 at 2:48 PM, Maven User
>
> <
>
>
>
> (mailto:
)>
>
> wrote:
>
> > Hello again all -
>
> >
>
> > First - thanks all for all the really helpful replies to any/all
>
> > earlier posts. I've been able to move pretty quickly because of the
>
> > help.
>
> >
>
> > Now I have a tougher question.
>
> >
>
> > I'm trying to work with a windows service for an item that we build and
>
> > install.
>
> >
>
> > This means stopping it if it exists, installing it if it doesn't and
>
> > then starting it if it isn't already running.
>
> >
>
> > I've tried to make the only_if/not_if be a "sc query <servicename>",
>
> > but I'm seeing mixed results in different windows servers.
>
> >
>
> > On Windows 7, if the service doesn't exist, I get a non-zero (1060)
>
> > return value, on Windows server 2003 (R2), I get 0 regardless if the
>
> > service exists or doesn't exist.
>
> >
>
> > I've been thinking about just parsing the output of the "sc query"
>
> > command versus just relying on the return value, but this is starting
>
> > to feel kludgy.
>
> >
>
> > Any suggestions?
Archive powered by MHonArc 2.6.16.