I want to be able to terminate a Sinatra app from a request, e.g. with the following route:
post '/terminate' do
Thread.current.kill
end
Implementing it like this is a bit abrupt. I'd rather the request completed, returned an HTTP OK message, and then Sinatra shut down gracefully.
Is there a hook to do this?
Edit:
My application is a lightweight mock server used for receiving webhook notifications. I will be using multiple servers like this on the same machine (different ports), so need to avoid any global methods of starting/stopping.
My requirement is driven by the fact that each server must run in its own Ruby instance, hence no communication between my tests and the server other than via the REST interface.
I'm using the default thin
server to run Sinatra. So far my code is just a subclass of Sinatra::Base, started using run!
from within the code. This is nice and simple, I can make standalone scripts to instantiate each server, I just need to have a way of stopping them.