I have a plain ruby application (it’s not a Web app, so not using a pre-existing platform like rails, sinatra…) processing data continuously.
I plan to deploy it with Capistrano and simply start it with the ruby command. The problem is that I get data by batches, and it can take few minutes to process them.
When I deploy a new version I would like to introduce a soft restart, meaning that the app will be first notify about the new deploy: so it can finish the batch, and then say ‘I m ready for an update’ (the deployment script will wait for that message).
Is there any Gem for that? Maybe Capistrano includes that option?
Allow the application to trap POSIX signals. Take a look at the Signal class.
If you send a
kill <signal type>to the process, any signal handlers will be invoked, regardless of what the process is currently doing. You can, for example, set some sort of flag that is checked at a sensible point in your logic (at the end of a run loop, for example), terminating the process if that flag is set. There are many signals you can respond to, butSIGHUPor one of theSIGUSRsignals probably make sense for what you’re doing… you can respond to whatever signal you like in whatever way you like, but it makes sense to allow the default behaviour for most of the typically handled ones (likeSIGTERMandSIGKILL). For really complex stuff, you can actually accept a coded series of signals to trigger particular events too.Output
Because in another terminal window I’d done: