Question

When the Rails app goes to shutdown what is the procedure that is followed? How can I hook into this to clean-up files that were created during the run of the Rails app?

Was it helpful?

Solution

You can add the following block to config/boot.rb to run commands when the app is shut down:

at_exit do
  puts "Shutting the app down..."
end

This is the output you'll see in your server process:

[Swanny ~/Sites/test_app]$ bundle exec thin start
>> Using rack adapter
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
^C>> Stopping ...
Shutting the app down...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top