Skip to content

Instantly share code, notes, and snippets.

@houmanka
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save houmanka/289184ca5d8d92de0499 to your computer and use it in GitHub Desktop.
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.
# 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