Skip to content

Instantly share code, notes, and snippets.

@houmanka
Last active Aug 29, 2015
Embed
What would you like to do?
Rake task for stopping a rails server when you don't have access to it.
# 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`
@jheck88
Copy link

jheck88 commented Jun 4, 2015

Hey man my cmd throws an error about the Rakefile. How do I blend this into the rakefile?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment