Perform Action on Rails App Close
-
27-10-2019 - |
题
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?
解决方案
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...
不隶属于 StackOverflow