diff options
author | Chris Doherty <cdoherty@getchef.com> | 2014-09-05 15:58:31 -0700 |
---|---|---|
committer | Chris Doherty <cdoherty@getchef.com> | 2014-09-10 16:34:28 -0700 |
commit | e1cb4798d79b857da01ae964abd95eae88fee476 (patch) | |
tree | bdcec42c166f10189ab92009c33ac28e9e8c739a /lib/chef/platform | |
parent | 5f0d5d63ec6a30ff90b10bf01782e698a34ffbfa (diff) | |
download | chef-e1cb4798d79b857da01ae964abd95eae88fee476.tar.gz |
Chef::Rebooter -> Chef::Platform::Rebooter
Diffstat (limited to 'lib/chef/platform')
-rw-r--r-- | lib/chef/platform/rebooter.rb | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/chef/platform/rebooter.rb b/lib/chef/platform/rebooter.rb new file mode 100644 index 0000000000..d471b3838e --- /dev/null +++ b/lib/chef/platform/rebooter.rb @@ -0,0 +1,55 @@ +# +# Author:: Chris Doherty <cdoherty@getchef.com>) +# Copyright:: Copyright (c) 2014 Chef, Inc. +# License:: Apache License, Version 2.0 +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +require 'chef/dsl/reboot_pending' +require 'chef/log' +require 'chef/platform' + +# this has whatever's needed to reboot the server, on whichever platform. +class Chef + class Platform + module Rebooter + extend Chef::Mixin::ShellOut + + 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}'" + + shell_out!(cmd) + end + + def reboot_if_needed!(this_node) + @node = this_node + @reboot_info = node.run_context.reboot_info + + if node.run_context.reboot_requested? + reboot! + end + end + end # end class instance stuff. + end + end +end |