Hi Sachin,I build my AMI's using Chef and I have also split them into two parts(before and after reboot). Before boot adds a windows task to run Chef on the next boot: https://github.com/opscode-cookbooks/windows#windows_task . It needs to run as SYSTEM without a password to work without login(IIRC). After boot recipe removes the task.Cheers,-GregOn Tue, Nov 25, 2014 at 2:03 AM, Sachin Gupta < " target="_blank"> > wrote:I am able to get the reboot message and system gets rebooted after a period of 60 sec. From this use case it is clear that reboot is done only at the end of the chef client.At the top of the Apache recipe, I had also added the line ( include_recipe 'windows::reboot_handler' and 'include_recipe 'chef_handler::default') and also added (depends "windows" and chef_handler)in apache metadata.rb.In the meantime, I also tried to add the following code for reboot at the end of Apache installation.Thanks James/Todd for sharing this info.Do you know when chef 12 will be released??
windows_reboot 60 do
reason "Installed a new Apache package"
action:request
endNow if I want to do a reboot at the middle of execution, then will this approach work??a) will break the recipe into two parts, first part will installed the required package and second part will do the remaining stuff.Now the biggest challenge is how to start the chef client again after reboot.
I have to make a reboot.txt file before the reboot in first recipe and after that system will be rebooted. during the startup script if I pass the chef-solo command to run the chef client with the second recipe and in that recipe it will check whether the reboot.txt file is present or not. if reboot.txt is present then only second recipe will move forward otherwise it will not do anything and exit.James/Todd Is this making any sense and would like to know whether I am moving on a correct path??Thanks & Regards,
Sachin KumarOn Mon, Nov 17, 2014 at 11:11 PM, Todd Pigram < " target="_blank"> > wrote:James,That is awesome!!!!On Mon, Nov 17, 2014 at 11:46 AM, James Scott < " target="_blank"> > wrote: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 RDSpowershell node['w2k8']['rds'] docode <<-EOHImport-Module ServerManagerAdd-WindowsFeature RDS-RD-ServerEOHnot_if {reboot_pending?}end# Install desktop experiencepowershell node['w2k8']['deskexp'] docode <<-EOHImport-Module ServerManagerAdd-WindowsFeature Desktop-ExperienceEOHnot_if {reboot_pending?}endpowershell node['w2k8']['xps'] docode <<-EOHImport-Module ServerManagerAdd-WindowsFeature XPS-ViewerEOHnot_if {reboot_pending?}endwindows_reboot 30 doreason 'Chef said to'only_if {reboot_pending?}endif 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 itreboot_pending.rbclass Chefclass Resource# include Chef::Mixin::ShellOutdef 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 AlexRegistry.key_exists?('HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending')endendend--On Mon, Nov 17, 2014 at 8:30 AM, Sachin Gupta < " target="_blank"> > wrote:Thanks & Regards,Any help would the useful .I also gone through some documentation but nothing is useful.Is there a way, we can return the chef client to run the same cookbook after reboot??the second recipe will do the remaining stuff. I don't know this will work or not.would like to know the possible best practice to implement this use case;Hi All,I have a use case where I need to reboot windows machine after some package installation.a) Make a single recipe that will do the package installation and product installation and then at last call chef handler to reboot the machinea) make two different chef recipe, the first recipe will install packages and then reboot the machine,
Sachin Kumar--
Archive powered by MHonArc 2.6.16.