Search code examples
ruby-on-railsjruby

Shutdown hook for Rails


I'd like to have some cleanup code run when Rails is shutting down - is that possible? My situation is that I have a few threads in the background (I'm using jruby and calling into java) that live for the life of the process and I need to let them know to shut themselves down

Thanks!


Solution

  • Probably should just use the Ruby exit handler, which is a Kernel method:

    $ irb
    >> at_exit do
    ?>   puts 'bye...'
    >> end
    => #<Proc:0xb79a87e4@(irb):1>
    >> exit
    bye...
    $