Skip to content

Instantly share code, notes, and snippets.

@scottwb
Created December 1, 2009 10:28
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 scottwb/246209 to your computer and use it in GitHub Desktop.
Save scottwb/246209 to your computer and use it in GitHub Desktop.
Script to kill Rails script/server processes.
#!/usr/bin/env ruby
#
# Quick-and-dirty script to kill rogue script/server processes.
#
###############################################################################
# Configuration
###############################################################################
# The command you use to run your Rails server.
SERVER_CMD="ruby script/server -e production"
###############################################################################
# Main Program
###############################################################################
username = ENV['USER']
killed = false
`ps auxwww | grep "ruby"`.split(/$/).grep(/^#{username}\s+(\d+)\s+.*#{SERVER_CMD.gsub('/','\\/')}/) do |line|
puts "Killing PID: #{$1}"
system("kill -9 #{$1}")
killed = true
end
if !killed
puts "No script/server processes to kill."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment