Skip to content

Commit

Permalink
Merged reboot changes of tjnicholas and also checking reboot_pending?
Browse files Browse the repository at this point in the history
  • Loading branch information
nimisha committed Jan 22, 2015
2 parents cbaa8e9 + f5f2a05 commit c369803
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 13 deletions.
4 changes: 4 additions & 0 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
# INSTALLATION_REBOOT_MODE = "delayed_reboot". Used for node reboot after chef-client run.
default['powershell']['installation_reboot_mode'] = ENV['INSTALLATION_REBOOT_MODE'] || 'no_reboot'

# number of seconds to warn before reboot. The clock starts at the end of the
# chef run.
default['powershell']['reboot_timeout_seconds'] = 10

# For enabling HTTPS transport in winrm recipe
default['powershell']['winrm']['enable_https_transport'] = false
default['powershell']['winrm']['thumbprint'] = '' # mandatory for https transport
Expand Down
1 change: 0 additions & 1 deletion attributes/powershell4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@
end
end

default['powershell']['reboot_notifier'] = 'windows_package[Windows Management Framework Core4.0]'
6 changes: 6 additions & 0 deletions recipes/powershell2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@

include_recipe 'ms_dotnet2'

# Reboot if user specifies doesn't specify no_reboot
include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot'

windows_package 'Windows Management Framework Core' do
source node['powershell']['powershell2']['url']
checksum node['powershell']['powershell2']['checksum']
installer_type :custom
options '/quiet /norestart'
action :install
# Note that the :immediately is to immediately notify the other resource,
# not to immediately reboot. The windows_reboot 'notifies' does that.
notifies :request, 'windows_reboot[powershell]', :immediately if reboot_pending? && node['powershell']['installation_reboot_mode'] != 'no_reboot'
not_if do
begin
registry_data_exists?('HKLM\SOFTWARE\Microsoft\PowerShell\1\PowerShellEngine', { :name => 'PowerShellVersion', :type => :string, :data => '2.0' })
Expand Down
7 changes: 7 additions & 0 deletions recipes/powershell3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,19 @@
# WMF 3.0 requires .NET 4.0
include_recipe 'ms_dotnet4'

# Reboot if user specifies doesn't specify no_reboot
include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot'

windows_package 'Windows Management Framework Core 3.0' do
source node['powershell']['powershell3']['url']
checksum node['powershell']['powershell3']['checksum']
installer_type :custom
options '/quiet /norestart'
success_codes [0, 42, 127, 3010]
action :install
# Note that the :immediately is to immediately notify the other resource,
# not to immediately reboot. The windows_reboot 'notifies' does that.
notifies :request, 'windows_reboot[powershell]', :immediately if reboot_pending? && node['powershell']['installation_reboot_mode'] != 'no_reboot'
not_if do
begin
registry_data_exists?('HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine', { :name => 'PowerShellVersion', :type => :string, :data => '3.0' })
Expand Down
15 changes: 7 additions & 8 deletions recipes/powershell4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,19 @@
# Ensure .NET 4.5 is installed or installation will fail silently per Microsoft. Only necessary for Windows 2008R2 or 7.
include_recipe 'ms_dotnet45' if windows_version.windows_server_2008_r2? || windows_version.windows_7?

# Get powershell version
powershell_version_cmd = 'powershell.exe $PSVersionTable.PSVersion.Major'
shell_out = Mixlib::ShellOut.new(powershell_version_cmd)
shell_out.run_command
powershell_version = shell_out.stdout.to_f

# Reboot if user specifies immediate_reboot and powershell version < 4
include_recipe 'powershell::windows_reboot' if node['powershell']['installation_reboot_mode'] == 'immediate_reboot' && powershell_version < 4
# Reboot if user specifies doesn't specify no_reboot
include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot'

windows_package 'Windows Management Framework Core4.0' do
source node['powershell']['powershell4']['url']
checksum node['powershell']['powershell4']['checksum']
installer_type :custom
options '/quiet /norestart'
action :install
success_codes [0, 42, 127, 3010]
# Note that the :immediately is to immediately notify the other resource,
# not to immediately reboot. The windows_reboot 'notifies' does that.
notifies :request, 'windows_reboot[powershell]', :immediately if reboot_pending? && node['powershell']['installation_reboot_mode'] != 'no_reboot'
not_if do
begin
registry_data_exists?('HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine', { :name => 'PowerShellVersion', :type => :string, :data => '4.0' })
Expand Down
6 changes: 6 additions & 0 deletions recipes/powershell5.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@

if windows_version.windows_server_2012_r2? || windows_version.windows_8_1?

include_recipe 'powershell::windows_reboot' unless node['powershell']['installation_reboot_mode'] == 'no_reboot'

windows_package 'Windows Management Framework Core 5.0' do
source node['powershell']['powershell5']['url']
checksum node['powershell']['powershell5']['checksum']
installer_type :custom
options '/quiet /norestart'
action :install
success_codes [0, 42, 127, 3010]
# Note that the :immediately is to immediately notify the other resource,
# not to immediately reboot. The windows_reboot 'notifies' does that.
notifies :request, 'windows_reboot[powershell]', :immediately if reboot_pending? && node['powershell']['installation_reboot_mode'] != 'no_reboot'
not_if { registry_data_exists?('HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine', { :name => 'PowerShellVersion', :type => :string, :data => '5.0.9701.0' }) }
end

Expand Down
18 changes: 14 additions & 4 deletions recipes/windows_reboot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@

include_recipe 'windows::reboot_handler'

windows_reboot 'rebooter' do
windows_reboot 'powershell' do
reason 'Reboot after successful/unsuccessful powershell installation'
timeout 60
notifies :run, node['powershell']['reboot_notifier'], :immediately
not_if { false }
timeout node['powershell']['reboot_timeout_seconds']
action :nothing
notifies :run, 'ruby_block[end_chef_run]', :immediately if node['powershell']['installation_reboot_mode'] == 'immediate_reboot'
end

# The reboot handler only does something at the end of the chef run. If it
# needs to happen straight away to be useful, throw an exception...
ruby_block 'end_chef_run' do
block do
raise 'Requested sudden end to the run... I hope this was justified.'
end
action :nothing
end

0 comments on commit c369803

Please sign in to comment.