In several projects, I'd like to have a rake task like rake server
which will start serving that application via whatever means it needs. Here's one example:
task :server do
%x{bundle exec rackup -p 1234}
end
This works, but when I'm ready to stop it, pressing Ctrl+c
does not shut down gracefully; it interrupts the Rake task itself, which says rake aborted!
and gives a stack trace. In some cases I have to do Ctrl+c
twice.
I could probably write something with Signal.trap
that would interrupt this more gracefully. Is there an easier way?
trap('SIGINT') { puts "Your message"; exit }
That should make the trick.
You can even add the trap
at the task level.
task :server do
trap('SIGINT') { puts "Your message"; exit }
%x{bundle exec rackup -p 1234}
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With