How to perform rest of tasks after reboot


#1

Hi

I have the number of the task after the reboot command in recipes, but when reboot command is executed, the rest of the tasks are not executed.

reboot 'now' do
  action :nothing
  reason 'Cannot continue Chef run without a reboot.'
  delay_mins 0
end

file 'c:/text.txt'  do
	action :create
	notifies :reboot_now, 'reboot[now]', :immediately
end

# Delay of 5 second
powershell_script '5 second delay' do
   code 'Start-Sleep 5'
end

file 'c:/text2.txt'  do
	action :create
end

#2

Hi Deepak,

I worked on similar scenario in my last project . below is the approach to handle recipes after reboot.

a) Before calling a reboot function. I had created a schedule task in windows (that will run only once )

b) this schedule task will run the chef client and call rest of the recipe's to be executed after reboot

c) At the last , do some clean up to remove schedule task

Thanks!!

Sachin


#3

Thanks, Sachin

Suppose I have 10 recipes, and all are mentioned in the default recipes. I want to reboot the chef-node in 2-3 recipes.
eg:

default.rb

include_recipe 'TestCookbook::recipe_1'
include_recipe 'TestCookbook::recipe_2'
include_recipe 'TestCookbook::recipe_3'
include_recipe 'TestCookbook::recipe_3'
.......
.......
include_recipe 'TestCookbook::recipe_10'

If I used reboot in recipe_2 and recipe_5, in this case how task scheduler will work?
How will the user know about the completion of all recipes?
Can a single task scheduler run multiple recipes? If yes, then how?

Can you please provide a example to run multiple recipes in single task scheduler in sequence?
I also want that if there is failure in ant recipe, suppose recipe_3 is failed during task scheduler execution, then rest of task should be stopped, and then how chef- workstation will know, there is an failure in in recipe_3?

Thanks
Deepak


#4

Hi Deepak,

I would suggest group your recipes in two parts, one group required to run before reboot and second group after the reboot .

you can check each of the chef run logs (through the chef portal Chef Automate )

Thanks,

Sachin