trap 'TERM' do
warn 'Exiting.'
exit 1
end
This prints a 10 line stacktrace.
How to suppress the stacktrace and exit silently?
Ruby 2.2.0
You can do it like this:
trap "TERM" do
warn "Exiting."
$stderr.reopen(IO::NULL)
$stdout.reopen(IO::NULL)
exit 1
end
If you hit Ctrl + C, the signal will be INT
, not TERM
. If you want to catch both, you can do something like this:
p = proc do
warn 'Exiting.'
exit 1
end
trap 'INT',p
trap 'TERM',p