Created
July 6, 2010 22:32
-
-
Save tkareine/466019 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def exit_upon(*signals) | |
process_going_down = false | |
signals.map { |signal| signal.to_s.upcase }.each do |signal| | |
Signal.trap(signal) do | |
exit! if process_going_down # terminate if still executing the given block | |
process_going_down = true | |
yield(signal) if block_given? | |
exit! 0 | |
end | |
end | |
end | |
exit_upon(:int, :term) do |signal| | |
puts "Received #{signal}, starting to do a long cleanup work..." | |
sleep 10 | |
puts "Done cleaning up, exiting..." | |
end | |
sleep 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment