Chef-client managing chef-client service

Hello Chefs!

I¹ve come across an interesting issue with Chef 11.12.8 on Ubuntu 12.04.
I¹ve got a chef-client bootstrap that includes the chef-client cookbook,
managing chef-client as an init service (upstart seems to work fine).

It seems that chef-client as a daemon holds a lock, but exits gracefully,
thus resulting in chef-client not running at all on the system post chef
run.

Scenario:

  • Vanilla Ubuntu 12.04 install with Chef 11.12.8 debian package installed.
    Note that init scripts are not installed to /etc/init.d or /etc/init
  • Chef client #1 manually started with run-list including
    "recipe[chef-client]"
  • Chef-client recipe starts chef-client as a service (client #2)
  • Client #2 waits for Client #1 to finish
  • Client #1 updates /etc/init.d/chef-client template, which triggers
    chef-client service restart
  • Client #2 receives SIGTERM, which waits complete recipe run to shutdown
    gracefully
  • Chef-client #3 starts, and immediately exits, due to Client #2 already
    running
  • Finally Client #1 finishes run, and Client #2 starts its run
  • Client #2 ensures that service is running, which is correct (i.e. Client
    #2 is running)
  • Client #2 finishes run, and gracefully stops

Result:

  • No chef-clients running. Client #1 was a one-time run, Client #2 asked
    to shutdown gracefully, and Client #3 terminated since Client #2 already
    running.

Note that changing DIETIME and SLEEPTIME does not change the results, as
Client #1 waits for the init scripts to complete.

I¹ve filed https://github.com/opscode-cookbooks/chef-client/issues/173
against the chef-client cookbook, but in the meantime I¹ve switched to
upstart as the init_style. Other than using upstart, is there a
recommended way to start chef-client as a daemon, from a knife bootstrap?

Thanks!
Andrew

On Fri Jul 18 10:02:08 2014, Andrew Brown wrote:

  • Chef-client #3 starts, and immediately exits, due to Client #2 already
    running

There's already a github issue in the chef project on changing this so
that the daemon will immediately exit and release the daemon lock. The
new daemon will be able to start and acquire the lock. If there's
already a client running the initial child that is kicked off by the
new daemon will then block on the child lock if there's already a CCR
running.

On 2014-07-18, 3:44 PM, "Lamont Granquist" lamont@opscode.com wrote:

On Fri Jul 18 10:02:08 2014, Andrew Brown wrote:

  • Chef-client #3 starts, and immediately exits, due to Client #2 already
    running

There's already a github issue in the chef project on changing this so
that the daemon will immediately exit and release the daemon lock. The
new daemon will be able to start and acquire the lock. If there's
already a client running the initial child that is kicked off by the
new daemon will then block on the child lock if there's already a CCR
running.

Gotcha - it¹s service chef-client restart fails · Issue #1524 · chef/chef · GitHub
My google-fu didn¹t find it when I was searching earlier today.

Thanks!