Created
June 16, 2017 21:53
-
-
Save stephanwehner/83c87fce21d9f0d48a80e93f3a4c493f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is for Rails apps | |
# Place this in app/controllers/shutdown_controller.rb | |
# | |
# When you want to start up a new Rails server, but some other one is already running | |
# simply run this command: "curl http://localhost:3000/shutdown/exit" -- it will go away. | |
# | |
# This will work without any other changes if your routes include something like | |
# match '/:controller(/:action(/:id))', via: [:all] | |
# | |
# Also, add app/controllers/shutdown_controller.rb to your global .gitignore file and noone will ever know! | |
class ShutdownController < ActionController::Base | |
include Logging | |
def exit | |
Rails.logger.info 'Received exit request!' | |
pid = File.read(Rails.root.join('tmp/pids/server.pid')) | |
Rails.logger.info "Received exit request. Read pid as #{pid.inspect}" | |
Rails.logger.info "Received exit request. Doing kill-9" | |
system "kill -9 #{pid}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment