Skip to content

Commit

Permalink
Do not continue doing things after Ctrl+C
Browse files Browse the repository at this point in the history
Call Kernel.exit! 1 to force an immediate error-exit
if the operator uses Ctrl+C to prevent performing post-hook steps.

Signed-off-by: Marc A. Paradise <[email protected]>
  • Loading branch information
marcparadise committed Apr 3, 2017
1 parent 43b1041 commit e31b682
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/omnibus-ctl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def scary_cleanse_warning(*args)
sleep 60
rescue Interrupt
log ""
exit 0
Kernel.exit 1
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/omnibus-ctl/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Omnibus
class Ctl
VERSION = "0.5.0"
VERSION = "0.5.1"
end
end
15 changes: 11 additions & 4 deletions spec/omnibus-ctl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -668,19 +668,17 @@ def ctl_output

describe "cleanse" do
before(:each) do
# this is potentially destructive if run on a live system,
# not to mention loaded with sleeps - skip it.
# No-op everything cleanup_procs_and_nuke wants to do, it's destructive
# (and slow/sleep-laden):
allow(@ctl).to receive("cleanup_procs_and_nuke").and_return 0
end

it "should invoke the cleanse_post_hook" do
# No-op everything cleanup_procs_and_nuke wants to do, it's destructive:
expect(@ctl).to receive("command_post_hook")
@ctl.run(["cleanse", "yes"])
end

it "should invoke the scary_cleanse_warning" do
# No-op everything cleanup_procs_and_nuke wants to do, it's destructive:
expect(@ctl).to receive("scary_cleanse_warning")
@ctl.run(["cleanse", "yes"])
end
Expand Down Expand Up @@ -734,6 +732,12 @@ def ctl_output
@ctl.scary_cleanse_warning("cleanse")
expect(ctl_output).not_to match(/--with-external/)
end

it "will hard-stop when the operator uses Ctrl+C to exit" do
allow(@ctl).to receive(:sleep).and_raise(Interrupt)
expect(Kernel).to receive(:exit).with(1)
@ctl.scary_cleanse_warning("cleanse")
end
end

context "cleanse_post_hook" do
Expand Down Expand Up @@ -940,4 +944,7 @@ def ctl_output
end
end
end



end

0 comments on commit e31b682

Please sign in to comment.