diff options
author | Chris Doherty <cdoherty@getchef.com> | 2014-09-04 13:03:38 -0700 |
---|---|---|
committer | Chris Doherty <cdoherty@getchef.com> | 2014-09-10 16:34:23 -0700 |
commit | 67bb227814615d82a062d15883e08257b5f47c66 (patch) | |
tree | 89a5857784858aac8a7807777d80ef577cf74a48 | |
parent | bf64c21888102e57cb910ec298db025af2829dc8 (diff) | |
download | chef-67bb227814615d82a062d15883e08257b5f47c66.tar.gz |
Switch from class variables to class instance variables; tweak temporary logging a bit.
-rw-r--r-- | lib/chef/rebooter.rb | 54 | ||||
-rw-r--r-- | lib/chef/run_context.rb | 4 |
2 files changed, 24 insertions, 34 deletions
diff --git a/lib/chef/rebooter.rb b/lib/chef/rebooter.rb index 1c187ec3bc..acaf0ed854 100644 --- a/lib/chef/rebooter.rb +++ b/lib/chef/rebooter.rb @@ -20,44 +20,34 @@ require 'chef/dsl/reboot_pending' require 'chef/log' require 'chef/platform' -# this encapsulates any and all gnarly stuff needed to reboot the server. - -# where should this file go in the hierarchy? +# this has whatever's needed to reboot the server, on whichever platform. class Chef class Rebooter - # below are awkward contortions to re-use the RebootPending code. include Chef::Mixin::ShellOut - attr_reader :reboot_info - - # shims for RebootPending. - attr_reader :node, :run_context - - def initialize(node) - @node = node - @run_context = node.run_context - @reboot_info = node.run_context.reboot_info - end - - def reboot! - Chef::Log.warn "Totally would have rebooted here. #{@reboot_info.inspect}" - cmd = if Chef::Platform.windows? - "shutdown /r /t #{reboot_info[:delay_mins]} /c \"#{reboot_info[:reason]}\"" - else - shutdown_time = reboot_info[:delay_mins] > 0 ? reboot_info[:reboot_timeout] : "now" - "shutdown -r #{shutdown_time}" + class << self + attr_reader :node, :reboot_info + + def reboot! + cmd = if Chef::Platform.windows? + "shutdown /r /t #{reboot_info[:delay_mins]} /c \"#{reboot_info[:reason]}\"" + else + shutdown_time = reboot_info[:delay_mins] > 0 ? reboot_info[:reboot_timeout] : "now" + "shutdown -r #{shutdown_time}" + end + Chef::Log.warn "Shutdown command (not running): '#{cmd}'" + # for ease of testing we are not yet actually rebooting. + #shell_out!(cmd) end - Chef::Log.warn "Shutdown command: '#{cmd}'" - # for ease of testing we are not yet actually rebooting. - #shell_out!(cmd) - end - def self.reboot_if_needed!(node) - @@rebooter ||= self.new(node) - if node.run_context.reboot_requested? - @@rebooter.reboot! - end - end + def reboot_if_needed!(node) + @node = node + @reboot_info = node.run_context.reboot_info + if node.run_context.reboot_requested? + reboot! + end + end + end # end class instance stuff. end end
\ No newline at end of file diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb index b41173e12b..bbe2f9eba0 100644 --- a/lib/chef/run_context.rb +++ b/lib/chef/run_context.rb @@ -283,12 +283,12 @@ ERROR_MESSAGE # 5. raise an exception on any second call. # 6. ? def request_reboot(reboot_info) - Chef::Log::warn "Changing reboot status from #{@reboot_info.inspect} to #{reboot_info.inspect}" + Chef::Log::info "Changing reboot status from #{@reboot_info.inspect} to #{reboot_info.inspect}" @reboot_info = reboot_info end def cancel_reboot - Chef::Log::warn "Changing reboot status from #{@reboot_info.inspect} to {}" + Chef::Log::info "Changing reboot status from #{@reboot_info.inspect} to {}" @reboot_info = {} end |