Multiple restarts

Hello,

I am still learning Chef and have few basic questions:

I have multiple cookbooks. Some are related to applications and some are generic ensuring compliance. Compliance cookbook needs to be applied to node less frequently than application configuration. I have multiple roles each dealing with a cookbook. Each cookbook is independent of each other. How can I set this multiple runs of chef-client throughout the day? I heard, chef-client has to run in a thread safe manner and hence question. Any example will be helpful.

This leads to another issue. if in a single cookbook, if I have multiple recipes which may need restart, how I can accomplish this without stopping/killing the rub? Ideally I want to restart the node once when entire run list is complete. I can add restart at the end of default.rb but then I don’t want to restart unless I have at-least one recipe demands, is there a elegant way of I need to set/check attributes/variable etc?

Thanks in advance

M

In terms of rebooting, you could create an empty file inside a recipe signaling that a reboot is required. Then you would use a guard in your reboot resource with ::File.exist? To check for the file.

For reboot, see https://docs.chef.io/resource_reboot.html . The examples show you how to notify the reboot resource, which you can do as many times as you like. At the end of the chef run, if anything has sent a notification to the reboot resource, chef will cause your node to reboot.

With regards multiple different run lists, you can use the -o flag to chef-client to specify a different run list. In general though, I’d recommend you just do the full run frequently - as long as your cookbooks are idempotent, it doesn’t matter how often you run them.

Thanks Thommay and Oirizarry,

ideally i need to restart, if needed, at the end of my role runlist. May be i can flag ( add a file or set a node attribute) and then have a dummy recipe at the end of the runlist to restart if needed. I was hoping somehow role has some kind of post runlist call which I use…

I will look into running everything frequently…

Thanks

M

Hi,
That’s exactly what the reboot resource does. No need for flags, just include the reboot resource anywhere in your recipes and then send it notifications. Please read the documentation.
-Thom