Starting background process on windows

Hi,

Is there any help to be expected from chef or from an existing cookbook for
starting background processes? I cannot find a way to start my server after
deploying without having chef just hang there until I kill the server. I
have tried a few different things: batch start command; ruby’s Process.spawn
command. The best I get is a separate process but not one that is detached
from the chef-client process.

Cheers,

Florian

Use chef to define a service, then have the service started by your chef run.

See service Resource for more info.

--
Brad Knowles
Sent from my iPhone

On Aug 23, 2013, at 10:13 AM, "Florian Hehlen" florian.hehlen@gmail.com wrote:

Hi,

Is there any help to be expected from chef or from an existing cookbook for starting background processes? I cannot find a way to start my server after deploying without having chef just hang there until I kill the server. I have tried a few different things: batch start command; ruby’s Process.spawn command. The best I get is a separate process but not one that is detached from the chef-client process.

Cheers,
Florian

Brad,

Unless I miss-understand, this resource is for controlling applications that can already run as services. I have a plain java executable that I want to spawn and fork. I do not see how I can do this.

Cheers,

Florian

From: Brad Knowles [mailto:brad@shub-internet.org]
Sent: 23 August 2013 17:21
To: chef@lists.opscode.com
Cc: chef@lists.opscode.com
Subject: [chef] Re: starting background process on windows

Use chef to define a service, then have the service started by your chef run.

See http://docs.opscode.com/resource_service.html for more info.

Brad Knowles

Sent from my iPhone

On Aug 23, 2013, at 10:13 AM, “Florian Hehlen” florian.hehlen@gmail.com wrote:

Hi,

Is there any help to be expected from chef or from an existing cookbook for starting background processes? I cannot find a way to start my server after deploying without having chef just hang there until I kill the server. I have tried a few different things: batch start command; ruby’s Process.spawn command. The best I get is a separate process but not one that is detached from the chef-client process.

Cheers,

Florian

On Friday, August 23, 2013 at 8:58 AM, Florian Hehlen wrote:

Brad,

Unless I miss-understand, this resource is for controlling applications that can already run as services. I have a plain java executable that I want to spawn and fork. I do not see how I can do this.

Cheers,
Florian

What you really should do, is use something like runit, daemontools, systemd, upstart, etc. to manage the service. These options all provide a framework for starting/stopping the service, and restarting it if it crashes. Other people using your systems will have a standard way to check if the service is running and so on.

If you're not going to do that, then you need to create a wrapper script to properly daemonize your service on your own. In principle it's pretty simple, but there's a lot of little details you need to get right. Chef's daemonization code is here: chef/lib/chef/daemon.rb at main · chef/chef · GitHub For an example of daemonizing a java program, take a look at GitHub - chef-boneyard/chef-solr

--
Daniel DeLeo

Daniel,

Thanks for the links. I got over my initial issue with a simple Process.spawn followed by Process.detach. This is obviously not enough for a production environment. But at the moment I am in the startup phase of the project and getting up and going is more important than making things bullet-proof.

I will definitely take a look at the cookbooks you suggest. I am still new to Ruby and have to admit struggle when looking at other people's code. This is part of why my first attempts were not working. I also find myself very alone in the windows/chef world which does not help when looking for online help.

cheers,
FLorian

On Aug 23, 2013, at 6:16 PM, Daniel DeLeo dan@kallistec.com wrote:

On Friday, August 23, 2013 at 8:58 AM, Florian Hehlen wrote:

Brad,

Unless I miss-understand, this resource is for controlling applications that can already run as services. I have a plain java executable that I want to spawn and fork. I do not see how I can do this.

Cheers,
Florian

What you really should do, is use something like runit, daemontools, systemd, upstart, etc. to manage the service. These options all provide a framework for starting/stopping the service, and restarting it if it crashes. Other people using your systems will have a standard way to check if the service is running and so on.

If you're not going to do that, then you need to create a wrapper script to properly daemonize your service on your own. In principle it's pretty simple, but there's a lot of little details you need to get right. Chef's daemonization code is here: chef/lib/chef/daemon.rb at main · chef/chef · GitHub For an example of daemonizing a java program, take a look at GitHub - chef-boneyard/chef-solr

--
Daniel DeLeo

On Aug 24, 2013, at 12:52 AM, Florian Hehlen wrote:

Daniel,

Thanks for the links. I got over my initial issue with a simple Process.spawn followed by Process.detach. This is obviously not enough for a production environment. But at the moment I am in the startup phase of the project and getting up and going is more important than making things bullet-proof.

I will definitely take a look at the cookbooks you suggest. I am still new to Ruby and have to admit struggle when looking at other people's code. This is part of why my first attempts were not working. I also find myself very alone in the windows/chef world which does not help when looking for online help.

Create a user-defined service - Windows Client | Microsoft Learn shows how to create a service from any arbitrary process in Windows using srvany.

--Noah

Florian,

We used to use winsw to start up Chef as a service on Windows. I think this
is still the mechanism used by Jenkins.

I think srvany is deprecated on Windows; the article Noah sent later is for
Windows NT (!)

  • Julian

On Sat, Aug 24, 2013 at 3:52 AM, Florian Hehlen florian.hehlen@gmail.comwrote:

Daniel,

Thanks for the links. I got over my initial issue with a simple
Process.spawn followed by Process.detach. This is obviously not enough for
a production environment. But at the moment I am in the startup phase of
the project and getting up and going is more important than making things
bullet-proof.

I will definitely take a look at the cookbooks you suggest. I am still new
to Ruby and have to admit struggle when looking at other people's code.
This is part of why my first attempts were not working. I also find myself
very alone in the windows/chef world which does not help when looking for
online help.

cheers,
FLorian

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]