Last active
August 29, 2015 14:22
-
-
Save houmanka/289184ca5d8d92de0499 to your computer and use it in GitHub Desktop.
Rake task for stopping a rails server when you don't have access to it.
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
# Make a file under: `project_root/lib/tasks/server.rake` | |
# Then paste the following code | |
namespace :server do | |
desc "Stop the running server by killing the PID" | |
task :kill do | |
STDOUT.puts "Enter port number: " | |
post_number = STDIN.gets.strip | |
system "pid=$(lsof -i:#{post_number.to_i} -t); kill -TERM $pid || kill -KILL $pid" | |
end | |
end | |
# Then to use it in the terminal: `rake server:kill` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey man my cmd throws an error about the Rakefile. How do I blend this into the rakefile?