summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-10-13 11:34:14 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-10-13 11:34:14 -0700
commit8d62921ef82fad3b545baa81c2a50715a8120857 (patch)
treececcaa0d302ab7ed3feacbf4bd8ee2756506122f
parent71f4a954d0fd7c9cb0a636c5503e25c7cf46e9bd (diff)
downloadchef-fix-linux-rebooter.tar.gz
fix rebooter for solaris and background rebootsfix-linux-rebooter
closes #5026 Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/platform/rebooter.rb10
-rw-r--r--spec/functional/rebooter_spec.rb33
2 files changed, 29 insertions, 14 deletions
diff --git a/lib/chef/platform/rebooter.rb b/lib/chef/platform/rebooter.rb
index 33a6e24be2..430d175869 100644
--- a/lib/chef/platform/rebooter.rb
+++ b/lib/chef/platform/rebooter.rb
@@ -33,14 +33,18 @@ class Chef
def reboot!(node)
reboot_info = node.run_context.reboot_info
- cmd = if Chef::Platform.windows?
+ cmd = case
+ when Chef::Platform.windows?
# should this do /f as well? do we then need a minimum delay to let apps quit?
# Use explicit path to shutdown.exe, to protect against https://github.com/chef/chef/issues/5594
windows_shutdown_path = "#{ENV['SYSTEMROOT']}/System32/shutdown.exe"
"#{windows_shutdown_path} /r /t #{reboot_info[:delay_mins] * 60} /c \"#{reboot_info[:reason]}\""
+ when node["os"] == "solaris2"
+ # SysV-flavored shutdown
+ "shutdown -i6 -g#{reboot_info[:delay_mins]} -y \"#{reboot_info[:reason]}\" &"
else
- # probably Linux-only.
- "shutdown -r +#{reboot_info[:delay_mins]} \"#{reboot_info[:reason]}\""
+ # Linux/BSD/Mac/AIX and other systems with BSD-ish shutdown
+ "shutdown -r +#{reboot_info[:delay_mins]} \"#{reboot_info[:reason]}\" &"
end
msg = "Rebooting server at a recipe's request. Details: #{reboot_info.inspect}"
diff --git a/spec/functional/rebooter_spec.rb b/spec/functional/rebooter_spec.rb
index a28491cc0b..36961593b0 100644
--- a/spec/functional/rebooter_spec.rb
+++ b/spec/functional/rebooter_spec.rb
@@ -35,8 +35,9 @@ describe Chef::Platform::Rebooter do
resource
end
+ let(:node) { Chef::Node.new }
+
let(:run_context) do
- node = Chef::Node.new
events = Chef::EventDispatch::Dispatcher.new
Chef::RunContext.new(node, {}, events)
end
@@ -44,7 +45,8 @@ describe Chef::Platform::Rebooter do
let(:expected) do
{
:windows => "#{ENV['SYSTEMROOT']}/System32/shutdown.exe /r /t 300 /c \"rebooter spec test\"",
- :linux => 'shutdown -r +5 "rebooter spec test"',
+ :linux => 'shutdown -r +5 "rebooter spec test" &',
+ :solaris => 'shutdown -i6 -g5 -y "rebooter spec test" &',
}
end
@@ -69,8 +71,9 @@ describe Chef::Platform::Rebooter do
end
shared_context "test a reboot method" do
- def test_rebooter_method(method_sym, is_windows, expected_reboot_str)
+ def test_rebooter_method(method_sym, is_windows, is_solaris, expected_reboot_str)
allow(ChefConfig).to receive(:windows?).and_return(is_windows)
+ node.automatic["os"] = node.automatic["platform"] = node.automatic["platform_family"] = "solaris2" if is_solaris
expect(rebooter).to receive(:shell_out!).once.with(expected_reboot_str)
expect(rebooter).to receive(:raise).with(Chef::Exceptions::Reboot)
expect(rebooter).to receive(method_sym).once.and_call_original
@@ -81,24 +84,32 @@ describe Chef::Platform::Rebooter do
describe "when using #reboot_if_needed!" do
include_context "test a reboot method"
- it "should produce the correct string on Windows", :windows_only do
- test_rebooter_method(:reboot_if_needed!, true, expected[:windows])
+ it "should produce the correct string on Windows" do
+ test_rebooter_method(:reboot_if_needed!, true, false, expected[:windows])
+ end
+
+ it "should produce a SysV-like shutdown on solaris" do
+ test_rebooter_method(:reboot_if_needed!, false, true, expected[:solaris])
end
- it "should produce the correct (Linux-specific) string on non-Windows" do
- test_rebooter_method(:reboot_if_needed!, false, expected[:linux])
+ it "should produce a BSD-like shutdown by default" do
+ test_rebooter_method(:reboot_if_needed!, false, false, expected[:linux])
end
end
describe "when using #reboot!" do
include_context "test a reboot method"
- it "should produce the correct string on Windows", :windows_only do
- test_rebooter_method(:reboot!, true, expected[:windows])
+ it "should produce the correct string on Windows" do
+ test_rebooter_method(:reboot!, true, false, expected[:windows])
+ end
+
+ it "should produce a SysV-like shutdown on solaris" do
+ test_rebooter_method(:reboot!, false, true, expected[:solaris])
end
- it "should produce the correct (Linux-specific) string on non-Windows" do
- test_rebooter_method(:reboot!, false, expected[:linux])
+ it "should produce a BSD-like shutdown by default" do
+ test_rebooter_method(:reboot!, false, false, expected[:linux])
end
end
end