[chef] Re: Re: Chef handler to reboot windows machine


Chronological Thread 
  • From: James Scott < >
  • To: " " < >
  • Subject: [chef] Re: Re: Chef handler to reboot windows machine
  • Date: Mon, 17 Nov 2014 08:46:36 -0800

Also, Chef 12 adds a new resource that moves the cookbook-based reboot resource into core Chef:


On Mon, Nov 17, 2014 at 7:20 AM, Todd Pigram < " target="_blank"> > wrote:
Sachin,

make sure that the 'windows::reboot_handler 'is at the top of your run list as well as putting ('depends     'windows') in your metadata.rb.

The install what you want and Chef will reboot and continue. 

here is an example of installing RDSH for preparation for Citrix XenApp install. It will starts the RDSH, reboot and then come back and do the desktop experience, and so on.... As long as you installed the chef service during client install or created a scheduled task. 

# install RDS
powershell node['w2k8']['rds'] do
  code <<-EOH
  Import-Module ServerManager
  Add-WindowsFeature RDS-RD-Server
  EOH
  not_if {reboot_pending?}
end


# Install desktop experience
powershell node['w2k8']['deskexp'] do
  code <<-EOH
  Import-Module ServerManager
  Add-WindowsFeature Desktop-Experience
  EOH
  not_if {reboot_pending?}
end

powershell node['w2k8']['xps'] do
  code <<-EOH
  Import-Module ServerManager
  Add-WindowsFeature XPS-Viewer
  EOH
  not_if {reboot_pending?}
end

windows_reboot 30 do 
  reason 'Chef said to'
  only_if {reboot_pending?}
end

if you still have issues, create a library file called reboot_pending.rb in you cookbook - I was given this by Alex Vinyar from Chef. This was added to Chef Client back in version 11.12...But I still use it

reboot_pending.rb

class Chef
  class Resource
    # include Chef::Mixin::ShellOut

    def reboot_pending?
      # Any files listed here means reboot needed
      (Registry.key_exists?('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations') &&
        Registry.get_value('HKLM\SYSTEM\CurrentControlSet\Control\Session Manager','PendingFileRenameOperations').any?) ||
      # 1 for any value means reboot pending
      # "9306cdfc-c4a1-4a22-9996-848cb67eddc3"=1
      (Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired') &&
        Registry.get_values('HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired').select{|v| v[2] == 1 }.any?) ||
      # 1 or 2 for 'Flags' value means reboot pending
      (Registry.key_exists?('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile') &&
        [1,2].include?(Registry::get_value('HKLM\SOFTWARE\Microsoft\Updates\UpdateExeVolatile','Flags'))) ||
      # added by Alex
      Registry.key_exists?('HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending')
    end

  end
end

 

On Mon, Nov 17, 2014 at 8:30 AM, Sachin Gupta < " target="_blank"> > wrote:
Hi All,

I have a use case where I need to reboot windows machine after some package installation.

would like to know the possible best practice to implement this use case;

a)  Make a single recipe that will do the package installation and product installation and then at last      call chef handler to reboot the machine

a)   make two different chef recipe, the first recipe will install packages and then reboot the machine,
       the second recipe will do the remaining stuff. I don't know this will work or not.    
       Is there a way, we can return the chef client to run the same cookbook after reboot??
    

I also gone through some documentation but nothing is useful.

Any help would the useful .


Thanks & Regards,
Sachin Kumar



--




Archive powered by MHonArc 2.6.16.

§