Know if a node is shutted down (or not)


#1

Hello chefs,

I am interested in learning how to get through chef/ohai the state of a
node. This means to know if a node is turned off or on.

Some of my recipes use chef search and since I am using a cloud
infrastructure provider is pretty typical that I have nodes turned off but
registered in chef. This sometimes does not play nice resulting in
configuration of services that include nodes that idealistically should not
be included.

Thanks in advance.

Jacobo García López de Araujo


#2

Hi Jacobo,

I don’t know that there is any way to specifically generate a sort of “state: stopped” attribute since it necessarily relies on ohai running when the server is in that state (which would be paradoxical). However in our own environment we determine if a node is “running” if it has an ohai_time of (Time.now.to_i - ohai_time) > (chef_run_interval + splay_time + some_fudge_factor). I.e. if the node hasn’t updated ohai in a while, it is assumed to be “off.” Of course this also ropes in nodes where ohai isn’t being run for some other reason but usually that still meets our needs.

Hope this helps,

Eric

On May 14, 2013, at 07:44 , Jacobo García wrote:

Hello chefs,

I am interested in learning how to get through chef/ohai the state of a node. This means to know if a node is turned off or on.

Some of my recipes use chef search and since I am using a cloud infrastructure provider is pretty typical that I have nodes turned off but registered in chef. This sometimes does not play nice resulting in configuration of services that include nodes that idealistically should not be included.

Thanks in advance.

Jacobo García López de Araujo


#3

We use our asset database [1] for keeping track of the status of assets.
Chef handles assets that are allocated (aka doing useful work) while
the asset db deals with assets that are unallocated, being provisoined
etc. We dump that info into ohai so so that chef knows if it’s running
on an asset when maybe it should not be. We delete client/node from
chef when unallocating assets (ie redhat rekick), but if garbage
collection is needed we can do that from the asset db (or from knife status). Nodes don’t really “come back” in that workflow, even if a
hostname is shared assets are new nodes when re-provisioned.

It sounds like in your case you are using search and picking up down
assets. If treating chef nodes as ephemeral doesn’t work for you (and I
get that it’s not as smooth in a cloud situation when you turn off
images at night) you could try injecting some sort of “I am shutting
down information” via a role/environment etc as part of the shut down
procedure. You could then use that as part of your search queries.

[1] http://tumblr.github.io/collins/

On 05/14/2013 07:44 AM, Jacobo García wrote:

Hello chefs,

I am interested in learning how to get through chef/ohai the state of a
node. This means to know if a node is turned off or on.

Some of my recipes use chef search and since I am using a cloud
infrastructure provider is pretty typical that I have nodes turned off but
registered in chef. This sometimes does not play nice resulting in
configuration of services that include nodes that idealistically should not
be included.

Thanks in advance.

Jacobo García López de Araujo