# How to know if a chef-client run is occuring

**URL:** <https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341>\
**Category:** Chef Infra (archive)\
**Created:** [August 21, 2013, 4:22pm UTC](https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341 "2013-08-21T16:22:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Hart](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@Michael\_Hart](https://discourse.chef.io/u/Michael_Hart)\
**Post date:** [August 21, 2013, 4:22pm UTC](https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341/1 "2013-08-21T16:22:59Z")

</div>

Is there a definitive way of querying the chef server to see if a chef-client run is occurring on a node? We’ve noticed that a “knife status” will return a timestamp of “382528 hours ago”, or however many hours you are away from epoch, and but it’s not entirely consistent and using that in code feels like a bit of a hack. Ideally I’d like an API to return true or false if a chef-client run is occurring. Thoughts?

cheers  
mike

–  
Michael Hart  
Arctic Wolf Networks  
M: 226.388.4773

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [August 21, 2013, 4:42pm UTC](https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341/2 "2013-08-21T16:42:10Z")

</div>

you mean in-flight chef runs? chef server cant say that, Chef 11 (may be  
10.16 onward too) introduced file fcntl based locks while chef run is  
underway, to prevent concurrent chef runs, you can use knife ssh against  
the node in question and check if the lock is present, this will be a near  
real time indicator of any on going chef run.  
default location of the lock file is  
Chef::Config[:file\_cache\_path]/chef-client-running.pid.

> <https://github.com/chef/chef/blob/main/lib/chef/config.rb#L138>

> <https://github.com/chef/chef/blob/main/lib/chef/run_lock.rb#L45>

On Wed, Aug 21, 2013 at 9:22 AM, Michael Hart  
[michael.hart@arcticwolf.com](mailto:michael.hart@arcticwolf.com)wrote:

> Is there a definitive way of querying the chef server to see if a  
> chef-client run is occurring on a node? We've noticed that a "knife status"  
> will return a timestamp of "382528 hours ago", or however many hours you  
> are away from epoch, and but it's not entirely consistent and using that in  
> code feels like a bit of a hack. Ideally I'd like an API to return true or  
> false if a chef-client run is occurring. Thoughts?
> 
> cheers  
> mike
> 
> --  
> Michael Hart  
> Arctic Wolf Networks  
> M: 226.388.4773

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [August 21, 2013, 4:43pm UTC](https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341/3 "2013-08-21T16:43:50Z")

</div>

On Wednesday, August 21, 2013 at 9:22 AM, Michael Hart wrote:

> Is there a definitive way of querying the chef server to see if a chef-client run is occurring on a node? We've noticed that a "knife status" will return a timestamp of "382528 hours ago", or however many hours you are away from epoch, and but it's not entirely consistent and using that in code feels like a bit of a hack. Ideally I'd like an API to return true or false if a chef-client run is occurring. Thoughts?

Chef client communicates over HTTP, which is a stateless protocol, so there's no robust way for the server to know anything other than the last time a client made a request.

In Enterprise Chef (née Hosted and Private Chef), upcoming updates will include a node run history reporting feature that emulates the ability to track running clients by having them check in at the beginning and end of a run. How much of this makes it into the open source version and when is an open question at this point, but you could use a custom event dispatcher to track the state of clients in a similar way by integrating with a different system.

> cheers  
> mike
> 
> --  
> Michael Hart  
> Arctic Wolf Networks  
> M: 226.388.4773

--  
Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![Ranjib](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/ranjib/32/1040_2.png) [@Ranjib](https://discourse.chef.io/u/Ranjib)\
**Post date:** [August 21, 2013, 4:45pm UTC](https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341/4 "2013-08-21T16:45:39Z")

</div>

btw, knife status uses a node attribute called 'ohai\_time', which is an  
automatic attribute, provided by ohai. You can use that if you want to  
check the last successfull chef run. Also, you can use the event handler  
for real time chef run progress.

On Wed, Aug 21, 2013 at 9:42 AM, Ranjib Dey [dey.ranjib@gmail.com](mailto:dey.ranjib@gmail.com) wrote:

> you mean in-flight chef runs? chef server cant say that, Chef 11 (may be  
> 10.16 onward too) introduced file fcntl based locks while chef run is  
> underway, to prevent concurrent chef runs, you can use knife ssh against  
> the node in question and check if the lock is present, this will be a near  
> real time indicator of any on going chef run.  
> default location of the lock file is  
> Chef::Config[:file\_cache\_path]/chef-client-running.pid.
> 
> [chef/lib/chef/config.rb at main · chef/chef · GitHub](https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L138)  
> [chef/lib/chef/run\_lock.rb at main · chef/chef · GitHub](https://github.com/opscode/chef/blob/master/lib/chef/run_lock.rb#L45)
> 
> On Wed, Aug 21, 2013 at 9:22 AM, Michael Hart \<[michael.hart@arcticwolf.com](mailto:michael.hart@arcticwolf.com)
> 
> > wrote:
> 
> > Is there a definitive way of querying the chef server to see if a  
> > chef-client run is occurring on a node? We've noticed that a "knife status"  
> > will return a timestamp of "382528 hours ago", or however many hours you  
> > are away from epoch, and but it's not entirely consistent and using that in  
> > code feels like a bit of a hack. Ideally I'd like an API to return true or  
> > false if a chef-client run is occurring. Thoughts?
> > 
> > cheers  
> > mike
> > 
> > --  
> > Michael Hart  
> > Arctic Wolf Networks  
> > M: 226.388.4773

---

<div class="post-metadata">

**Author:** ![Michael\_Hart](https://avatars.discourse-cdn.com/v4/letter/m/8edcca/32.png) [@Michael\_Hart](https://discourse.chef.io/u/Michael_Hart)\
**Post date:** [August 22, 2013, 12:45am UTC](https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341/5 "2013-08-22T00:45:25Z")

</div>

Thanks Daniel, the feature in Enterprise Chef sounds interesting. Do you know the timeline for this feature’s release in Enterprise Chef?

cheers  
mike

–  
Michael Hart  
Arctic Wolf Networks  
M: 226.388.4773

On 2013-08-21, at 12:43 PM, Daniel DeLeo \<[dan@kallistec.com](mailto:dan@kallistec.com)[mailto:dan@kallistec.com](mailto:dan@kallistec.com)\> wrote:

On Wednesday, August 21, 2013 at 9:22 AM, Michael Hart wrote:

Is there a definitive way of querying the chef server to see if a chef-client run is occurring on a node? We’ve noticed that a “knife status” will return a timestamp of “382528 hours ago”, or however many hours you are away from epoch, and but it’s not entirely consistent and using that in code feels like a bit of a hack. Ideally I’d like an API to return true or false if a chef-client run is occurring. Thoughts?  
Chef client communicates over HTTP, which is a stateless protocol, so there’s no robust way for the server to know anything other than the last time a client made a request.

In Enterprise Chef (née Hosted and Private Chef), upcoming updates will include a node run history reporting feature that emulates the ability to track running clients by having them check in at the beginning and end of a run. How much of this makes it into the open source version and when is an open question at this point, but you could use a custom event dispatcher to track the state of clients in a similar way by integrating with a different system.

cheers  
mike

–  
Michael Hart  
Arctic Wolf Networks  
M: 226.388.4773

–  
Daniel DeLeo

---

<div class="post-metadata">

**Author:** ![kallistec](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/kallistec/32/23_2.png) [@kallistec](https://discourse.chef.io/u/kallistec)\
**Post date:** [August 22, 2013, 3:02pm UTC](https://discourse.chef.io/t/how-to-know-if-a-chef-client-run-is-occuring/4341/6 "2013-08-22T15:02:58Z")

</div>

On Wednesday, August 21, 2013 at 5:45 PM, Michael Hart wrote:

> Thanks Daniel, the feature in Enterprise Chef sounds interesting. Do you know the timeline for this feature's release in Enterprise Chef?
> 
> cheers  
> mike

We're looking at a release some time in Q4 this year. The core code is there, but we have a lot of performance and other testing to do before we ship it to everyone.

--  
Daniel DeLeo
