Pause chef-client in runtime

Hi partners, I want to know if there is a resource or something that allow to pause chef-client in runtime for x minutes while a task is executed totally, e.g., running a service that will be used for chef-client later.


Well you could always add a ruby sleep in a ruby_block but it would be better to actually poll for some setting that indicates the service truly is ready.

I assume you are running a command that starts a service somewhat asynchronously and you want to wait for it to be up before starting a dependent service? If so, that's usually accomplished by polling the first service.

One way to do that is to write some code in a ruby block resource to do the polling. You can see an example of that approach here: chef-server/postgresql.rb at 1e7e6c90bb5bc4ae1b3827cc77cd1261c5247d6b · chef/chef-server · GitHub

The other common way to do it is to run an execute resource that will fail if the service isn't fully up, and set the retries property (along with the retry delay).

Hi @Matt_Wrock and @kallistec, I think use the ruby_block resource and sleep. I would like to know what is the best way to check if tomcat 7 is ready, you know ?

I take it as example:

Thanks for your help.

So its been like 13 years since I was a java dev using tomcat but I’d imagine firing an http HEAD request in search for a 200 would do.

Ok, I try to do that, thanks !

The simplest way to code this might be to use the http_request resource with retries.

Can you give me an example ? I will use http://localhost:8080

A lot depends on how your tomcat service actually behaves. Ideally it should respond with a HTTP 503 when it's partially up, but I think any kind of response other than 2XX should work. You should be able to use a HEAD request, but GET should be fine if your server/app don't work correctly with HEAD requests.

Assuming the server behaves in a reasonable way, just code it up as described in the docs: http_request Resource and set the retries property to something other than zero. You may need to adjust the retry_delay property to ensure that retries * retry_delay is greater than the start time of the service.

You might also want to set action :nothing and trigger the http_request resource via a notification from the service resource. That will prevent Chef Client from making the http requests when the service is already running. That said, I'd recommend developing incrementally, get the http request part working first then add the notifications and such.

Ok, thanks for your help @Matt_Wrock and @kallistec