Using reboot resource but does not continue after reboot


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

windows_package 'some_app_01' do
  source node['app01']['binary']
  options '/Q'
  action :install
  notifies :reboot_now, 'reboot[now]', :immediately
end

windows_package 'some_app_02' do
  source node['app02']['binary']
  options '/Q'
  action :install
end

The reboot resource is successfully triggered by the 'some_app_01' package installation and the OS is sent to reboot… but when it comes back chef-client does not start automatically
I have seen workarounds using scheduled tasks, but I thought the reboot resource handles this on its own, since there is an option to fire reboot immediately and there could be things left to converge after reboot (like some_app_02)


#2

Early in my cookbook/recipes, I have a resource the sets up a Scheduled task that does a Chef-client run OnStart. That way during an initial build/converge, reboots occur as needed and Chef-client runs begin after a restart.

I have a guard on that resource so that if it is not the initial build/converge, that resource doesn’t fire.

And I have a resource at the end of my run_lists to then remove this task.


#3

@Pcguy88 thanks for the comment and workaround solution… however I feel it as a workaround…

Apart from the workaround solution, the chef-client could run as a service too…
Although I accept the chef terminology that the chef-client should be set as a service and pick up the line after every reboot and converge the node in an idempotent style, but it would nice to have solutions for ‘offline clients’ to start chef-client after reboot… maybe an extra feature in the reboot resource could come in handy to handle a scheduled task on its own?


#4

There was an RFC to change the reboot behavior in chef 13

As far as I can tell it is up to the external tools to ‘catch’ that the chef has exited with exit code -35 and handle it appropriately. Chef could and (probably should) automatically start a chef run on the next reboot, but that currently isn’t implemented.

With regards to chef as a scheduled task vs chef as a service: Most people I’ve talked to recommend chef as a scheduled task since the service doesn’t always restart when there is a fatal error.

The way we work around the reboot behavior is with scheduled takes like so:


  reboot 'Restart Computer' do
    action :nothing
  end

  windows_task 'chef ad-join' do
    task_name 'chef ad-join'
    user 'SYSTEM'
    command 'chef-client -L C:\chef\chef-ad-join.log'
    run_level :highest
    frequency :onstart
    only_if { node['kernel']['cs_info']['domain_role'].to_i == 0 || node['kernel']['cs_info']['domain_role'].to_i == 2 }
    action :create
  end

  file 'c:/Windows/chef-ad-join.txt' do
    content 'Placed by ad-join cookbook. Cookbook will keep rebooting windows until server is part of a domain and this file exists. DONT DELETE'
    action :create_if_missing
    notifies :reboot_now, 'reboot[Restart Computer]', :immediately
  end

  windows_task 'remove chef ad-join' do
    task_name 'chef ad-join'
    action :delete
  end